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

This how-to was originally posted inside of this thread. I am starting a separate thread to gain additional visibility for anyone who is looking.

Special thanks to @dbej for creating the DTH and code for this, this is all his work. I’m just the messenger :wink:

Note: This setup requires the use of an internal “gateway” server/PC that receives commands from the SmartThings hub and translates/forwards them on to your TP-Link HS-100 outlets, so it’s more complex than the typical smartapp & DTH type integration. The instructions below are specific to a Windows environment, but several community members have been able to accomplish the same integration using a Raspberry Pi or similar. While @dbej used Docker to get this up and running, I am using a node.js command prompt instead, so keep in mind that there are other ways to do this that may be better suited to your needs.I recommend reading the original thread linked above to catch up on all of the conversation around this integration.

Pre-requisites:
- Windows machine that stays turned on, logged in, and connected to your local network all the time. This will be your gateway PC
- Static IP address for your gateway PC. Assign through your router.
- Static IP address for each of your TP Link smart outlets (you can find the MAC addresses for your outlets in the Device Settings page in the Kasa app if needed)
- I recommend disabling automatic updates on the gateway PC so it does not auto-restart and kill your node.js session. Do this at your own risk.

  1. Install node.js. Link here: https://nodejs.org/en/download/ note - make sure you get the msi installer package, not just the exe binary

  2. Download the zip file from @dbej https://gist.github.com/danlogan9/66b8ed43c1cb372e3811756a737397b2/archive/f2d72911e57c44b5620f9bdeaffbd94a62d37ea1.zip

  3. Extract the zip file to whatever location you want. Name the folder something rational. For these instructions, I put the files in c:\test\hs100

  4. Open a command prompt and navigate to the folder where you extracted the zip file from @dbej and run the command “npm install”. This will install the current 0.3.0 version of the hs100-api.

  5. Go back to your command prompt, go to the hs100 folder, and run the command “node hs100.js”. This starts the gateway server listening for commands from SmartThings hub to forward to your TP Link outlets. This window has to stay open for this to work correctly. If it closes, the outlets will stop functioning with SmartThings.

  6. Log in to SmartThings IDE, then go to “My Device Handlers”. Click the green button for “Create New Device Handler”.

  7. On the Create New Device Handler page, choose the “From Code” option at the top. Paste in the raw groovy code from dbej site, then go to the bottom and click the “Create” button. https://gist.githubusercontent.com/danlogan9/66b8ed43c1cb372e3811756a737397b2/raw/bcd97ef4ded9d44075cb60dc0ef916a2d206e0b6/tplink-hs-100.groovy

  8. On the next page that opens, click Publish, then For Me.

  9. Go to My Devices in IDE, click on New Device in the top right corner (you will repeat this step for each of the outlets you have)

    • Name - enter a unique name. I have 3 HS100 outlets, and named them HS100-1, HS100-2, HS100-3.
    • Label - enter a label, this is what will show in the SmartThings app
    • Device Network Id - enter a unique ID. I used tplink001, tplink002, and tplink003
    • Type - select tplink-hs-100 from the drop down list (should be at the very bottom of the list)
    • Version - Published
    • Location and Hub - select for your setup
    • Group - leave blank for now, you can assign to a room later through the app
      Click Create
  10. Now that your device is created, you need to specify the IP addresses for your gateway PC and each outlet. To do this, click on “edit” next to Preferences (or find the outlet in your list of Things in the ST app, and go to settings).

  11. Enter the IP addresses for the outlet and gateway PC, then enter port 8083 (I believe this can be changed by editing the hs100.js file, but default is 8083). Click Save.

  12. Profit

Go into the SmartThings app, and you should now see your new outlets in your list of things. Turn one of them on and off a few times. Watch the command prompt you left open, you should see log entries for on and off, and your outlet should be turning on and off.

4 Likes

There is a workaround for this :slight_smile: Windows 10 allows you to define certain wifi networks as metered (data-capped) connections. When you do this, it effectively disables automatic updates. To do this, go to Start → Settings → Network & Internet. Then go to Advanced options:

On the next screen, turn on the “Set as metered connection” option. I’m on my work computer right now and corporate policy has this option disabled (which is why it’s grayed out in the screenshot below), but you should be able to do this on your home computer.

2 Likes

Sorry if this has been answered before, but what is preventing the hub from sending the commands directly to the sockets instead of using the gateway as a middleman? Is it just that the node code has not been ported to run on the hub or is there something lacking in the hub capabilities?

Thanks

From the original thread:

I haven’t tried using a hardwired connection. Not sure about this one.

I read that as literally power sockets rather than the udp / tcp kind! I’ll read up on this as it seems to be a poor limitation, many thanks for your help.

