TP-Link Kasa lights will not change color via rule

I’ve been racking my brain on this and after 12 hours I definitely stuck but perhaps, there is an issue with the TP-Link binding.

I’m using OH 2.5 and the beta TP-Link binding (Beta 30-8-2019). I have a virtual switch item that I’m using to issue groups changes to several KL130 light bulbs (these are the ones that have fulll color and white temperature control). I can turn them on, set the temperature but changing the color is no go. To diagnose, I’ve been using one of the bulbs to test (item office_lamp_c). Here are the relevant bits…

(I can provide the complete blocks if needed)

.Items:

// Groups
Group Lights
Group:Switch:OR(ON,OFF) internal (Lights)
Group:Switch:OR(ON,OFF) external (Lights)
Group internalColor // this would be the group to control the bulb color
Group internalClrTmp

// virtual switches
String    scene_vs

Switch    office_lamp_p       "Office Lamp"                             <switch> (Lights,internal)     { channel="tplinksmarthome:kl130:6FF206:color" }
Number    office_lamp_ct      "Office Lamp Color Temperature [%dK]"              (Lights,internalClrTmp)     { channel="tplinksmarthome:kl130:6FF206:colorTemperatureAbs" }
Color     office_lamp_c       "Office Lamp Color"                       <colorwheel>    (Lights,internalColor)     { channel="tplinksmarthome:kl130:6FF206:color" }

.sites:

Frame label="Controls" {
        Group item=Lights {
                Selection item=scene_vs label="Scenes" mappings=[0="Default", 1="TV Lighting", 2="Fireplace Lighting"] 
  }
}

.rules:

import org.eclipse.smarthome.core.library.types.HSBType
import org.eclipse.smarthome.core.library.types.DecimalType
import org.eclipse.smarthome.core.library.types.PercentType

rule "Scene Selection"
when Item scene_vs received command
then
        if (receivedCommand == "0") {
        val HSBType myColor = new HSBType(new DecimalType(0),new PercentType(0),new PercentType(5))
        var Number myColorTemp = 2700
        internal.sendCommand(ON)
        office_lamp_c.sendCommmand(myColor)
        internalClrTmp.sendCommand(myColorTemp)
        }
end

The error I am getting, which is visible in openhab.log file is:

[ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule ‘Scene Selection’: ‘sendCommmand’ is not a member of ‘org.eclipse.smarthome.core.library.items.ColorItem’; line 14, column 9, length 35

What is strange is that I should be able to directly use an HSB string, like so:

office_lamp_c.sendCommmand("0,0,5")

That is literally take from the event.log, when I control the light via the Kasa app…

[vent.ItemStateChangedEvent] - office_lamp_c changed from 0,0,100 to 0,0,5

However, in both case, I get that same error.

After reviewing similar posts about controlings hues for other bulbs I’m at a lost for what might be wrong. I’ve tried declaring the vars outside the block (i.e. above the rule name and below the imports) as well as directly referenings the libraries and not using the imports. I consistently get the same error.

I don’t think I’ve missed anything but if I have please let me know. There are some other quirks and issues I’ve noticed using the Kasa bulbs (which I absolute love and are priced right) that I haven’t posted about yet (and beta is beta) but this error doesn’t make much sense to me.

Try restarting OH.

I’ve done that as well.

Can you set the color on individual bulbs via the UI, like in PaperUI?

Yes, PaperUI has complete control… BasicUI and the android app (i.e. using sitemaps) has a problem with setting color temperature (I’m going to do the bug report in the next few days on that later along with some other Kasa issues) but ironically, setting the color temperature works via the rules.

Can you use the code fences on your post, please so that we can read your code, thanks

updated… thanks for pointing that out

According to the binding docs:

KB130 Kasa Multi-color Smart Light Bulb

    Power On/Off
    Fine-tune colors
    Adjust light appearance from soft white (2500k) to daylight (9000k)
    Adjust the brightness
    Actual power usage
    Wi-Fi signal strength (RSSI)

Switching, Brightness and Color is done using the color channel.

You need to adjust the brightness via the color channel.
The channel colorTemperatureAbs looks like is read only

In the items you show they all point to the same bulb and if I read your rule correctly you first set the color and then the colorTemperatureAbs on the same bulb? Is that intended? Because colorTemperatureAbs would simply override the color changes.

P.s. the colorTemperatureAbs is not read only.

You are correct but it wasn’t commented out because the last thing I did to see was to have that line about the color one make sure the color temperature was being set (and it is). I was isolating where the rule was failing.

That said, the correct procedure for setting a white color is to send the color temperature first and then use the color channel to set the brightness with the first two parameters set to 0. For example, to set a bulb to white with a color temperature fo 5500K and brightness of 30%. I should be able to do something like this:

office_lamp_ct.sendCommand(5500)
office_lamp_c.sendCommmand("0,0,30")

Here’s something interesting…

In reviewing

https://www.eclipse.org/smarthome/documentation/javadoc/org/eclipse/smarthome/core/library/items/ColorItem.html

It is true that sendCommand is not there. However there is a send function and when I do this:

office_lamp_ct.sendCommand(5500)
office_lamp_c.send("0,0,30")

It works!

Question is, is that right? Seems like an API issue to me.

Also, before I did this, I tried removing all my import lines too- no joy.

1 Like

Sorry to double-post but my example wasn’t quite right and I wanted to state the full logic that now works with the entire group of lights:

if (receivedCommand == "0") {
val HSBType myColor = new HSBType(new DecimalType(0),new PercentType(0),new PercentType(5))
var Number myColorTemp = 2700
internal.sendCommand(ON)
internalClrTmp.sendCommand(myColorTemp)
internalColor.send(myColor)
}

Apparently with the .send method you do have to use the proper HSBType. It will not take a string as I previously stated.