New TP-Link Smart Home binding with Bulb, Plug and Switch Support

@yeisnier Sometimes it doesn’t directly discover, I don’t know why, but retrying discovery sometimes helps.

@mcqwerty: Are you able to add the lb230 manually in Paper UI using the LB230 device? Also if you run with debug log it should log any detected, but not supported devices during auto discovery. This might indicate incorrect detecting of the bulb. In that case can you post the message here? or run with log trace that gives you even more detailed information.

Regarding:

Energy Usage: I didn’t add this for bulbs as I don’t know what it actually returns and I don’t have these bulbs to test. However, I’ve build the binding in such a way that that it should return this information (but as it’s not tested it might not give the information). If you would run with trace log you should be able to see this in the logging. If you can post this json here I can use it to add this feature.

Time: For switches this is returned (but not used), but for bulbs I don’t have seen it in the default return response. It’s possible to get the information over several days, but this is more complex as it requires to send the date to the device (so that should be in sync) and can be a much larger data set (so limits need to be increased) Since measuring (up)time is also something that can be done using openHAB persistent service, I’m not sure if the added complexity is worth it to build into the binding.

Regading color temperature. There was actually such a channel, but I’ve removed it upon request during code reviews, to make the binding more in line with other light bindings :frowning: The assumption was that most people don’t use very specific kelvin values and thus it’s not necessary to have this kind of detail channel. But if you think this does add value, you could start a new topic about the need for kelvin values in color temperature light bindings.

Here’s how I added the HS200’s to the Items, Things and Sitemap in case that´s useful for someone.

Home.things

//TP-Link HS200 Switches
Thing tplinksmarthome:hs200:X0X00X "Hallway Light" @ "Lights" [ipAddress="192.168.X.XX", refresh=60]

Thing tplinksmarthome:hs200:X0X00X "Kitchen Light" @ "Lights" [ipAddress="192.168.X.XX", refresh=60]

Home.items

//TP-Link HS-200 Switch
Switch TPL1_Switch "Hallway Light" (LivingRoom, Lights) ["Switchable"] { channel="tplinksmarthome:hs200:X0X00X:switch" }
Number TPL1_RSSI "Signal [%d dBm]" (gChart2) { channel="tplinksmarthome:hs200:X0X00X:rssi" }

Switch TPL2_Switch "Kitchen Light" (LivingRoom, Lights) ["Switchable"] { channel="tplinksmarthome:hs200:X0X00X:switch" }
Number TPL2_RSSI "Signal [%d dBm]" (gChart2) { channel="tplinksmarthome:hs200:X0X00X:rssi" }

Home.sitemap

Frame label="Livingroom"
	{
       	Switch item=TPL1_Switch label="Hallway Light" icon="Light"
        Text item=TPL1_RSSI label="Signal [%d dBm]" icon="network"
		
	Switch item=TPL2_Switch label="Kitchen Light" icon="Light"
        Text item=TPL2_RSSI label="Signal [%d dBm]" icon="network"
	}

I used @fritzcm code and replace it with my stuff… :smiley: I hope it helps someone!

I went to Inbox → Clicked ‘+’ → TP-Link Smart Home Devices Binding → Add Manually
But the LB230 bulb is not listed:

image

As mentioned previously I installed the (Beta) version of the TP-Link binding from the marketplace.
I checked the Karaf console and it reports that I have v2.3.0.201712262051 installed.

I guess this explains why my LB230 bulbs were not detected but why do they not show in the device list?

I’m guessing the information you are looking for from the trace is the format of the query response containing the energy details. This portion of my log is below:

