TP-Link/Kasa Bulbs and Plugs Control (Old, Unofficial Integration)

Sadly, you need a hub. SmartThings does not support direct TCP comms on the Local Area Network and TP-Link has not uncovered their API for control through their server. If either did this, we could create code for you to load and go w/o a separate hub.

What is a hub for TP-Link? The simplest is a Windows 10 PC, Laptop, tablet or stick PC running Windows 10. Least expensive is the tablet (Fry’s has had one on sale several times for under $60, Amazon for under $100. I do not check e-bay).
Installation does not take specific programming experience, but may be include things you usually do not do. I have generated some detailed instructions at site in this thread for the Beta System. Read them BEFORE proceeding to assure you are comfortable.

First, the hub is configured to auto-start and never go to standby (takes < 10 minutes - I have instructions). Then:

a. Install Node.js using the Windows file from nodejs.com - takes 5 minutes and no explicit expertise.
b. Install the hub (server) app that you choose and schedule it in windows (5 minutes, instructions available).
c. Start the hub software
d. From the Hub or any PC / MAC with a browser: load the single Service Manager (Smart App) and Device Handlers for your device into the SmartThings environment (including getting account, takes about 10-15 minutes).
e. From the SmartThings App (on your phone) run the Service Manager twice. First time installs the hub. Second time installs the devices. Takes a total of about 10 minutes or less.

install documentation is at: https://github.com/DaveGut/Beta-TP-Link-Devices-Connect/tree/master/Documentation

I just installed the bridge and was wondering if there is a way to increase the refresh time for an HS device? Right now it seems to refresh every 15 minutes.
I ask because I’d like to use CoRE to react to the switch without also having to have CoRE refresh the device as well.

Also, any thought to integrating your GitHub with the IDE?

Not sure which version you are using. Either way, after the metadata section of the Device Handler, the following code may be included. This is from the Beta “connect” version. For non-connect, you can add this,

def installed() {
   updated()
}
def updated() {
   unschedule()
   runEvery15Minutes(refresh)
   //  See RunEvery in Documentation for shorter periods.
   runIn(2, refresh)
}

(If you want to do this for the HS110, post me again. Other changes will be required to eliminate calculate usage on these refresh cycles.)

Then save and go to smartapp. Select the device, and open the settings page. Then select “Done”. This will activate the new frequency.

You can check this on the Recently tab or the Logging function within the environment.

Relative to gitHub integration. I am new to programming (at age 68) and am still learning. Integrating gitHub with SmartThings is on my list, but not yet.

Thanks Dave. I’m have one HS200 that was bought for me and I’m so glad I came across your post. Right now I’m using v3 of the non beta DH. I’ll probably swap it out for the the ‘connect’ version eventually.

You are welcome. I would not upgrade to the connect version unless you add more devices. Sort of “if it ain’t broke, don’t fix it” attitude. The connect is meant for new installations and is simpler to install. But it does not improve functionality.

Added device handlers for the LB110, LB120, and LB130 Bulbs with the Energy Monitor functions. See Server.

1 Like

Dave,

Does the hub PC need to be W10? I have a W8.1 tablet laying around that doesnt pull its weight around the house.

And I have to ask, I ended up on this thread because I was looking into the tinkering community for the LB130. I recently purchased one and was somewhat disappointed with the lack of neat tricks. This is my first foray into smart devices and IoT so Im wondering what sort of capabilities we can get with this setup

