Controlling the TP-Link HS110 smart plug with Domoticz
Posted: Sun Oct 01, 2017 9:04 pm
Although there are plenty of smart plugs currently available on the market, my choice was, as usual, hugely constrained by the requirement of maximum hackability of such a device. So I've decided to pick up the TP-Link HS110 smart plug, mainly because of this article: Reverse Engineering the TP-Link HS110, which describes many aspects of the plug in great detail, and also shows how to operate the plug using just a simple Python script (tplink-smartplug.py), so the integration with the home automation system of your choice (Domoticz in my case) is going be pretty straightforward.
First thing you should do is to reserve an IP address for your smart plug on your router. For this, you'll need plug's MAC address, which is written on the backside of the device (alternatively you can figure out the MAC address inside the companion Kasa application).
Then you can use tplink-smartplug.py to turn on/off the plug simply like so:
which gives the below response:
You can also read the real-time power consumption info via (HS110 only):
which gives:
The nice thing about this plug is that it is operated simply via sending JSON requests, so it can be easily commanded and queried for various information. For example, I'm going to use the above real-time power consumption info for monitoring when my washing machine finishes its job (I'll keep this for next time though).
The final step is to integrate the plug with Domoticz (in my case running on a Raspberry Pi). For this you will need to copy the control script into '~/domoticz/scripts/' and make it executable. This can be achieved via:
Then you can open Domoticz in your web browser, go to "Setup/Hardware" and add a new virtual hardware of the "Dummy" type. After that click on "Create Virtual Sensors" of the newly created virtual hardware, the bellow popup will appear:
Name the newly created sensor, and select "Switch" as its type. After that you will need to edit the switch and add the on/off actions:
That's it! Your switch is now ready.
Related articles:
Home automation with Domoticz, ESP8266 and BME280
First thing you should do is to reserve an IP address for your smart plug on your router. For this, you'll need plug's MAC address, which is written on the backside of the device (alternatively you can figure out the MAC address inside the companion Kasa application).
Then you can use tplink-smartplug.py to turn on/off the plug simply like so:
Code: Select all
python ./tplink-smartplug.py -t <IP> -c on
Code: Select all
Sent: {"system":{"set_relay_state":{"state":1}}}
Received: {"system":{"set_relay_state":{"err_code":0}}}
Code: Select all
python ./tplink-smartplug.py -t <IP> -j '{"emeter":{"get_realtime":{}}}'
Code: Select all
Sent: {"emeter":{"get_realtime":{}}}
Received: {"emeter":{"get_realtime":{"current":0.041124,"voltage":237.504900,"power":9.341753,"total":0.001000,"err_code":0}}}
The final step is to integrate the plug with Domoticz (in my case running on a Raspberry Pi). For this you will need to copy the control script into '~/domoticz/scripts/' and make it executable. This can be achieved via:
Code: Select all
cp ./tplink-smartplug.py ~/domoticz/scripts/
sudo chmod +x ~/domoticz/scripts/tplink-smartplug.py
Name the newly created sensor, and select "Switch" as its type. After that you will need to edit the switch and add the on/off actions:
Code: Select all
script:///home/pi/domoticz/scripts/tplink-smartplug.py -t <IP> -c on
script:///home/pi/domoticz/scripts/tplink-smartplug.py -t <IP> -c off
That's it! Your switch is now ready.
Related articles:
Home automation with Domoticz, ESP8266 and BME280