28-Dec-2017 13:43:45.298 [TRACE] [penhab.binding.tplinksmarthome.internal.Connection] - Executing command: {"system":{"get_sysinfo":{}}, "smartlife.iot.common.emeter":{"get_realtime":{}}}
28-Dec-2017 13:43:45.339 [TRACE] [penhab.binding.tplinksmarthome.internal.Connection] - Command response: {"system":{"get_sysinfo":{"sw_ver":"1.6.0 Build 170703 Rel.141938","hw_ver":"1.0","model":"LB230(E26)","description":"Smart Wi-Fi LED Bulb with Color Changing","alias":"BathroomMaster_South","mic_type":"IOT.SMARTBULB","dev_state":"normal","mic_mac":"50C7BFEB704E","deviceId":"8012B08FE32574A938AA4DD652AB2E7718CA7D40","oemId":"39DF2F5A8EADED2A390EE4A14D12107B","hwId":"111E35908497A05512E259BB76801E10","is_factory":false,"disco_ver":"1.0","ctrl_protocols":{"name":"Linkie","version":"1.0"},"light_state":{"on_off":1,"mode":"normal","hue":0,"saturation":0,"color_temp":3800,"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":-55,"active_mode":"none","heapsize":298924,"err_code":0}},"smartlife.iot.common.emeter":{"get_realtime":{"power_mw":11000,"err_code":0}}}

It reports this information approx every minute as I have my refresh rate set to 60 in my things file.
Does this give you enough information?

I agree. Since it appears the power_mw property is only non-zero when the bulb is illuminated and appears to be an instantaneous value then all the other metrics can be computed by the user outside of the binding.

:disappointed: I certainly do think it adds value and it’s a shame you were asked to remove it. One real strength of OpenHAB in my opinion is that very little is hidden from the user and one can get as detailed as one prefers. I don’t see the harm of having an additional channel that both reports and enables setting of the direct Kelvin value. If anything, this is a feature that is missing from other bindings (Lifx for example), rather than something that should be removed from yours.

I will see about creating another thread but it seems like the minds of the powers that be are made up. Would adding the additional channel cause issues in a future code review? Maybe there could be a marketplace binding including this channel for advanced users?

@hilbrand

An other topic:

TP-Link announced their new cloudbased IP Camera "Kasa Cam KC120". Currently available in the US. It’s supported by KASA APP.

See here: http://www.tp-link.com/us/products/details/cat-5515_KC120.html

Will it be supported by the OpenHAB binding? Maybe in near future?

Thanks!

It looks like you got a incorrect version of the binding. For the eclipse market place I use the binding build by the openHAB pull request builder. When this binding was not yet part of openHAB this is worked fine as my pr was the only one that created this binding. But now that the binding is part of openHAB it can also be overridden by to other pr’s that only contain what is part of openHAB, (which is not any new code I added that is not part of openHAB). I should probably change this in the future and use another location to store the jar.

The good news is that the pr with new devices support has been merged already, you can use or an openHAB snapshot version of the jar or reinstall the eclipse market place jar.

I think I have enough info on the power_mw property. This looks like it shows power in milliwatt (value is 11000, which looks like 11 watt), I’ll probably will let it show in watt with 1 decimal: (11.0 W).

Regarding color temperature. I think there is still room for discussion. So it might be worth it. For example I was thinking if you have a lb120 and lb130 and want to show the same color temperature, this is almost impossible with percentages since they have both a different color temperature range. Setting the kelvin value in such a case would certainly make sense. I’ll still have the code available, so it would not be to much work to re-add it, in case it is requested. I don’t think a different binding in the marketplace would be a good idea, as it’s more effort to maintain and might create confusion.

To add support to the KASA Cam KC120 I would need to know how to communicate with the device. And at this moment I have no information about this. As I don’t have the device and can’t research this. So if someone is going to provide the necessary information (which will probably require some reverse engineering/network monitoring) I can add support for it.

Ok. Thanks for your reply. At the moment the cam is available only in the US. Maybe someone has it bought yet and has the knowhow to do a network monitoring?

Did this and tried again, auto-detection of my LB230 bulbs worked as did adding manually in the things file using the lb230 device type. Thanks! :smiley:

My thoughts exactly. Your plan sounds great to me, looking forward to the new functionality. Thanks!!!

Right, and I am planning on using various local factors to calculate the ideal colour temperature so I would like to set the K value directly and also have it be generic rather than tied to a particular percentage for a particular bulb implementation. (Lifx has a similar issue but I am guessing it will be even harder to get this functionality added to that binding). I will find some time to create a new post and add a link here.

Once again thanks for your work on this binding and continued support @hilbrand

New binding in eclipse marketplace available with channel to read power value of bulb devices. (It still points to the pull request build location, so it might be inadvertently be overridden if another build process is taking place)

@hilbrand Thanks! Installed and it is working great. Doesn’t look like the code was overwritten by another PR as the lb230 device type is still valid.
I added an item linked to the new thing channel and I am seeing power being reported.

One comment: I see that you named the channel powerMw but the value being reported looks to be Watts (W). So the implementation is as you proposed in an earlier post but the naming of the channel doesn’t seem to be consistent with this. Am I missing something?

Your right about the naming. I also was thinking about this and changed this. I changed the name to power. It’s currently being build so the update will be available once the build on the pr is finished.

Tested and working great. Thanks.

Hi hilbrand,

I received the LB120 Lightbulb as a gift over the holidays and new to OpenHAB in general, but a few things im noticing with the LB120 as I try to control it via the TP Link binding.

The switching on/off status in OpenHAB doesn’t sync all the way. I can turn the bulb on and off via OpenHAB just fine. If I turn the bulb off via the Kasa app though, the TP Link binding will not pick up on this change. If the bulb is off and I turn it on via the Kasa App, the TP Link binding does pick up on the change.

I can adjust Light Color via the TP Link binding, however, the value of the color never stays in sync. It always revert back to a reading of NaN and 0 on a slider. If I make changes to the Light Color via the Kasa App, the TP Link binding will not pick up on this change in any way either.

Brightness/Dimmer is fine though. Any change I make is reflected in both OpenHAB and Kasa.

Hopefully what I described makes sense and wondering if you had any ideas?

This would suggest the status information of the bulb isn’t interpreted correctly by the binding. The binding can log the json returned by the bulb if you set the log level for the binding to trace level. This will among others print the json of the bulb from the get_sysinfo call. The state info is in the light_state block. If possible can you post what it returns in the case of when you switch it off with Kasa, and when you change the color? You might have to wait some seconds after the command given because the data is retrieved at the refresh interval. This information can give me a clue about why it’s not working as intended. At this moment I have no other clue.

Hi,
downloaded the jarin my addons folder, but cant start.

192 | Installed | 80 | 2.2.0.201712161258 | TPLinkSmartHome Binding

bundle:start 192

Error executing command: Error executing command on bundles:
Error starting bundle 192: Could not resolve module: org.openhab.binding.tplinksmarthome [192]
Unresolved requirement: Import-Package: org.eclipse.jdt.annotation; resolution:="optional"
Unresolved requirement: Import-Package: org.eclipse.smarthome.core.cache

How can i install the missing requirements ?

2nd Question - will that bundle show up in the paper ui so that i can configure mit things and items and use it in the HABPanel?

Sorry iam new to openhab2 and still figuring out how thinks work.

greetings

Ben

The normal way is to just install the binding through paper ui. I looks like you tried to manually install something instead.

in the paper ui , it didnt show up on openhab2

It’s available in version 2.2, otherwise try via eclipse marketplace. The marketplace is a binding you first need to install via paper UI binding

Thanks for the info , iam running on stable 2.0 is it possible to upgrade ? or need to make afresh install ?

I think it’s not compatible with that version, which explains the error you got. I’m not familiar with that upgrade path, so can’t give advice.