[RELEASE] TP-Link Plug, Switch, and Bulb integration


#123

I see, thanks for the explanation. By the way, the UDP driver is working with my HE with HS100, thanks!


#124

So I actually did look at this. As @djgutheinz mentioned to port the api elements into the driver is not trivial. Well beyond anything i would be able to do.

Though I do think it is possible.


#125

Hi, thank you for answering

You @djgutheinz and @cwwilson08 should team up!

Happy New Year!


#126

I would not mind. However I think @djgutheinz has better things to do than spoon feed me information. The project was out of my league to begin with. It is a small miracle I got it working for me. I was really hoping I wold spur the interest of people with more skills than myself.


#127

Dave - this is working brilliantly! Love it!

So two questions:

  1. Do we need the TP-Link HE app anymore?
  2. What is recommended refresh time from your initial experience?

#128
  1. App is not necessary if you have set up "static" IPs for the devices through your router.
  2. The default 10 minute is great for normal operations. Faster would be desirable if you have (a) a rule machine that reacts to changes and (b) a lot of activity that does not go through Environment. These activities include google and amazon linked to the Kasa app instead of Hubitat integration, direct use of the Kasa App to change state.

The old smart app has code that will delete the child devices if you delete the smart app (do not delete). A new smart app will come out today or tomorrow (in final testing) with update instructions. It can be deleted after update w/o deleting child devices.


#129

Version 4.0 (UDP Version) Update Announcement

The full Version 4.0 UDP version with drivers and application have been completed. Installation files and Install/Update instructions can be found at:


#130

@djgutheinz

Dave - I am absolutely AMAZED! So not only did you improve local execution using UDP but you also made to installation/upgrade SO easy. I didn't have to input IP addresses or anything. This is truly a work of art. Kudos to you for this incredible integration!


#131

It was actually fun. I really enjoy trying new things (UDP) and actually getting them to work.


#132

Hi @djgutheinz

I have been wanting to integrate my TP-Link plugs for a long time now but never got the time to setup the pi with node.js for it, this is awesome!!

That said, I'm unable to discover my devices (5x HS105). Looking at the code I realized that the discovery checks for every IP on the same subnet as the Hub and I have the plugs in a separate subnet for non-trusted IoT devices, so I hardcoded the networkPrefix to my IoT subnet but still, nothing gets discovered...

Do you know if these devices have some kind of restriction where they only accept UDP connections or commands from the same subnet or something like that?


#133

The bulbs have no restrictions.
a. Try a manual installation for one device and see if it works.

b. Separate segment for untrusted devices. Not even sure if Hubitat supports separate subnets for devices??? I do know (in my router) you have to set up the router to allow cross access.

c. For the HS-105, if you move them to your trusted segment and then place them in Local only mode through the Kasa App, then they will no longer be accessible to the Kasa App. (Note, if you use Amazon, you can use the Hubitat integration to control.)

d Debug code. In the App and Driver are the following two lines:

def debugLog() { return false }

// def debugLog() { return true }

Reverse these to get full debugging.


#134

Ahh! I found the problem, when the device is not in the local subnet, resp.mac will be null, and this is your first check in the response when discovering the device and then you use it for the device DNI.

I think maybe checking for IP is null instead and then getting the MAC from cmdResp.mac for the DNI would solve this, plus it is in human readable format instead of hex (easier to match a device from the devices page)... do you know if you can use ":" in a DNI? maybe replace them with "-"...

I'll give this a try and send you my changes if I can make it all work...

BTW, thanks for those tips!


#135

I updated the code as follows:

a. Stop polling at device 254, avoiding a duplicate response from the global address.

b. Do not use the udp returned mac for a filter if null.

c. Parse the get_sysinfo return mac or mic_mac field (different based on device type) to generate the dni in format of MAC less colons.

I did no change the polling range. Could not figure out a way to do that w/o user interface. Would require a significant design change. You will have to hard-code that area.

Dave


#136

This is Awesome Dave! got home from work ready try my coding skills but you were faster! :grinning:

Discovery worked with the new code and I was able to add the devices and they work perfectly!

I don't have any problem with hardcoding my subnet. Thanks so much for this integration!


