I started this blog writing a series of articles about Azure App Service Architecture, mainly trying to explain and illustrate how I understand it works, beyond what one can find publicly in Microsoft (extensive) documentation. Then I got an HS100 TP-Link smartplug: a “connected thing”, a plug that is connected to Internet (don’t say that to any person, most will look at you like o.0?!), a plug that you can control from an App on your phone, from wherever you are: at home, or from outside: from anywhere in the world. And I guess Oops I did it again!
Interface the HS100 with everything
I couldn’t resist to imagine many potential applications and possible integrations with online (cloud) services that are publicly and freely available, like IFTTT; I’m also a big fan of Android Tasker, Node-Red, the MQTT pub/sub protocol, and Raspberry Pi / NodeMCU hooked with sensors and hardware pieces attached on the GPIO pins) that make more connected things, so literally ideas are all over the places in my heads, on papers, in Keep notes…
Like this one that just popped in my mind:
Switch off the main lights in the salon, dim the lights around the sofa and TV, power on the media server box (smartplug) and TV when I sit on the sofa, with a NodeMCU controller and a pressure sensor (FSR)! Or maybe I’d prefer to have all that triggered when I power on the TV, but only in a certain time slot?…
Told you I have crasy ideas ;). Totally got to try to do that BTW!
Error: Time not found
What I only lack really is time. First, time to try and make some of those idea work (they do eventually with perseverence and I always learn a lot in the process), then time to write about them (here).
I didn’t realize the time it take to write articles people need to write good articles. I usually take notes of what I do, notes that I understand, but publishing those is no value to anyone. You need to structure the ideas, give them some form so the result make sense for the reader, enough at least so they can be inspired in trying also themselves to do, learn and make something that work for them out of what I wrote. Unfortunately due to the lack of time, I don’t enter into too much details, and I assume the reader is tech-savvy enough to read, understand and try by himself. That means some reader gets frustrated because I missed some parts they didn’t know… Sorry about that.
Wins so far
Back to the HS100: there were some (very good) resources publicly available already out there that showed how to interact with an HS100 plug, from shell scripts based on cURL, php and python libraries or Node.js modules, even a Node-Red. But they all had the same problem: they only worked withing the same local network (WiFi/LAN) the plug was connected to. Ugh bummer.
The Kasa App and the Alexa integration were proof that TP-Link was hosting a cloud service, but no API was publicly available yet.
So I started to work on figuring out how the App talked to the TP-Link Cloud endpoint, and started to publish it here. The series got (modestly) popular among the maker and tinkerers ;), and people used the comments to exchange ideas, issues, and come with solutions. So far, I’ve published (not in chronological order)
- Retrieve token and deviceID from Kasa App on Android (this is how everything started)
- Login to TP-Link (with your username and password) and retrieve token
- also …with Tasker
- Retrieve the cloud end point URL and list of your TP-Link devices (with deviceID)
- Set the plug state (on/off) remotely (once you have Token, DeviceID, and URL)
So far the whole process was rather hacky and manual I reckon, but still one could achieve the goal of switching a smartplug from a remote place (outside of the smartplug local network), like from one’s smartphone (Tasker), or an IFTTT recipe. It already enabled some cool logics.
Pitfalls: what about scenes?
Soon after having found out how to trigger one TP-Link HS100 smartplug, the most frequently asked question in the comments has been ¿how can I power On/Off multiple devices from ITFFF?
After all it’s a feature that people know from the Kasa App: you define buttons in the app that will put several of you smartplugs in a state you define.
Related to my idea above, a scene would be:
“Time to watch some TV” scene: Switch off the main lights in the salon, dim the lights around the sofa and TV, power on the media server box (smartplug) and TV.
You can define that in Kasa, but what about calling it from IFTTT? You can’t. You can only call one POST call (via Maker), in an IFTTT recipe.
The second to most request in the mind of all is probably related to the TOKEN that will eventually expire sooner of later, making it a hassle to edit all your IFTTT Recipes/Tasker tasks/whatever scripts… manually!
Well, I’m happy to say this was until now!
More Wins coming soon…
This week I’ve been working hard on this (it’s the second time I try it, and this time I made it!).
This is what I have done:
- I’ve created a node.js module to easily interact (power On/Off, get state) with any number of HS100/HS110 smartplugs and LB100/LB110/LB120 and LB130 smartbulbs (set on/off, set brightness, set color). The module handles the login, token retrieval, and device triggering, in almost no call.
- I’ve created a Glitch example app in which one can define scenes. As Glitch publishes a URL, you can then trigger one “scene” with only one call (http://url.glich.me/scene1/) and with only one POST call it will do whatever you want to! Not only that but you can even define as many scenes as you want in a single Glitch app ( each with a different end-point: http://url.glich.me/scene2/, http://url.glich.me/scene3/…).
- Next I will create a library of new TP-Link Node-Red nodes to control the smartthings from Node-Red!
All that is already working fine for me, so this is what I’ll talk about in next posts (and I’ll publish the code for everything 😉 ) when I get some more time to talk about it. (Believe it or not, it took me more than two hours to write this post)!
So, stay tuned if you are interested. I suggest you follow me on Twitter, and follow this blog, recommend on Disqus (the heart icon).
Ah and well… all this is free, but you might see some interesting (or not) Ads around my content. I won’t mind if you all start clicking everywhere. I’m not suggesting anything… :p