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
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.
Install node.js. Link here: https://nodejs.org/en/download/note - make sure you get the msi installer package, not just the exe binary
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.
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.
Log in to SmartThings IDE, then go to “My Device Handlers”. Click the green button for “Create New Device Handler”.
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).
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.
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.
There is a workaround for this 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.
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?
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.
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!
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?
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]
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:
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:
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.