[HOW TO] Add your TP-Link HS-100 Wifi outlets to SmartThings

MortenB,

Do you still have to refresh to get the correct status? Does you log look like I mentioned earlier (two line display with final line saying response sent to SmartThings)? There is one case where a null response can be sent - socket.on error. I am adding capture code to provide details to the log/smartthings in a future release. I can prioritize if desired.

UPDATED on 5-16-2017. Incorporated error handling, improved program flow, added auto-schedule of weekly and monthly stats just after midnight. Requires new DH and new prototype.js file.

Next step - integration with rest of TP-Link line in version 3.0. Probably next week after I fully test prototype.js versus existing DHs.

I just updated the test software to provide full energy monitor functionality.

2 Likes

TP-Link provided either the SW or an API for google and amazon. It is not available to the general user. The DHs that are written in this thread do not require TP-Link authentication nor their server. Therfore, path is simpler.

Some lesson learned during HS110 development that some others may be interested in. I am using Node.js and TCP.

  1. For the emeter messages, the single return is frequently turned into two separate data streams. Using socket.on(data… will then give in incomplete return that JSON can not parse. I had to concatenate data returns and delay decryption.

  2. I noted during testing that sometimes after sending a valid command to a bulb, the socket.on(data, does not process data from the bulb. It was usually when I set the timeout to other than zero.
    dave

I just recieved an email from TP-Link stating Kasa now works with Nest thermostats, so hopefully SmartThings will follow soon.

“We Work with Nest. Good news! All of our smart products now work with Nest Thermostat’s Home and Away Mode. You can use one of the scenes you already have or create a new one through the Kasa app. From the home screen on the Kasa app, tap the “+” sign and click “Works With Kasa” to get started.”

Being Verbose.

TP-Link is using the KASA app as a launch point for their eventual (and overdue) SR20 Router with integrated Z-wave and Zigbee. Good news - another choice. Bad news: a. They are starting at the same point as SmartThings did several years ago with limited product baseline outside the z-wave/zigbee realm. b. Seems to be closed (i.e., no third party support yet available). c. Currently appears to run exclusively through the TP-Link portal and with other accounts for LAN devices. d. Probably means that TP-Link will not develop Smart Things Support.

I would still like SmartThings to support direct control of TP-Link plugs, etc. over the LAN (w/o bridge or connect to TP-Link). I know everything is feasible (been there, done that) and I understand ST wanting to control UDP. Anyone who can finalize this is welcome to my code w/o restriction to use, pillage, or throw away.

My unpublished code uses the bridge strictly as a bridge and for encryption; however, I have code that does encryption in the DH that has been tested. I also have Service Manager code finished that installs and manages the bridge and devices; including managing IP changes. The only bridge functions are encryption, HTTP to UDP, and a short UDP discovery routine (25 lines counting formatting the data for return to ST). (This is still undergoing testing. for each test, I have to change the device static IP (to force a change) then see if missing is detected automatically and update complete. Kind of cumbersome.

OK. Found some free time. Sorry for the delay.

Here’s what I’m seeing

On/off functionality appear to work just fine.

Code from console

Sending to IP address: 192.168.1.201 Command: {"emeter":{"get_daystat":{"month": 4, "year": 2017}}}
Response Data:     {"emeter":{"get_daystat":{"day_list":
[{"year":2017,"month":4,"day":19,"energy":0},{"year":2017,"month":4,"day":20,"energy":0},
{"year":2017,"month":4,"day":21,"energy":0.006000},
{"year":2017,"month":4,"day":22,"energy":0},{"year":2017,"month":4,"day":23,"energy":0},
{"year":2017,"month":4,"day":24,"energy":0},
{"year":2017,"month":4,"day":25,"energy":0.020000},
{"year":2017,"month":4,"day":26,"energy":0.126000},
{"year":2017,"month":4,"day":27,"energy":0.261000},
{"year":2017,"month":4,"day":28,"energy":0.152000},
{"year":2017,"month":4,"day":29,"energy":0.111000},
{"year":2017,"month":4,"day":30,"energy":0.204000}],"err_code":0}}}
Command Response sent to SmartThings!

Quick gotcha - the version of Node in the Ubuntu repositories is out of date. Use these instructions to update.

I have updated to device handler and tested versus the data you provided. Place at same location as previous. The read-me tells you a short cut to update this driver (in case you are not familiar).

Open item - I have to work on automatic updates and assure they will work. For now, turning switch on or off and Refresh update today’s data. Refresh Stats update monthly/weekly stats.

Risk 1: Still may not work with TODAY’S data. I had to guess there.

Risk 2: May not exactly match Kasa app on reporting total and average data for month, week. Can work later this fine-tuning.

:+1:

Looking good, thanks!

Kasa below:

I’m fairly new to all this, so I don’t really have a view on what information is useful for scripting. I know I use Current Power on my SmartThings plug (to determine if the TV is on standby), and I can maybe see a use case for Today’s Usage and Today’s Runtime.

We hit it on one iteration? Miracle. Thanks for your assistance.

In early June, I will be releasing a new version of the entire package (all TP-Link plugs, switches, lights). It will include all current devices with energy monitor for the HS110 only. Code is already complete, i am just exercising in an bridge with a log file.

regards, Dave

1 Like

One more error corrected. I was using UTC (Zulu) date for the calcs. Needed to use local date. Updated code to grab date from plug.

New code is on the gitHub server. To initialize the date and automatic scheduling functions (date and week/month stats), use the SmartApp. Go to details page, then settings (upper right corner). Press “DONE”. This should cause an update to this code and set the current date values for the device.

@aapocketz are you going to update your docker with the new version?

Thanks

First, I want to move these discussion to the thread: " TP-Link Bulbs and Plugs Control". That is specific to the DHs that I work and we are intruding here.

Thanks for asking. I am a 67 year old novice programmer. I do not know how to create Docker files; but, I will look into it and will if I can.

I have kept the files structure flat and only call to native node.js elements (specifically HTTP and UDP (or NET).

The next version will be out shortly after the 1st. It will include refinements on the SmartApps interface, more complete error passing to the cloud, and the HS110 implementation. Hopefully, the SmartThings application implementation will also be updated.

Jymbob,

The monthly stats may not be working. I found an error where my test bulb would not respond to the UDP today (it did yesterday). I think the UDP response is limited in size.

IT IS NOW FIXED with new device handler and new prototype.js file at:

https://github.com/DaveGut/Prototype-HS110

Note. A full update to everything to a single baseline is planned this week. There will be a single node.js applet plus updated device handlers for all current TP-Link switches, plugs, and bulbs.

3 Likes

Everyone

The update to version 3 is now available. Details are in the " TP-Link Bulbs and Plugs Control" thread. Update provides some enhancements, but unless you want the HS110 device handler, not necessary. (If it ain’t broke, don’t fix it).

Again, please direct comment to the threat " TP-Link Bulbs and Plugs Control".

Dave

Just put your code to use today… WORKS BEAUTIFULLY WITH SmartThings and my Tp-Link HS-200 switches are working with SmartThings. Thank you so much. I have one question, don’t know if it’s possible to do…

I have 4 Hue bulbs that I want to control on/off when I press the Tp-Link switch.
When I press the Kitchen Table Switch (Tp-Link HS200) on in SmartThings it turns on the 4 Hue bulbs (table 1, 2, 3 4). Off as well. Perfect. It is in SmartThings as a switch, that switch has smart lightning set to turn on the 4 bulbs through the app.

Since the HS-200 is not “wired” to the fan lights (1, 2, 3, 4), I press the switch it goes on/off, but of course the lights I have linked through SmartThings do not go on as well.

Is there a way that when I press the switch (on, it also turns on my SmartThings switch which would then turn on my 4 light?

1 Like

The easiest way would be to create an automation routine, select the switch and bulbs, and use that as a hook. It goes to a different page in the phone app. There may also be some way with CORE pistons, but beyond my current experience. Next learning project for this old man.
PS - if you are using Amazon Echo for voice control, the automation routines become single actions to turn on (i.e., Alexa turn on fan, turn off fan). Might also be true for Google Home.

1 Like

Hi,

I have installed node onto my raspberry pi but the node hs100.js throws an error
pi@raspberrypi:~/Downloads/hs100 $ node hs100.js

/home/pi/Downloads/hs100/node_modules/hs100-api/lib/client.js:3
const dgram = require(‘dgram’);
^^^^^
SyntaxError: Use of const in strict mode.
at Module._compile (module.js:439:25)
at Object.Module._extensions…js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object. (/home/pi/Downloads/hs100/node_modules/hs100-api/index.js:4:11)
at Module._compile (module.js:456:26)
at Object.Module._extensions…js (module.js:474:10)
at Module.load (module.js:356:32)

is it supported as I could not get it working on my win 10 box server runs but no off and on through smartthings works frin through the tplink app ??

cheers

The errors is in the HS100-api files. I no longer use these, so others, please chime in.

You may want to try re-installing the HS100 api files (follow instructions explicitly).

Additionally, what version of node.js are you using? On versions before 4.x this error may occur. See the responses to:

If that does not work, there is another available solution. See the thread ‘TP-Link Bulbs and Plugs Control’. (Disclaimer - I am the author of these DHs and Server App. I do not think they are better than nor worse than the application in this thread, just a different approach.)

PS - If you change, please make all discussion of the ‘TP-Link Bulbs and Plugs Control’ in that thread.

Just a heads up for anyone who has the same problems I did. I installed it onto my raspberry pi v3 running raspbian. The default installation of node.js is from the 0.10 branch and caused the following:
TP-LinkServer.js:114
socket.on('connect', () => {
SyntaxError: Unexpected Token )

Updating my installation of node to 7.10.0 fixed it. To do that I added the NodeSource repository:
curl -sL https://deb.nodesource.com/setup_7.x | sudo -E bash -
and then installed it with:
sudo apt-get install nodejs

Besides that I registered the script with systemd so that it would autostart with the system and restart if the service crashed and everything else went perfectly! If anyone needs me to go over that I can.