TP-LINK HS110 Smart Plug w/ Energy Monitoring, Wi-Fi Enabled

Oh, my bad! Thanks for the response. My apologies!

1 Like

Hi, I’d very much appreciate a little help…

Presently when I run “node hs100” I get the message “The HS-100 controller has started”, but I receive no further messages, and the HS100 does not respond to toggling the switch in ST (or vice versa).

I’m running Raspbian Jessie on a PI3. I have node 7.2.0 installed, and I have installed hs100-api@0.2.0
The Gateway IP/Port and Outlet IP are definitely set correctly in the ST device.
The HS100 correctly responds to the standard Kasa app.

Any ideas how to resolve?

Thanks in advance.
Chris

Just wanted to throw this out there as I did not see any mention. The method to get this working for the plug also works with the tp link smart switch. https://www.amazon.com/TP-Link-Required-Fixtures-Anywhere-HS200/dp/B01EZV35QU
Thanks for all the hard work on this!

Hi guys. I finally had a few moments to update the hs-100-api calling code to be compatible with his v3.0 code. I have been running it against my plugs and it operates as before. I also put the code from @destructure00 that outputs the additional commentary as to what has happened when you make a call.

@ChrisM. I am running node 7.2.0 also. Lets try this:

  1. ssh in to your gateway. Update to the latest code. Start the hs-100.js from the terminal with
    node /hs-100/hs100.js.
    This will let us see messages being outputted as you are making calls.

  2. From a different ssh, run the following. Edit it to put in the IP of your outlet and your gateway
    curl -H “x-hs100-command:on” -H “x-hs100-ip:[plugip]” -D - [gatewayip]:8083
    curl -H “x-hs100-command:off” -H “x-hs100-ip:[plugip]” -D - [gatewayip]:8083

  3. Those to curl commands will turn the outlet on or off just using the gateway, removing the DTH and ST from the mix for testing. If you hear the relay kick on and off, we have to look at the DTH. You should also see messages on the gateway similar to this following.
    Sun Dec 04 2016 20:01:49 GMT+0000 (UTC): OFF commmand sent to xxx.xxx.xxx.xxx
    Sun Dec 04 2016 20:01:49 GMT+0000 (UTC): ON commmand sent to xxx.xxx.xxx.xxx

  4. If you don’t see the messages or hear the relays we will have to troubleshoot a few other things.

1 Like

Thank you so much for posting the update! I was literally in the middle of troubleshooting my own rig when I saw your update, worked like a charm, thank you! Perfect timing!

For those of you trying to get this all to work on a Raspberry Pi 3 with npm/node, here’s what worked for me. (This assumes you have node/npm already setup).

  • Download @dbej’s github zip to the Pi
  • Extract the files to a new folder, I named mine ‘hs100’
  • Open the terminal, change your working directory to the new folder - cd hs100
  • Next install the node with this command npm install
  • Lastly, use this command - node hs100.js to run it.
  • Next, reference @destructure00’s post, and follow steps 9 through 15., use your Raspberry Pi’s IP address as the Gateway IP.
  • Don’t forget to Profit.

Thank you @dbej and @destructure00, you guys are the folks who make this community awesome!

1 Like

Hi @dbej,

Many thanks for the quick reply.

I’ve updated hs100-api to V3.0, replaced hs100.js & package.json with your latest versions, and updated the ST DTH with your latest tplink-hs-100.groovy.

Following steps 1 & 2 in your last email does turn on/off the HS100, and messages are output as per your step 3 - progress :slight_smile:

However, still nothing when trying to change state from ST - Any ideas now to sort out the ST end?

Thanks again,
Chris.

Thanks for the update! I updated my instructions above to reflect support for v0.3.0.

@ChrisM, what do you see when look at the DTH in Live Logging tab in the ST IDE? With the default messages I left in the DTH, you should see some outputs similar what is in the below image. You can filter the Live Log to just your HS100 device to keep the messages just the device by clicking on it above the Logs area. You can either load the DTH in to the simulator and execute ‘on’ and ‘off’ for the switch capability or toggle the switch in the ST app to cause the DTH to output the messages.

@dbej Here’s the live logging output when I toggle the switch in the ST app.

Thanks.

Lets verify a few things. Can you replace the executeCommand() function with this one? I just changed few of the log outputs. From what I can see, it looks like it makes it the sendHubCommand call. I can’t tell if it makes it through it though. You are definitely not getting a response back from the hubActionResponse or parse functions, which you should after the ST hub executes the call. I know you said you have the IPs setup correctly but can you double check to make sure the IPs line up for the gateway:port and outlet you are calling?

