TPLink HS100 – Python Package / Home Assistant

The TPLink HS100 Smart Plug lets you remotely control your electric devices, and best of all, it’s compatible with Alexa, and other Open Source home automation software such as Home Assistant.

The TPLink HS100 is as simple as it gets, plug to the wall socket, connect your device, set it up with the app, and off you go. By default, support is limited through Kasa (TPLink Smart Home app), and Amazon Echo (Alexa). Other features include Remote Access (wherever you have internet), through the Kasa App, Scheduling – Schedule the Smart Plug to automatically power electronics on and off as needed, like setting lights to come on at dusk or turn off at sunrise, Amazon Echo Voice Control – Amazon Echo (sold separately) lets you control devices connected to the Smart Plugs just using your voice.

Amazon Echo is getting quite popular among the home automation crowd since it easily enables voice control. I don’t have an Echo though, and I tried, but I couldn’t get it detect and work with the poor man alternative, AlexaPi, or Roger (Android app).

Thanks to George Georgovassilis, he was able to reverse engineer the command codes over WiFi and you can download his bash script to control the TPLink HS100 plug remotely.

But that’s still not good enough.

I recently started to dabble with Home-Assistant, an open source home automation software based on Python. It shows good promise and you can check out the demo for a quick look at what it can do. It didn’t support the TPLink plug but as it allows for custom development, I have created an add-on component platform to work with the TPLink plug. It integrates nicely with the rest of the Home Assistant switches, and it doesn’t just issue dumb commands of on / off. It is also able to check if the TPLink plug current on/off status.

The Git Pull Request has been approved, and should make its way to the next version of Home-Assistant.

Anyhow, you can check out the source code.

I have also separated out the codes into a Python package, pyHS100, so if you want to control it via Python, you can download that instead. It will also work with the TPLink HS110, which comes with an Energy Meter.

You can try it out as follows:

from pyHS100.pyHS100 import SmartPlug
switch = SmartPlug("192.168.1.105") #The TPLink HS100 / HS110 IP
print(switch.state) #check plug status
switch.state = "OFF" #turn plug off
switch.state = "ON" #turn plug on

Sean

Sean is a tech geek and star wars fan. He loves playing with new gadgets, writing little code snippets in Python, JS, and dabbling with Android programming from time to time, while keeping a lookout for the next biggest happening in the world of tech!

One thought on “TPLink HS100 – Python Package / Home Assistant

  1. Thanks. Looks interesting. I was annoyed to find that the remote capability required me to provide information about the latitude and longitude of the device (detected via gps-enabled device used to register). What legitimate business is it of TP-Link’s where the device is? Surely this is a security risk in the event of the company’s cloud services being compromised, giving prospective burglars good intelligence. And the data mining goes further with the free 3rd year warranty in return for registration. Oh, and the kasa app wanted access to all sorts of things including my photos on my phone. Where does nonsense end?

    I’d very much prefer to use open source devices, not to disclose my location or contact details. And in the meantime any software that can expose or bypass vulnerabilities is welcome.

    This may be of interest, albeit for the HS110, if you haven’t seen it:

    https://www.softscheck.com/en/reverse-engineering-tp-link-hs110/

Leave a Reply