#137

@djgutheinz

Errors in logs:


#138

Tried each of my bulbs, no problem (bulbs are where line 274 is in refreshResponse). Exactly what bulb was it? Is it repeatable?

FYI - the code is JSON parsing the return from decrypt. It indicates a truncated string was received (therefore only 12 characters long). Looks like a spurious comms glitch - but....

Turn on 'traceLog' (line 30-31 of the driver) and capture one cycle. If it continues, I will have to create a test driver with even more data.

Dave


#139

These are the 230 color bulbs. Will turn on trace logging and get back to you. And this happens on both 230 and 130 bulbs.


#140

After line 270, insert the below code. It will tell me what the "raw" data return is.

log.error parseLanMessage(response)

Also, what version are you using? (line 33 of driver)

I have run 100 cycles w/o an error. Still confused.


#141

Version: 4.0.01

Added the log.error info...information below

[dev:271](http://10.0.2.38/logs/past#dev271)2019-01-03 08:53:29.191 pm [info](http://10.0.2.38/device/edit/271)Living Room - Couch: Power: on / Brightness: 100% / Circadian State: normal / Color Temp: 4000K / Color: [hue:0, saturation:0]

[dev:271](http://10.0.2.38/logs/past#dev271)2019-01-03 08:53:29.189 pm [info](http://10.0.2.38/device/edit/271)Living Room - Couch Color Mode is CT. Color is Moonlight.

[dev:271](http://10.0.2.38/logs/past#dev271)2019-01-03 08:53:29.099 pm [error](http://10.0.2.38/device/edit/271)[index:00, mac:50C7BFA0EC9F, ip:0a000297, port:270f, type:LAN_TYPE_UDPCLIENT, payload:D0F281F88BFF9AF7D5EF94B6D1B4C09FEC95E68FE187E8CAF08BA9DAADF284E193B18BA998B68EA096B6F481E884E0C0F1C9F9C1F1C8E8BADFB39DAD94A593A69FBD91B3DBACF385E092B08AA899B787A589ABC6A9CDA8C4E6DCFEB2F0C1F2C2EABFECC5E7CBE98DE89BF88AE393E78EE18FAD97B5E68BEA98ECCC9BF2DF99F0D09CD99DBDFF8AE684A4D3BACEA686C5AAC6A9DBFBB8D0B1DFB8D1BFD8FAD6F495F990F182A09AB8F49DEB82EC8BABF996F994B499B9FA95E083EBC9E5C7AAC3A0FF8BF282E7C5FFDD94DB8FA1F2BFFEACF8BAEFA3E1C3EFCDA9CCBAE596E283F792B08AA8C6A9DBB6D7BB99B597FA93F0AFC2A3C0E2D8FACFFFBC8BC98FCEFEBBF8C187A589ABCFAADCB5D6B3FA9EBC86A49CAC9DAF9CD8EFAE9EDAECDFE6A4E5D190D5EDDC9EDCE9D0E6D1E3A696D795AD9CA49DA49DD99FDDFFD3F19EFB96DFBB99A381B184C680B7F5C684C1F0C6F1C487B2F3C5FDCBFCBE89C8FFBA8ECDF4B284C2F5D7FBD9B1C68FEBC9F3D1E0D1E0A596A39AAA92A69FA8E9D9ECD9E8DA9FAD98A1E3A196A098A899DCEDDDFFD3F198EBB4D2B3D0A4CBB9C0E2D8BEDFB3C0A589ABCFA6D5B6D986F095E7C5FFDDECC2F2D0FCDEBDC9BBD788F88AE591FE9DF29EEDCFF58EACC2A3CEAB89B391DDB4DAB1D8BD9FB391E782F083EA85EBC9F3D1E0CEFEDCA18DAFC3AACDA5D18EFD89E89CF9DBE19AB8D7B9E689EF89AB91A08CAEC3ACC8AD8FB597F996E489E884A68AA8C0B5D0F2C8F8D4F685E490E597F682EB84EAC8F2C2EECCAFC0ACC3B1EE9AFF92E2C0FACEFECEFED2F092E089EE86F29CF98AF9DBE1D0E0D0AD81A3CAB9E682EB86EB8AE884E1C3F9C8E4C6AFDC83E08FE38CFEDCE6D7FBD9B0C39CEA8BF990F193FF9AC5A6C9A5CAB8E793F69BEBC9F3C2EECCBCCEABCDA8DAA8CDA9F685F190E481A399C2B99BF29CF89DE5C7FDCDE1C3ABDEBB99A393BF9DEE8FFB8EFC9DE980EF81A399A985A7C4ABC7A8DA85F194F989AB91A394A494B89AF88AE384EC98F693E093B18BBE8EF3DFA486EF81E580F8DAE0D1FDDFB7C2A785BF8FA381F293E792E081F59CF39DBF85B287AB89EA85E986F4ABDFBAD7A785BF8FA381E391F89FF783ED88FB88AA90A191A1DCF08BA9C0AECAAFD7F5CFFDD1F39BEE8BA993A290A08CAEDDBCC8BDCFAEDAB3DCB290AA9DA884A6C5AAC6A9DB84F095F888AA90A08CAECCBED7B0D8ACC2A7D4A785BF8EBE8EF3DFA486EF81E580F8DAE0D3FFDDB5C0A587BD8FBB8BA785F697E396E485F198F799BB81B683AF8DEE81ED82F0AFDBBED3A381BB8BA785E795FC9BF387E98CFF8CAE94A595A5D885A98BF98AF990B288A591A884A6C7A4D0B9CFAAF598F793F6D4EECCA2CDA3C6E4C8EA82E786F685EC96F3D1EBD9E0D1E6D6E6CAE88DFF8DD2B1DEBADFFDC7F78AF78A]

[dev:271](http://10.0.2.38/logs/past#dev271)2019-01-03 08:52:29.081 pm [info](http://10.0.2.38/device/edit/271)Living Room - Couch: Power: on / Brightness: 100% / Circadian State: normal / Color Temp: 4000K / Color: [hue:0, saturation:0]

[dev:271](http://10.0.2.38/logs/past#dev271)2019-01-03 08:52:29.081 pm [info](http://10.0.2.38/device/edit/271)Living Room - Couch Color Mode is CT. Color is Moonlight.

[dev:271](http://10.0.2.38/logs/past#dev271)2019-01-03 08:51:29.069 pm [info](http://10.0.2.38/device/edit/271)Living Room - Couch: Power: on / Brightness: 100% / Circadian State: normal / Color Temp: 4000K / Color: [hue:0, saturation:0]

[dev:271](http://10.0.2.38/logs/past#dev271)2019-01-03 08:51:29.068 pm [info](http://10.0.2.38/device/edit/271)Living Room - Couch Color Mode is CT. Color is Moonlight.

[dev:271](http://10.0.2.38/logs/past#dev271)2019-01-03 08:51:20.634 pm [info](http://10.0.2.38/device/edit/271)Living Room - Couch: Power: on / Brightness: 100% / Circadian State: normal / Color Temp: 4000K / Color: [hue:0, saturation:0]

[dev:271](http://10.0.2.38/logs/past#dev271)2019-01-03 08:51:20.633 pm [info](http://10.0.2.38/device/edit/271)Living Room - Couch Color Mode is CT. Color is Moonlight.

[dev:271](http://10.0.2.38/logs/past#dev271)2019-01-03 08:51:20.516 pm [info](http://10.0.2.38/device/edit/271)Living Room - Couch: Power: on / Brightness: 100% / Circadian State: normal / Color Temp: 4000K / Color: [hue:0, saturation:0]

[dev:271](http://10.0.2.38/logs/past#dev271)2019-01-03 08:51:20.515 pm [info](http://10.0.2.38/device/edit/271)Living Room - Couch Color Mode is CT. Color is Moonlight.

#142

No errors. I will look at later. Have potential work-arounds. Tell me if it happens again and try to get data when it happens.

What I believe is happening: The return from the bulb is being split by the bulb into two messages. I have seen this in the Node.js for energy monitor responses - but only on extremely long energy stat messages and when the bulb was very busy (i.e., just received an set color command).