Friday, 12 May 2017

TP-Link HS100 wireless switches for home automation

So my ongoing quest for ultimate home automation continues, and I'm still looking for the best solution for controlling sockets using my home automation server (Ubuntu) which allows me to check the current state of the socket, change it to on/off and also be able to be put anywhere in the house and still controlled (without ethernet to it).

I've gone through several different solutions over the years, one that was in for a while was X10 which used signals over the mains powerline through the house. This worked but had many flaws, ultimately the devices self-destructed as they couldn't cope with power spikes, etc, and because the equipment used the mains supply to transmit/receive it couldn't be protected using surge protectors, etc. So this was dropped.

I then experimented with the 433Mhz generic off the shelf controllable sockets. These are available from most retailers as Energenie sockets and generally come with a remote control and a combination of sockets. They work, but have limited range on the 433Mhz, again cannot be queried to find out if they are on or off and a lot of the commands are fire-and-forget (or hope for the best). I interfaced them with an Arduino using the 433Mhz transceiver pair but this still is a fire-and-forget so not really an ideal solution.

Onto my current idea, the TP-Link HS100 wireless switches:
These retail for around £25 each, so not the cheapest option, but they have some interesting features. Firstly they are wireless, so connect to your 2.4Ghz (only) wireless in the house, so anywhere you have wireless they will work. They can also handle up to 13Amp switching which is higher than most others (Although I'd still not connect it to a high load like washing machine, dishwasher, etc). And the even better bit, they use a communication method that can and has been tapped into, so over IP you can send commands to the units and query their status. Perfect for me as I want to use everything over my IPv4 (wireless) LAN at home to do the monitoring and control.
Researching them, there has been a very good reverse engineering job at https://www.softscheck.com/en/reverse-engineering-tp-link-hs110/ and the author has also provided a python script that will let you query and talk to the devices. This fits exactly with my home automation system.
Now, don't get me wrong, there is a flaw here, these units when you set them up, you install their app to your phone and configure their details using the TP-Link 'cloud' system, which means giving the app your wifi SSID and password, which sends it to the smart switch using a temporary unsecured WIFI AP in setup mode. The unit then talks to the internet/TP-Link cloud for it's command and control. So far nothing here looks too bad, other than it having the ability to snoop your home network and talk to TP-Link! However, since we won't use the TP-Link cloud for our control we could simply drop this and not use it even for initial configuration. Furthermore we can send a command to the sockets to change the server they talk to, in theory cutting them off from TP-Link completely, which if you're paranoid you can do. I'm not too worried about this, so will probably just leave them at default.

So now I have a socket that I can setup a static IP in my DHCP scope, and then use the python utility to query and send commands.
To grab the python code you need, take a look at https://github.com/softScheck/tplink-smartplug
So I setup a script to query my socket and write the current state to a state-file on my home automation server, the script was very simple:
tplink-smartplug.py -t 192.168.xx.xx -c info | grep "Received" | cut -d ":" -f 23 | cut -d "," -f 1 > /tmp/tplink_plug1.out
That gives me either a 1 or a 0 depending on the current state of the socket. To set the state you simply use the python script again:
tplink-smartplug.py -t 192.168.xx.xx -c on
It's as simple as that.
I cannot comment on the longevity of the devices, but so far they are built well, easy to setup and super-easy to use. So I think this might be a new winner for home automation, the only thing I'd like to see is cost drop a little more, but when you think everything that's in the box £25 is pretty cheap!

Let me know your thoughts in the comments please or if you've found alternatives too.
 

No comments:

Post a Comment