private executeCommand(command){

    def gatewayIPHex = convertIPtoHex(gatewayIP)
    def gatewayPortHex = convertPortToHex(gatewayPort)
    //device.deviceNetworkId = "$gatewayIPHex:$gatewayPortHex"
    message ("deviceid:'$device.deviceNetworkId'")
    message ("gateway port: $gatewayIP:$gatewayPort")
    
    def headers = [:] 
    headers.put("HOST", "$gatewayIP:$gatewayPort")    
    headers.put("x-hs100-ip", outletIP)
    headers.put("x-hs100-command", command)
  
    message("x-hs100-ip: '$outletIP'")       
    message("executeCommand: '${command}'")
    try {
      sendHubCommand(new physicalgraph.device.HubAction([
          method: "GET",
          path: "/",
          headers: headers], 
          device.deviceNetworkId, 
          [callback: "hubActionResponse"]
      ))
      message ("executed sendHubCommand")
    } catch (e) {
      message(e.message)
    }
}

sendHubCommand seems to be bit tricky sometimes. I used an alternate parameter for the callback function (as opposed to the default parse) in the one above because I had some trouble with the normal call. I am not sure if it is expressly supported but it works well for our scenario of needing a gateway. It could be causing your grief. You can try the function below to see if you see the as expected behavior on you ST hub. It is more or less the way it is supposed to be called according to the doco. You may not see any logging information when you use it, even if it seems to be toggling the relay. If that does work, there are still some other issues to work through in getting the app to reflect the correct on/off status.

private executeCommand(command){

    def gatewayIPHex = convertIPtoHex(gatewayIP)
    def gatewayPortHex = convertPortToHex(gatewayPort)
    device.deviceNetworkId = "$gatewayIPHex:$gatewayPortHex"
    message ("deviceid:'$device.deviceNetworkId'")
    message ("gateway port: $gatewayIP:$gatewayPort")
    
    def headers = [:] 
    headers.put("HOST", "$gatewayIP:$gatewayPort")    
    headers.put("x-hs100-ip", outletIP)
    headers.put("x-hs100-command", command)
  
    message("x-hs100-ip: '$outletIP'")       
    message("executeCommand: '${command}'")
    try {
      sendHubCommand(new physicalgraph.device.HubAction([
          method: "GET",
          path: "/",
          headers: headers], 
          device.deviceNetworkId//, 
          //[callback: "hubActionResponse"]
      ))
      message ("executed sendHubCommand")
    } catch (e) {
      message(e.message)
    }
}

@dbej, is there any benefits in me updating to the new code and version? I ask because it’s running pretty stable as it is now with previous versions and code and wondering if I really should tinker with it.

There isn’t anything new for someone already running the original version. It will just work out of the box for anyone starting fresh. If what you have works, I’d say let it be.

Curiosity got the better of me and I did the changes. Changed the device handler code then redid the node part and for the life of me it wasn’t working. It would show the command but wouldn’t reach the host. After some quick thinking I realised by fiance had unplugged the smart switch…a few private mental expletives later I plugged it in, rebooted my pi and it’s all working. Don’t notice any differences in trigger speeds but it wasn’t slow to begin with so all in all I’m still very happy.

Thanks again for your work Sir!!!

1 Like

Hi @dbej,

I have tried both versions of executeCommand(), neither do anything on the HS100.

Here is the log from the first version:

And here is the log from the second version:

I have double checked the IP addresses & port, and these are OK… Incidentally, I did previously get the HS100 to respond with the commands below, so this would confirm that the addresses/port that I am using are correct - right?
curl -H “x-hs100-command:on” -H “x-hs100-ip:[plugip]” -D - [gatewayip]:8083
curl -H “x-hs100-command:off” -H “x-hs100-ip:[plugip]” -D - [gatewayip]:8083

Any further ideas? - I do very much appreciate the continued support.

Thanks.

Hey @ChrisM. Hmmm, I not sure. Looking at that output it appears that it is making it all the way through the sendHubCommand call. There are not any of the call back messages though from either ‘parse’ or ‘hubActionResponse’. Not that I would expect it to make much difference, can you send a reboot command to the hub using the utilities under my hub? I would also suggest pushing reset on the config and code by deleting and re-adding both the Device and Device Handler from the ST hub. Since those cURL calls worked, we can say with some certainty that it is something in ST that is causing the issue.

is there a way to set a static IP? Every time the router resets a new ip is assigned and i have to update the ip for each device.

Your router should be able to do this. Access your configuration page (usually 192.168.1.1 or 192.168.0.1) and look for the DHCP section. There’s usually a page for Address Reservations or something similar. You’ll add the MAC address for your plug and give it a static IP.

all work perfectly but the status of my outlet in the app don’t change when I activate manually the switch. It’s normal the current state don’t change manually

I think that’s normal. The Tp link kasa app updates if triggered manually, but not smart things. Incidentally my Internet was down today for the entire day due to a billing issue and I had to manually turn on my lights etc (so not used to that anymore lol). The Tp link switches were still functional via the Kasa app though even without an Internet connection…it really showed up the smartthings app in that regard. I wish they would have a local only mode somehow…

I understand, but the current state is necessary for the reliability of system. When I create automation, if the outlet is On for the Smartthings but not in real, my routine don’t work perfectly.

Is it possible in the device Handler to create a button On and Off (not just the toggle switch) for have possibly Press it ON even if it is already ON .

If press manually Off, is On in the smartthings but routine press On anyway, I would be sure that my sequence will work.