1 Like

Fantastic code @dbej and great write up @destructure00

I’m new to SmartThings but had already purchased a few of these tp-links for around the house so I was bummed when I saw they were not supported. This solution worked great!

One small piece of information that I will attempt to research is it doesn’t appear to function over Layer 3. If the gateway server and the tp-link device are on different layer 2 networks I never see any communication. I moved the package over to a machine I have on the same subnet and it worked perfectly. I’ll try to see anything in the code but I’m assuming its just missing a portion to throw a network gateway between the Gateway Server and the tp-link devices. I’m certainly not a coder but I’ll be happy to attempt to give it a look. If @dbej knows the segments to add I still have the VM spinning in my lab on a different L2 network and I’d be happy to test this functionality if added. If not as this might not be a feature that is widely used I completely understand but wanted to at least offer something back

Again thank you so much for the level of effort that went into this! Its a really positive first look at the ST community!

1 Like

FYI, in case someone missed the post in the previous thread I created a docker instance here:
https://hub.docker.com/r/aapocketz/hs100-smartthings-bridge/

If you have QNAP, just search docker hub in the container station for hs100

For synology: https://www.synology.com/en-us/knowledgebase/DSM/help/Docker/docker_container

On linux terminal you can run
docker pull aapocketz/hs100-smartthings-bridge

make sure you set it up to run automatically

2 Likes

Just got my smarthings hub for Christmas and already had some tp-link outlets. This is my first time attempting something of this nature. I followed the directions, but I get an error when I attempt to turn on/off the outlet.

Trace: { Error: connect ECONNREFUSED

It’s obviously attempting to turn it on/off and communicating to the command prompt. Is there something i could have missed that is causing this error? Thank you for your help.

Hey guys. I have this working great, but one thing I’m missing. My crappy router is being really bad at reserving addresses for the plugs so their ip’s keep changing. In the pre requisites listed at the top it stats a static ip for each plug. I can’t for the life of me find out how to set statics on them, the app doesn’t allow it as far as I can see, is there a web gui or something for them? Cheers all.

IP addresses are typically assigned through your router using DHCP. Some devices allow you to set a static IP on the device end, but as far as I know, the TP-Link outlets do not have this ability, so unfortunately you’re left with having to do it through the router. What’s wrong with the router that it won’t set static IP addresses?

1 Like

I’m reserving them in the router but every so often one of my plugs just stops working via smartthings so checking my dhcp list I see that despite it still being reserved via MAC address, it has a new ip and I have no idea why! Quite annoying as I have 5 tp-links and this week at some point or another one of them has changed IP!

Any chance your router needs a reboot before the reservations take effect? My TP Link router has to be rebooted whenever I add a new address reservation.

There are a few was to rectify the reboot and your app not coming back to life. Try creating a custom service with some of the suggestions in the post below. SC command is awesome for doing that. I’ve used SRVANY executable many years back to accomplish this need (second link).
[http://stackoverflow.com/questions/3582108/create-windows-service-from-executable]

1 Like

Is there any way to do this at startup e.g. via a batch job? I just had a powercut so trying to find a way to automate this.

Thanks in advance

I created a .bat file for this and put it in my Startup folder. I’ll post the specifics when I get home from work.

I just remembered, the startup folder will only run after you login. So keep that in mind. You may be able to follow @JZst directions to start something like this as a service in the background so it will run before login, never done that so I can’t help with that one.

Anyway, to create a startup .bat file:

Hit Windows Key + R to bring up the Run dialog. Type in shell:startup

Create a new text file in your startup folder. Enter something like the following, replacing my hs-100 path with yours.
“cmd /k cd c:\users\chris\onedrive\documents\github\hs-100\ & node hs100.js”

Save and close the file. Make sure you can see the file extensions in your folder view, then rename the file something like hs100.bat, making sure that you actually change the file extension.
Before:

After

Yep but the problem is that you’d have to log in for that to fire, can’t just leave a PC after a reboot otherwise won’t fire. The other two simple options are below and they will fire up on startup:

  1. Task Scheduler has a trigger called At Startup which will launch a process at system start.
  2. Use local/group policies to add a startup script.
1 Like

Anyway to get this to update the status of the switches in Smartthings? Right now all that I can do is turn off or on the switches but I would like the status of the switches to be triggers for additional actions. Since I mostly turn the switches on and off with Alexa the current state of the switch is often inaccurate in Smartthings.

Simplest way would be to use Alexa to turn on/off the SmartThings switch instead of using the direct TP Link integration.

I think someone created a core piston to refresh switch status every so often, so that may be another solution.