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


#143

I am using Scenes to call (1) lighting efffect for all the bulbs in the room. Let me try controlling independently to see if there are errors.

[UPDATE] same issues controlling independently too.

Logs:

[dev:273](http://10.0.2.38/logs#dev273)2019-01-04 10:07:58.363 am [info](http://10.0.2.38/device/edit/273)Fireplace - Right: Power: off

[dev:273](http://10.0.2.38/logs#dev273)2019-01-04 10:07:58.318 am [error](http://10.0.2.38/device/edit/273)[index:00, mac:50C7BFDB0816, ip:0a000284, port:270f, type:LAN_TYPE_UDPCLIENT, payload:D0F281F88BFF9AF7D5EF94B6D1B4C09FEC95E68FE187E8CAF08BA9DAADF284E193B18BA998B68EA096B6F481E884E0C0F1C9F9C1F1C8E8BADFB39DAD94A593A69FBD91B3DBACF385E092B08AA899B787A589ABC6A9CDA8C4E6DCFEB2F0C2F1C1E9AC9EA881A38FADC9ACDFBCCEA7D7A3CAA5CBE9D3F1A2CFAEDCA888DFB69BDDB494D89DD9F9BBCEA2C0E097FE8AE2C281EE82ED9FBFFC94F59BFC95FB9CBE92B0D1BDD4B5C6E4DEFCBAD3A1C4B4D8B9DABF9FB292C0A9CEA6D2F0DCFE93FA99C6B2CBBBDEFCC6E4ADE2B698CB86C795C183D69AD8FAD6F490F583DCAFDBBACEAB89B391FF90E28FEE82A08CAEC3AAC996FB9AF9DBE1C3F6C685B2F0B6F2B080B889BF9DB193F792E48DEE8BC2A684BE9CA494A597D591D491D5E6D5E5D6EEDD99A899A192A7E3A6E4DCEBAEEDA9EAD2EADBE3A092A6E5D795B79BB9D6B3DE97F3D1EBC9FAC387C1F3B580C1F9BCFDB9FCB88ACBF8C1F1B4F1C584B581C5F4C6F7C7F0B290BC9EF681C8AC8EB496A796A7E2D1E4DDEDD5E1D8EFAE9EAB9EAF9DD8EADFE6A4E6D1E7DFEFDE9BAA9AB894B6DFACF395F497E38CFE87A59FF998F487E2CEEC88E192F19EC1B7D2A082B89AAB85B597BB99FA8EFC90CFBFCDA2D6B9DAB5D9AA88B2C9EB85E489ECCEF4D69AF39DF69FFAD8F4D6A0C5B7C4ADC2AC8EB496A789B99BE6CAE884ED8AE296C9BACEAFDBBE9CA6DDFF90FEA1CEA8CEECD6E6CAE88CEA9EC1AEC09FEC98F98DE8CAF08BA9C4ABCFAA88B290FE91E38EEF83A18DAFC7B2D7F5CFFFD3F182E397E290F185EC83EDCFF5C5E9CBA8C7ABC4B6E99DF895E5C7FDC9F9C9F9D5F795E78EE981F59BFE8DFEDCE6D7E598E5C9EB82F1AECAA3CEA3C2A0CCA98BB180AC8EE794CBA8C7ABC4B694AE9FB391F88BD4A2C3B1D8B9DBB7D28DEE81ED82F0AFDBBED3A381BB8AA684F486E385E092E085E1BECDB9D8ACC9EBD18AF1D3BAD4B0D5AD8FB585A98BE396F3D1EBDBF7D5A6C7B3C6B4D5A1C8A7C9EBD1E1CDEF8CE38FE092CDB9DCB1C1E3D9EBDCECDCF0D2B0C2ABCCA4D0BEDBA8DBF9C3F6C6BB97ECCEA7C9ADC8B092A899B597FF8AEFCDF7C7EBC9BADBAFDAA8C9BDD4BBD5F7CDFACFE3C1A2CDA1CEBCE397F29FEFCDF7C7EBC9ABD9B0D7BFCBA5C0B3C0E2D8E9D9E994B8C3E188E682E79FBD87B599BBD3A6C3E1DBEAD8E8C4E695F480F587E692FB94FAD8E2D5E0CCEE8DE28EE193CCB8DDB0C0E2D8E8C4E684F69FF890E48AEF9CEFCDF7C6F6C6BB97ECCEA7C9ADC8B092A89BB795FD88EDCFF5C7F3C3EFCDBEDFABDEACCDB9D0BFD1F3C9FECBE7C5A6C9A5CAB8E793F69BEBC9F3C3EFCDAFDDB4D3BBCFA1C4B7C4E6DCEDDDED90CDE1C3B1C2B1D8FAC0EDD9E1CDEF8EED99F086E3BCD1BEDABF9DA785EB84EA8FAD81A3CBAECFBFCCA5DFBA98A290A999AC9EA68AA8CDBFCD92F19EFA9FBD87B7CAB7CA]

[dev:273](http://10.0.2.38/logs#dev273)2019-01-04 10:07:56.125 am [info](http://10.0.2.38/device/edit/273)Fireplace - Right: Power: on / Brightness: 12% / Circadian State: normal / Color Temp: 4000K / Color: [hue:0, saturation:0]

[dev:273](http://10.0.2.38/logs#dev273)2019-01-04 10:07:56.121 am [info](http://10.0.2.38/device/edit/273)Fireplace - Right Color Mode is CT. Color is Moonlight.

#144

The error in the message was my logging (to highlight within the great amount of logging). That was expected. It is the "raw" data that is received from the device. I was looking for another groovy.json.jsonexception with this data to confirm the truncation on receipt from the bulb.

I WILL rework the parsing of bulb responses - going back to an older method with more logic, but less messages. I was thinking about doing this anyway.

Dave


#146

New errors in TP130 colored bulbs:

dev:2712019-01-05 08:58:29.110 am errorgroovy.json.JsonException: Expected a closing curly brace '}' or a comma ',' on line: 1, column: 12. But got an unterminated object. on line 312 (refreshResponse)


#148

@djgutheinz

Just so you know even though there are errors in the logs everything works really well. Significantly reduced popcorn effect, almost instant on/off, etc. I am just helping out with errors I am seeing with the LB130 bulbs. The 230's have no errors.


#149

I really need to know what is going on when you get the error. Essentially, I must have the decrypted raw return from the bulb when the error occurs.

Instructions:

a. Insert the code below after line 298 in the new device handler

 log.debug "commandResponse:  ${response}"

b. Insert the code below after line 309 in the new device handler.

 log.debug "refreshResponse:  ${response}"

b. Insert the code below after line 402 in the new device handler.

      log.debug cmdResponse

c. Assure that the DH's traceLog is false (that is default).

d. Open hubitat logging until you get the error. (keep traceLog false).

e. paste the error message (groovy.jsonJsonException) and the preceding message.

This should give me a view of the received data. If I can find this out, I can possibly fix it. Otherwise, I will mask out the error.

I noted that you are doing a lot of refresh commands. How often? Use case?

REFRESH. Note that for these bulbs, refresh is only useful in four cases:

a. Someone manually turns off the bulb (at plug, switch, or unscrew). Refresh will detect this and create an error saying the bulb is not connected at the next scheduled refresh.

b. Someone uses the Kasa App to change the bulb state. Refresh will update on the next cycle.

c. The bulb is turned on using google assistant or Amazon Alexa with the device using the Kasa Skill (amazon) or equivalent. Again updated on next refresh cycle. However, if you use the Hubitat Alexa Skill (or google if it exists), you should disable the Kasa Skill and use the Hubitat Skill. Then the state updates immediately since it is updated by HE.

d. (Very rare.) There is a glitch in the return message (spurious). Then next refresh cycle will update unless comms are in a very big problem.

Sorry for the verbose discourse. I see a lot of over-use of refresh. It stresses the bulbs (more processing) and could stress the HE.

Dave


#150

Great feedback! I have it set to 1 minute refreshes. I don’t use any of the scenarios listed below and the bulbs are 99% controlled by HE; last 1% is using Kasa when a horrific issue happens with HE. Suggestions on refresh time with this in mind? Maybe I am over taxing everything.


#151

Every minute should be OK unless you have a lot of Hubitat devices and should not stress the TP-Link devices.

I am modifying code today to "handle" your error as best as possible. The modification will include a 30 minute refresh option (which is what I prefer).


#152

Here is the logs from the modified code:

dev:2712019-01-05 11:02:29.156 am errorgroovy.json.JsonException: Expected a closing curly brace '}' or a comma ',' on line: 1, column: 12. But got an unterminated object. on line 314 (refreshResponse)

dev:2712019-01-05 11:02:29.146 am debug{"system":{"get_sysinfo":{"sw_ver":"1.8.6 Build 180809 Rel.091659","hw_ver":"1.0","model":"LB130(US)","description":"Smart Wi-Fi LED Bulb with Color Changing","alias":"Living Room - Couch","mic_type":"IOT.SMARTBULB","dev_state":"normal","mic_mac":"50C7BFA0EC9F","deviceId":"80123D7A0D639BA4AE81BB59672E0AB818999DFB","oemId":"05BF7B3BE1675C5A6867B7A7E4C9F6F7","hwId":"111E35908497A05512E259BB76801E10","is_factory":false,"disco_ver":"1.0","ctrl_protocols":{"name":"Linkie","version":"1.0"},"light_state":{"on_off":0,"dft_on_state":{"mode":"normal","hue":0,"saturation":0,"color_temp":4000,"brightness":100}},"is_dimmable":1,"is_color":1,"is_variable_color_temp":1,"preferred_state":[{"index":0,"hue":0,"saturation":0,"color_temp":2700,"brightness":50},{"index":1,"hue":0,"saturation":75,"color_temp":0,"brightness":100},{"index":2,"hue":120,"saturation":75,"color_temp":0,"brightness":100},{"index":3,"hue":240,"saturation":75,"color_temp":0,"brightness":100}],"rssi":-41,"active_mode":"none","heapsize":290824,"err_code":0}}

dev:2712019-01-05 11:02:29.116 am debugrefreshResponse: index:00, mac:50C7BFA0EC9F, ip:0a000297, port:270f, type:LAN_TYPE_UDPCLIENT, payload:D0F281F88BFF9AF7D5EF94B6D1B4C09FEC95E68FE187E8CAF08BA9DAADF284E193B18BA998B68EA096B6F481E884E0C0F1C9F9C1F1C8E8BADFB39DAD94A593A69FBD91B3DBACF385E092B08AA899B787A589ABC6A9CDA8C4E6DCFEB2F0C1F2C2EABFECC5E7CBE98DE89BF88AE393E78EE18FAD97B5E68BEA98ECCC9BF2DF99F0D09CD99DBDFF8AE684A4D3BACEA686C5AAC6A9DBFBB8D0B1DFB8D1BFD8FAD6F495F990F182A09AB8F49DEB82EC8BABF996F994B499B9FA95E083EBC9E5C7AAC3A0FF8BF282E7C5FFDD94DB8FA1F2BFFEACF8BAEFA3E1C3EFCDA9CCBAE596E283F792B08AA8C6A9DBB6D7BB99B597FA93F0AFC2A3C0E2D8FACFFFBC8BC98FCEFEBBF8C187A589ABCFAADCB5D6B3FA9EBC86A49CAC9DAF9CD8EFAE9EDAECDFE6A4E5D190D5EDDC9EDCE9D0E6D1E3A696D795AD9CA49DA49DD99FDDFFD3F19EFB96DFBB99A381B184C680B7F5C684C1F0C6F1C487B2F3C5FDCBFCBE89C8FFBA8ECDF4B284C2F5D7FBD9B1C68FEBC9F3D1E0D1E0A596A39AAA92A69FA8E9D9ECD9E8DA9FAD98A1E3A196A098A899DCEDDDFFD3F198EBB4D2B3D0A4CBB9C0E2D8BEDFB3C0A589ABCFA6D5B6D986F095E7C5FFDDECC2F2D0FCDEBDC9BBD788F88AE591FE9DF29EEDCFF58EACC2A3CEAB89B391DDB4DAB1D8BD9FB391E782F083EA85EBC9F3D1E0CEFEDCA18DAFC3AACDA5D18EFD89E89CF9DBE19AB8D7B9E689EF89AB91A18DAFCBADD986E987D8ABDFBECAAF8DB7CCEE83EC88EDCFF5D7B9D6A4C9A8C4E6CAE880F590B288B894B6C5A4D0A5D7B6C2ABC4AA88B282AE8CEF80EC83F1AEDABFD2A280BA8EBE8EBE92B0D2A0C9AEC6B2DCB9CAB99BA190A090ED90BC9EF784DBBFD6BBD6B7D5B9DCFEC4F5D9FB92E1BEDDB2DEB1C3E1DBEAC6E48DFEA1D7B6C4ADCCAEC2A7F89BF498F785DAAECBA6D6F4CEFFD3F181F396F095E795F094CBB8CCADD9BC9EA4FF84A6CFA1C5A0D8FAC0F0DCFE96E386A49EAE82A0D3B2C6B3C1A0D4BDD2BC9EA494B89AF996FA95E7B8CCA9C4B496AC9EA999A985A7C5B7DEB9D1A5CBAEDDAE8CB683B3CEE299BBD2BCD8BDC5E7DDECC0E28AFF9AB882B29EBCCFAEDAAFDDBCC8A1CEA082B88FBA96B4D7B8D4BBC996E287EA9AB882B29EBCDEACC5A2CABED0B5C6B597AD9CAC9CE1CDB694FD93F792EAC8F2C0ECCEA6D3B694AE9FAD9DB193E081F580F293E78EE18FAD97A095B99BF897FB94E6B9CDA8C5B597AD9DB193F183EA8DE591FF9AE99AB882B383B3CEE299BBD2BCD8BDC5E7DDEEC2E088FD98BA80B286B69AB8CBAADEABD9B8CCA5CAA486BC8BBE92B0D3BCD0BFCD92E683EE9EBC86B69AB8DAA8C1A6CEBAD4B1C2B193A998A898E5B894B6C4B7C4AD8FB598AC9DB193F291E58CFA9FC0ADC2A6C3E1DBF997F896F3D1FDDFB7D2B3C3B0D9A3C6E4DEECD5E5DDEFDBF7D5B0C2B0EF8CE387E2C0FACAB7CA


#153

Driver 4.0.03 update. All drivers for TP-Link devices have been updated to handle the error described by @aaron (summarized at bottom). The update includes:

a. Change Bulb Command Response processing to eliminate unnecessary 'refresh' command.
b. Added a 'Preference' for traceLog (default to false) to allow enhanced logging for problem resolution.
c. Added error processing to capture the error being corrected and suggest the fix.
d. Added 30 minutes as a 'refresh' option. (Note, unless you have some other use case, 30 minute refresh is recommended.)

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: 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.

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.


#154

Finally able to replicate. See Driver 4.0.03 update.


#155

I set all my devices to 30 minute refresh except one plug device that controls more automation sequences than it probably should. That is set to 5 minutes.

I now have this error with the TP-Link Switch though:

dev:3392019-01-05 01:05:53.070 pm errorjava.lang.NullPointerException: Cannot get property 'system' on null object on line 216 (refreshResponse)


#156

Fixed. My error on copying the file!!!!! OUCH. Must be getting old (actually, I was in a hurry to fix same issue on SmartThings).


#157

Updated device code for all devices. Color bulbs no longer have errors except for my long name.


#158

Thanks for the assist in troubleshooting the problem. (BTW, your device is 1 character too long.) I would never have found without the assist.


#159

Hi
I just installed UDP app/driver from GitHub for my HS110 plugs realising the driver doesn't show energy usage and this is the main reason I use the plugs for (OLED TV and room A/C). So if you still need a tester here I am.


#160

Will have a test sometime this weekend. One known issue is the weekly and monthly stat coming back from bulb in two messages (intermittent issue, usually toward end of month). I will try to mitigate - but may still occur sometimes. If these are not important to you, then it will be much easier.

Dave


#161

Updating the existing SmartThings code for this. Will probably be sometime next week (I will announce here). What I am creating:

Current power in Watts
Usage in kWh (also as states for readability in the device detail page.
a. Use by day this month as a JSON object (if feasible)
b. Use by month this year as a Json object (if feasible)
c. Use by month last year as a Json object (if feasible)

All will be as attributes. The Json objects can be accessed in a application to create reports, as desired.


#162

That's great work of yours. Thanks in advance and I'm here if you need me. Just bear in mind I'm in Central Europe UTC+1 - 20.50 hrs here now.


#163

HS110 Energy Monitor Test Driver. I have created a test driver for the HS110 Energy Monitor Plug that provides energy monitor data. File is in the devices folder: "test - TP-Link Engr Meter Plug (Hubitat).groovy".

Uses capability "power" and "energy" and adds attributes "power" (current power in watts) and "energy" (consumption today in kilo watt hours). Also adds states
a, "energyThisMonth" - daily consumption for this month.
b. "energyThisYear" - monthly consumption for this year.
c. "energyLastYear" - monthly consumption last year.
Also added three exposed functions to pull the data from the three states into an application: "sendThisMonth", "sendThisYear", and "sendLastYear". The HS110 can be selected on the input of the application using either capability power or energy.

I need comments back.

Update. You can update an already installed HS110 as follows:
a. On the HE device's page, update the "type" in the Device Information section and "Save Device"
b. Select "Display trace messages", then "Save Preferences".

You can also do a clean install manually.

Example of monthly state (energy_wh will be energy for HS110): energyThisMonth : [{month=1, year=2019, energy_wh=103, day=1}, {month=1, year=2019, energy_wh=133, day=2}, {month=1, year=2019, energy_wh=50, day=3}, {month=1, year=2019, energy_wh=39, day=4}, {month=1, year=2019, energy_wh=80, day=5}, {month=1, year=2019, energy_wh=84, day=6}, {month=1, year=2019, energy_wh=120, day=7}, {month=1, year=2019, energy_wh=50, day=8}, {month=1, year=2019, energy_wh=76, day=9}]

Example of yearly state (2019) ("energy_wh" will be "energy" for HS110): energyThisYear : [{month=1, year=2019, energy_wh=1088}]

Once functionality is verified, I will update the Application to install this driver for the HS110 plug.


#164

My HS110 plugs are arriving today so I should get a change to help with testing.

Thanks

G