Skip to content

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

dspw215

A small, dependency-light CLI and Home Assistant MQTT bridge for the D-Link DSP-W215 Wi-Fi smart plug, speaking the device's native HNAP1 (SOAP-over-HTTP) protocol.

It handles the whole lifecycle:

  • Commission a factory-fresh plug onto your Wi-Fi (no discontinued mobile app needed).
  • Control the relay (on / off / toggle / state).
  • Read instantaneous power (W), lifetime energy (kWh) and internal temperature (°C).
  • Bridge to MQTT with Home Assistant MQTT Discovery, so the plug shows up automatically as a switch + sensors, including a kWh sensor ready for the Energy dashboard.

The protocol details were verified by reverse-engineering the device firmware; see docs/protocol.md. Tested against hardware rev A1, firmware 1.0x–1.24.

Why this exists: the official mydlink app is discontinued, and the popular pyW215 library disables energy reporting in the "legacy protocol" mode that these older plugs require. This tool talks to the plug directly and exposes the energy meter regardless.

⚠️ Security: the DSP-W215 is end-of-life with serious, unpatchable weaknesses. Run it on an isolated IoT VLAN with no Internet access and never expose it to the WAN. This tool is local-only (no cloud). See docs/security.md.


Installation

pip install dspw215            # CLI + library
pip install 'dspw215[mqtt]'    # also the Home Assistant MQTT bridge

From source:

git clone https://github.com/jamesrguy/dspw215
cd dspw215
pip install -e '.[mqtt]'

Requires Python ≥ 3.9. The core library and CLI use only the standard library; only the mqtt extra pulls in paho-mqtt.


Quick start

The plug's PIN (6 digits, on the label) is the password for everything.

1. Commission onto your Wi-Fi

Factory-reset the plug (hold the side button ~10 s until the light blinks orange), join your computer to its DSP-Wxxx setup network, then:

dspw215 --host 192.168.0.60 --pin 123456 \
        commission --ssid "MyNetwork" --password "MyWiFiPassword"

The plug reboots and joins your network with a new DHCP address. See docs/commissioning.md for the full walk-through (LED states, security options, troubleshooting).

2. Control & read (using the plug's new address)

export DSPW215_HOST=192.168.1.50
export DSPW215_PIN=123456

dspw215 info            # identity / firmware / MAC
dspw215 on              # relay on
dspw215 off             # relay off
dspw215 toggle
dspw215 state           # -> ON / OFF
dspw215 power           # -> 42 W
dspw215 energy          # -> 13.6 kWh   (lifetime counter)
dspw215 temp            # -> 31 °C
dspw215 read --json     # {"state": true, "power_w": 42.0, ...}

3. Run the Home Assistant MQTT bridge

dspw215 mqtt --broker 192.168.1.10 --mqtt-user ha --mqtt-pass secret

Home Assistant auto-creates a switch and three sensors (power, energy, temperature). Add sensor.<device>_energy to the Energy dashboard. See docs/home-assistant.md and the systemd unit for running it 24/7.


CLI reference

dspw215 [--host H] [--pin P] [--port 80] [--timeout 10] [--debug] <command>

  info        show device identity (--json)
  state       print relay state (ON/OFF)
  on|off|toggle
  power       instantaneous power (W)
  energy      lifetime energy (kWh)
  temp        internal temperature (°C)
  read        full sensor snapshot (--json)
  scan        scan for Wi-Fi networks (--json)
  reboot      reboot the device
  commission  --ssid --password [--security WPA2-PSK] [--encryption AES] [--radio RADIO_2.4GHz]
  mqtt        run the Home Assistant MQTT bridge (see docs/home-assistant.md)

Connection settings fall back to env vars: DSPW215_HOST, DSPW215_PIN, DSPW215_PORT (and DSPW215_MQTT_BROKER / DSPW215_MQTT_USER / DSPW215_MQTT_PASS for the bridge).

Library usage

from dspw215 import DSPW215

plug = DSPW215("192.168.1.50", "123456")
plug.set_state(True)
print(plug.read_all())   # {'state': True, 'power_w': 42.0, 'energy_kwh': 13.6, 'temperature_c': 31.0}

Documentation

License

MIT — see LICENSE. Not affiliated with or endorsed by D-Link.

About

CLI and Home Assistant MQTT bridge for the D-Link DSP-W215 Wi-Fi smart plug (HNAP)

Topics

Resources

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages