SmartThings Community

[Release] New TP-Link/Kasa Plug, Switch, and Bulb Integration

dth_lighting
dth_pocketsocket
(Dave Gutheinz) #103
  1. Classic App?
  2. Did you install in accordance with standard IDE procedures:
    a. Select you hub in My Locations first.
    b. copy and save the code from the GitHub link I provided to a “add” window?
    c. Publish
  3. Open Classic App, go to apps, Select Add. At bottom is list of “My Aps”
0 Likes

(kelvin) #104

Also got the same Token expired message on first login (even confirmed using the right kasa account and password by logging out of Kasa app and re-logged in.)

You have the change your Kasa password in Kasa app, then immediately go into to TP-Link Smarttings manager smartapp and enter with new password. Now I got around the token expired error and it found my three 3-way switches!

Thank you Dave and Anthony, awesome work!

0 Likes

(Michael) #105

Hello David,

First and foremost, excellent work on this TP Link integration with SmartThings. You’ve inspired me to learn some coding. However, I’ve run into an issue with the LB120 Tunable Bulbs and a hub/bridge running on a Raspberry Pi 3+. Whenever there is communication between the two, I receive the following error on the Nodejs shell:


deviceCommand sending to IP: 10.xx.xx.xx Command: {“system”:{“get_sysinfo”:{}}}
Command Response sent to Smart Hub
_http_outgoing.js:482
throw new ERR_HTTP_HEADERS_SENT(‘set’);
^

Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
at ServerResponse.setHeader (_http_outgoing.js:482:11)
at Socket.socket.on (/home/pi/Node Scripts/TP-LinkHub_v3.js:145:12)
at Socket.emit (events.js:188:13)
at addChunk (_stream_readable.js:288:12)
at readableAddChunk (_stream_readable.js:269:11)
at Socket.Readable.push (_stream_readable.js:224:10)
at TCP.onStreamRead [as onread] (internal/stream_base_commons.js:145:17)

I also receive the following error via the SmartThings IDE page and Live Logging:


[omitted] 12:37:38 AM: error groovy.json.JsonException: expecting current character to be ‘"’ with an int va…[TRUNCATED]

[omitted] 12:37:38 AM: error groovy.json.JsonException: expecting current character to be ‘"’ with an int va…[TRUNCATED]

These errors result in the service/process crashing, forcing me to restart the service/process. All other TP link devices work fine - LB100, HS100, and HS105. I must also mention that when I had been previously using the cloud and Smart Manager, all devices (including the LB120’s) worked fine.

If you need any additional information, please let me know.

Thanks for the assistance.

0 Likes

(Dave Gutheinz) #106

I just updated the node.js file to isolate the error causing the crash. The ST Log message was due to a bulb return message being broken into two messages. I am not able to correct that. It is usually caused when the bulb is being hammered with commands and responses too rapidly. Hopefully, day-to-day will work ok (It has in the past for almost everyone).

What is your bulb’s firmware version? Hardware version? (from the Kasa App).

0 Likes

(Michael) #107

The bulbs (LB120) hardware version is 1.0, and the firmware version is 1.8.6.

Thanks for getting back and issuing a resolve so quickly. I’ll test it out after work today and get back to you.

Again, appreciate your dedication and hard work.

0 Likes

(Dave Gutheinz) #108

Same hw and firmware version here.

0 Likes

(Michael) #109

Your revision definitely helped prevent the nodejs process from crashing due to those errors; which was the most detrimental issue as it affected other devices. From time to time, I’m still receiving errors which results in delayed status updates/refreshes within the SmartThings app for the LB120’s. However, as this issue doesn’t appear to be affecting other users, I’m going to migrate nodejs to a different environment (virtual machine, instead of the Raspberry Pi 3+), to eliminate potential issues with its current operating environment and/or hardware resource limitations. I’ve also noticed some TCP timeouts in a few of the errors as well, which further pushes me toward trying a different environment, including terminating to other network devices.

Again, thanks for the assistance and hardwork.

0 Likes

(Michael) #110

FYI…which I keep forgetting to mention, the “TP-Link TunableWhite Bulb.groovy” file on Github still references/returns the “Soft White Bulb” as the Device Type Identifier, instead of the “Tunable White Bulb.”

Not sure if that’s what is intended or not? On my local copy, I adjusted the comments accordingly.

1 Like

(Dave Gutheinz) #111

thanks, fixed.

0 Likes

(Dave Gutheinz) #113

New Bulb DH Version 3.6.02. Updated to partially address problem on Node Applet installation.

Error: a groovy.json.JsonException was being received in refreshResponse.

Cause: the return message from the device was being fragmented due to (1) length, and (2) something in the TP-Link code doing this when the device is very busy. Caused by sending an on->off or off->on command to the device followed immediately by the refresh command. Occurred when the message exceeded a certain number of characters. This was keyed when the bulbs name (set by Kasa App) exceeds 18 characters.

Program Fix: Fixed in code for bulbs by removing automatic ‘refresh’ after a command is sent. Use the command return instead to update the state.

Known Residual Issue: (1) If your bulb name is over 18 characters and you (or an automation) send the on->off of off->on command followed immediately by a refresh command, the error will occur. (2) Did not fix the node.js implementation yet.

Work-Around 1: Do not send the on->off of off->on command followed immediately by a refresh command. It is unnecessary.

Work-Around 2: change the name to less than 18 characters.

0 Likes

(The H Gamer) #114

should i have the hub to do that i try to do it without the hub but when i go to my apps there is nothing there i have tp link switch and i whant to use it in smart thing because i want when i turn on the switch it trigger ifttt …

0 Likes

(Dave Gutheinz) #115

You must own a hub.

0 Likes

(The H Gamer) #116

i have the echo plus 2 can i used it as a hub

0 Likes

(Dave Gutheinz) #117

You must own a SmartThings hub for any of my applications and drivers to work.

0 Likes

(Rlyons20) #118

Considering buying these as a cheaper alternative to Philips Hue. Is this method of control working? I’m very comfortable with custom DH and logging in to another API via the app. I just want to know if people are generally able to get this working well.

Thanks!

0 Likes

(Dave Gutheinz) #119

It works fine for me. But as the author… check with others.

0 Likes

(Michael) #120

I can attest with Dave, my 8+ TP Link devices have been working and meeting expectations. I ran into a snag with the LB120’s and “Node js” at the beginning (see above), but Dave quickly resolved those issues. I’ve never been a Hue user, so I can’t really offer a comparative between the two, especially since one uses the Zigbee protocol (Hue) and the TP Links are straight up IP based.

1 Like

(Dave Gutheinz) #121

App update. Updated app today to add two upcoming multi-plugs in the TP-Link Kasa lineup:

KP200 - wall outlet with two independently controllable outlets.

KP400 - outside plug with two independently controllable outlets.

Both are added (on faith) as multi-plugs using the same DH as the HS107 and HS300 devices.

0 Likes

(Daniel Siegel) #122

Dave - I just began looking at your Kasa integration and have to admit I’m a little lost.
I am still somewhat of a SmartThings beginner. I have copied/pasted some GitHub code to create some custom handlers, but have not done so to create a SmartApp before. So, I have some basic questions which I cannot easily answer from the links/instructions on this thread and your GitHub page.

I have a Kasa account with a number of devices (currently about a dozen HS-105 Mini Smart Plugs).
I have the SmartThings Hub and the IDE account which enables me to create custom Device Handlers, Smart Apps, etc.

I’m not sure if I have GitHub integration, as I have only gone to others’ GitHub pages and copied/pasted code (eg, to create a custom Device Handler). Not sure if this integration is necessary for your Smart App, but I guess that is one question.

I’m mostly stuck not knowing where to begin. From what I can discern, I would prefer the 1st of the 3 integration choices – cloud integration via my Kasa account, using your SmartApp.
But I dont know how to create your Smart App. Do I just copy/paste some code from your GitHub account, or is it more involved?

Appreciate any help you can provide.
Thanks
Dan

0 Likes

(Dave Gutheinz) #123

The gitHub repository is:

From the first page:

Installation (Must use the SmartThings Classic App)

Installation instruction can be found in the Documentation Folders. These are step-by-step and are for users new to SmartThings. However, they have not been modified from the previous version yet.

a. Install the relevant installation file(s):

Note:  If you have enabled GitHub integration in SmartThings, the repository settings are:
        Owner: davegut
        Name: SmartThingsPublic
        Branch: master

1.  Go to the MyDeviceHandler page on the IDE, select 'Create New Device Handler'  Select 'From Code'.

2.  Copy the contents of the relevant file in the 'Device Handler' folder herein.  Paste into the IDE page.

3.  Select "Create".  Select 'Publish' 'For Me'.

4.  For 'Kasa Account' or 'Node Applet' installations, go to the My SmartAps page on the IDE.  Select 'New SmartApp'.  Select 'From Code'.

5.  Copy the contents of 'TP-Link SmartThings Manager.groovy' in the 'Service Manager' folder herein.  Paste into the IDE page.

6.  Seleect 'Create'.  Select 'Publish' 'For Me'

7.  For Node Applet installations, copy the new 'TP-LinkHub_v3.js' and (for PC) 'TP-LinkHub_v3.bat' files and install on your hub.

b. Installation of ‘Kasa Account’ or ‘Node Applet’ integrations.

1.  From the SmartThings Classic phone app, select 'SmartApps', then 'Add a SmartApp'.  Select 'My Apps' at bottom of next page.  Select 'TP-Link SmartThings Manager' from the 'My Apps' page.

2.  'Select Installation Type'.  Tap for the selection of 'Kasa Account' or 'Node Applet'.  Once you select, the program will land on one of two pages

3.  'Kasa Account'.  Enter your Username and Password.  Once both are entered (right or wrong), you will be directet to select in "Install a Device to Continue.  That will take you to the 'Device Installation Page.  Follow prompts to install the devices.

4.  'Node Applet'. Assure the Node.js Applet is running.  Enter the device IP (example:  192.168.1.199) for your bridge.  You will see an error until the system has time to actually detect devices.  Then follow prompts to add devices.

c. Installation of Manual Node Installation

  1. Start the Node.js Applet. Go to the IDE, "My Devices’. Select ‘New Device’.
  2. Fill-out the form fields ‘Name’, ‘Label’, ‘Device Network ID’.
  3. From the pull-down ‘Type’, select the appropriate device type (handler). Select ‘Location’ (your hub).
  4. In 'My devices or on the phone (Classic App) for each device, select preferences. Enter the Bridge IP, and Device IP and save.
  5. You can now use either phone app to control the device. Prefernces can only be updated on the IDE or the classic app.
0 Likes