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

2017-05-07T14:02:43.817Z
Sending to IP address: 192.168.1.62 Command: deviceCommand

2017-05-07T14:03:41.971Z
Sending to IP address: 192.168.1.62 Command: deviceCommand

2017-05-07T14:03:49.471Z
Sending to IP address: 192.168.1.62 Command: deviceCommand

This is whats shown…

Have you added a device handler? Having a quick look I appear to be using the one from @dbej (should probably update to @Gutheinz’s one, but I only have sockets at the moment).

My device preferences look like this

EDIT: Sorry - if you’re seeing that, then you must have a device handler. Can you type ping 192.168.1.62 into your command prompt?

Pinging 192.168.1.62 works just fine.
I have a device handler indeed, should I try replacing it with the one from original poster?
https://github.com/DaveGut/TP-Link-to-SmartThings-Integration is the one I used

Ok, I replaced the one from Gutheinz with the one from dbej and got it working!
How did you setup getting it to start with Windows? I do IT for a living, but getting a bat file to run in task scheduler correctly can be quite a challenge at times:/

Hm. Just having a quick look at the code.

When you activate in ST, the groovy script should be sending a packet containing:

command: deviceCommand
tplink-iot-ip: xxx.xxx.xxx.xxx   # (your device's IP)
tplink-command: '{"system":{"set_relay_state":{"state": 1}}}'  # if switching on

This gets passed to the node server, which should then run the tplink-command but instead is trying to run the command which doesn’t do anything.

@Gutheinz it looks like you’ve got a variable reassignment issue in your node script.

@MortenB if you edit TP-LinkServer.js lines 53, 55 and 62 and change references to command to tpCommand it should start working

EDIT: 3 lines to change, not two

Thanks, Ill stick to the one Ive got working. But there is no 2way integration it seems? If I physically push the on/off button on the switch or use Kasa app, Smartthings cant pick it up?

I got them for like 1/3rd of the price of Z-Wave switches, but would be nice to know the status…

It should poll for updates. Possibly now you’re using a different device handler the polling isn’t getting back to the groovy script

I did replace the device handler too, followed the guide in the OP.

OK, it seems it was my fault. I used the wrong device handler version, I reinstalled the one from Gutheinz, and it fixes the stuff you pointed out @jymbob.
I can now control it with his code also. Though I need to manually hit refresh to get the correct status… Any way to fix that?

I’m not really up on how polling works, but I think I’m seeing updated statuses fairly quickly. I haven’t opened the Kasa app in a few weeks now.

Jymbob, you are correct. The incorrect TP-LinkServer.js was loaded to github. the correct version is there now (and tested).

Polling is calling the refresh command. The frequency is completely controlled by smartthings (i.e., this code does not initiate polling). Is there a way to set the frequency?

Curiosity, what version of the DH are you on?

MortenB,

I have the same issue - very occasionally. I set the DH as a state machine, where I use a different color/label when it is turning on/off and the state updates to the new state when return data received from the bridge.

When it occurs, I think it us usually the ST server (the command return was sent, etc). There is no log in ST. I have not figured this out. Polling will correct the state miss-match on the next poll, or refresh.

  1. Explicitly what device? Firmware version? DH name?
  2. Below is what the log looks like - indicating a round trip through the server. (This is on version 2.3). Anything else indicate an error in the bridge - device communication.

2017-05-08T12:41:12.887Z
Sending to IP address: 192.168.0.137 Command: {“system”:{“get_sysinfo”:{}}}
Command Response sent to SmartThings!

There are only two other cases possible:
The bulb communications time out. The console message will look like:

(node:8764) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Device TCP timeout

and the ST tile will turn orange with the label bulb or plug off line. This means that the TCP command to the TP-Link device timed out - either device is off, offline (known problem with bulbs) or the IP has changed.

The final case is a TCP error (I have never seen this error). Error will display on the console. this is an automatic message; however, I have never seen it. (future update?

In my DH, there is an automatic polling. About every 15 minutes (just re-confirmed by looking at ST events). This DH does not go through the TP-LInk site (not currently feasible), so it knows only it’s own state.

It turns out I’m entirely wrong. I don’t seem to see any polling updates here using Dan’s code. Sorry for the misleading posts.

In other news, one of my switches is the HS-110. If you’ve got any code around getting energy usage out you want testing, let me know. I might have a tinker myself at some point, but right now I have actual work to do!

When you say display energy usage, are you talking about the current energy usage (relatively easy to integrate) or the daily/monthly sums (requires some math functions summing data from bulb). If the first, a relatively easy mod to existing DH. Other, more complex.

Current energy usage. Here’s what the Kasa app shows at the moment:

jymbob,

I have created a prototype for “Current Power” only. Tested on a bulb, so logic works. Issue will be format of the returned data. The below link is where the groovy file is located. The “TP-LinkServer.js” file is the same as for my Version 2.1, 2.2, and 2.3 systems, so you do not have to run separate node.js app. The read-me has some more info for you.

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

Thanks. I’ll have a play at the weekend.

Suddenly thought to myself: “How does Google/Alexa authenticate with TP-Link?”

Then I found https://api.tplinkra.com/

So far I’ve only found a status page https://api.tplinkra.com/v1/iot/healthcheck but someone with more knowledge of grepping sites than me might find this useful.