Thanks

  1. Windows 8.1 should work.

  2. The current implementation does only the following:
    a. On / Off
    b. Brightness
    c. Color Temperature
    d. Color ((using color wheel)
    e. Mode (Circadian or Normal)
    f. Energy Monitor version also does

  1. Current usage
  2. Usage today
  3. Monthly and Weekly Total and Average.

Other functions not coded:
a. Transition Period (gradual transition from one state to another (example: on to off).
b. Set and recall the three bulb preferred state.
c. Scheduling functions (I use smartthings).

I have considered adding the Transition Period function. It is possible, but will take up screen space or would be a text entry on the “settings” page. Would not be hard.

Dave

If I were to implement Transition Period, it would go as below:
a. A preference (on setting page) to define Maximum Transition Period with a default of 1 minute (no maximum)
b. A slider to define the Transition Period Percent to use as a percent of Maximum Transition Period. Once set, following commands would use this period: on, off, and Brightness.

Example. When you wake up, you want the light to gradually brighten to 100 percent over a 5 minute period. Steps:

  1. Set Maximum Transition Period to 5 minutes.
  2. Set bulb brightness to 100 percent then turn off.
  3. Set Transition Period Percent to 100
  4. Cause the bulb to turn on (either manually or as part of a SmartThings Automation Routine.

Dave,

Do you know if its possible to install this on an Amazon Fire Stick.

I already see other projects that runs Node.js on a fire stick, but don’t know if all needed for your code can be installed there.

Thanks for your help.

1 Like

I do not know. I know for Android it is possible, but difficult - and fire is an Android derivative. I will do further checking - but it will take a while.

Thanks Dave for your quick response.

I have a Fire Stick and some basic skills with android. ST is a new world for me, but if you want help on this, send me instructions and I can help testing at home.

I own a TP-LINK bulb LB120.

Carlos.

i will continue looking. So far, I have found an app that runs on Android and Fire Tablets (but is not in the Fire TV catalog). It seems to work; however, it uses an early version of node.js, so my script would require modification.

The app is Server Ultimate. PS - I want to see if there is a way to install this on Fire TV. According to Amazon, both OS’s are based on Android 5.1 (Lollipop) and API 22. Anyone have more information?

I am going to research other available servers for Fire Tablets and see if any of them run a compatible node.js version. If not, I may update the server applet to be backward compatible with 0.x node.js (early versions).

Had fun today. With minor changes, I can create a version of the script that will run using Server Ultimate. That means that if you can install and figure on how to always run Server Ultimate, then you can run my TP-Link Hub using Server Ultimate - and a special .js package (to be published in beta format tomorrow) on

ANDROID
FIRE TABLETS

Major issue: The difference are in the ‘new Buffer’ commands not being in the baseline. To get it to work, I had to replace buffer.alloc with new buffer. Therefore, separate js baselines.

Dave, based on amazon documentation, its fire TV is based on Android 5.0 API22.
“Device OS/Platform software Based on Android 5.0 - API 22”

Even the new Fire TV Edition is based on same version/API.

I’ll take a look on Server Ultimate.

Thanks for your help.

Check with Amazon tech support on installing fire tablet pad on fire TV. The folks at the apartment house may not have a clue.

Btw. The free version is good for a week. Then $8.95.

I have this running on a Raspberry Pi and working great. I need the script to run at boot. I’ve tried setting up a daemon but I must not be invoking the node.js script properly in the init.d script. I also tried a Cron job with no success. Anybody know how to set this up properly?

No knowledge on my part; however, the thread “New Raspberry Pi–What do I do next?” in Projects and Stories may have some useful guidance.

Does anyone have written (step-by-step) instructions for install of node.js scripts to run on Raspberry Pi at startup? They are there for a PC and I am working on android and Amazon Fire Tablets.

INSTALLING NODE.JS AND TP-LINK SCRIPTS ON ANDROID AND AMAZON FIRE OS

OK, I found a app that creates a node.js server on Android and/or Amazon Fire OS. Compatible with Android version 2.2.1 or later. Link:

http://www.icecoldapps.com/app/servers-ultimate/

The cost is $9 after the 14 day free (with advertising) trial. Easy to install.

  1. Download and install app.
  2. Copy node script (on GitHub site) ‘TP-LinkServer_oldNode.js’ into a directory on the server (I used Documents).
  3. Start Server Ultimate
  4. On main screen, select Node.js from the drop-down. (If node.js does not appear, you may need to find and install the server pack with node.js. free)
  5. Select START
  6. on the left, Select Servers, then +ADD (upper right). Select Node.js from drop-down.
  7. Provide a Server Name
  8. Select "Start on boot.
  9. Go to Specific Tab and set script location (using browse).
  10. Select SAVE (upper right)
  11. Select Settings (from left)
  12. Select “Start the app on boot” then SAVE.
  13. Go to Servers page and start the server.

Testing: Tested on Amazon Fire TABLET running latest Fire software.
Tested on Samsung Galaxy S3.
Open

  1. Can it be installed on Fire TV sticks
  2. Overall robustness.

The ‘TP-LinkServer_oldNode.js’ is a direct copy of the “TP-LinkServer_v3.js” with some switches set differently. Namely, error.log file is disabled and the ‘oldNode’ variable is set to yes. This allow the script to use the legacy “new Buffer” (depreciated on newer versions) vice the “Buffer.alloc” which does not exist on the older versions (and is preferred).

UPDATED on 7-13-2017
07-13-2017 Updates
a. New Java Script file to reduce error. Tested and compatible with existing device handlers. Also updated to detect node.js version ‘6.0.0-pre’ and adjust program to run compatible buffer command.
b. Updated Energy Monitor Device Handlers to accommodate new Java Script (existing Device Handlers should work on - potential error on energy monitor near end of month (TP-Link sends stat in two packets vice one)
c. Updated formatting of other Device Handlers to common standard for mx purposes.

Recommendation for existing users : IF IT AIN’T BROKE, DON’T FIX IT.