ZigBee2MQTT how to control IKEA Tradfri color temperatre?

Hi,

I’m trying to get rid of the IKEA tradfri bridge since it frequently crashes and has huge lags when I’m trying to connect so it (via app or Google Home).

My Setup

Thing configuration

Thing mqtt:topic:tfb1ez2 "Hängelampe mitte" (mqtt:broker:zigbee2mqtt) @ "Esszimmer" {
    Channels:
        Type switch : switch "An/Aus" [
            stateTopic="zigbee2mqtt/bulbs/gf/livingroom/pendant1/state",
            commandTopic="zigbee2mqtt/bulbs/gf/livingroom/pendant1/set/state",
            on="ON", off="OFF",
            retained=true
        ]
        Type dimmer : brightness "Helligkeit" [
            stateTopic="zigbee2mqtt/bulbs/gf/livingroom/pendant1/brightness",
            commandTopic="zigbee2mqtt/bulbs/gf/livingroom/pendant1/set/brightness_percent",
            formatBeforePublish="%d",
            min=0, max=255,
            off="OFF", on="ON",
            retained=true
        ] 
        Type dimmer : colortemp "Farbtemperatur" [
            stateTopic="zigbee2mqtt/bulbs/gf/livingroom/pendant1/color_temp",
            commandTopic="zigbee2mqtt/bulbs/gf/livingroom/pendant1/set/color_temp",
            min=0, max=455,
            retained=true
        ]
        Type switch : availability "Availability" [
            stateTopic="zigbee2mqtt/bulbs/gf/livingroom/pendant1/availability",
            off="offline", on="online",
            retained=true
        ]
        Type dimmer : linkquality "Verbindungsqualität" [
            stateTopic="zigbee2mqtt/bulbs/gf/livingroom/pendant1/linkquality",
            min=0, max=255,
            retained=true
        ]
        Type datetime : lastseen "Zuletzt online" [stateTopic="zigbee2mqtt/bulbs/gf/livingroom/pendant1/last_seen", retained=true] 
}

Item configuration

Switch      Light_GF_Dining_PendantLights_Center_Switch         "An/Aus"                                <DimmableLight>     (gFP_Lights)    {channel="mqtt:topic:tfb1ez2:switch"}
Dimmer      Light_GF_Dining_PendantLights_Center_Brightess      "Helligkeit [%d %%]"                    <DimmableLight>     (gFP_Lights)    {channel="mqtt:topic:tfb1ez2:brightness"}
Dimmer      Light_GF_Dining_PendantLights_Center_LightColor     "Farbtemperatur [%d %%]"                <ColorLight>        (gFP_Lights)    {channel="mqtt:topic:tfb1ez2:colortemp"}
DateTime    Light_GF_Dining_PendantLights_Center_LastSeen       "Zuletzt [%1$ta %1$td. %1$tb %1$tR]"    <Time>              (gFP_Lights)    {channel="mqtt:topic:tfb1ez2:lastseen"}
Dimmer      Light_GF_Dining_PendantLights_Center_LinkQuality    "Signalstärke [%d %%]"                  <qualityofservice>  (gFP_Lights)    {channel="mqtt:topic:tfb1ez2:linkquality"}
Switch      Light_GF_Dining_PendantLights_Center_Availability   "Online"                                <switch>            (gFP_Lights)    {channel="mqtt:topic:tfb1ez2:availability"}

Problems

Controlling color temperature
I can’t properly control the color temperature. The bulb seems to have color-x/color-y, color_temp and color_mode to control the color temperature.
I tried color_mode first. As a freshly reset lamp returns {"color_mode" : "2"}, I tried setting:

mosquitto_pub -t 'zigbee2mqtt/bulbs/gf/livingroom/pendant1/set' -m '{"color_mode" : 1}'

But it yielded me the error:

zigbee2mqtt:error 2019-12-3 18:46:22 No converter available for ‘color_mode’ (1)

As I don’t know how to properly/valid set/control the color-x/color-y values, I tried color_temp then and it seems to have a range from 0 to 455 (even though I find that range strange, so I might be wrong here). After the factory reset the bulb had a value of 370 and I didn’t notice a change in the color temperature when sending a value higher than 455 with mosquitto via:

mosquitto_pub -t 'zigbee2mqtt/bulbs/gf/livingroom/pendant1/set' -m '{"color_temp" : 455}'

While setting the color temperature seems to work via mosquitto_pub it won’t work via the PaperUI. When I try to set the color temperature via the slider of the dimmer item, I get the warning:

[WARN ] [generic.internal.generic.ChannelState] - Command ‘370’ not supported by type ‘PercentageValue’: Value must be between 0 and 100

And the slider jumps from e.g. 90% back to ~20%. Accordingly a max value of 100 is applied and the light temperature is always some kind of cold white.

If I change the channel config in the thing configuration to use the following commandTopic

commandTopic="zigbee2mqtt/bulbs/gf/livingroom/pendant1/set/color_temp_percent",

Using the slider yields the warning:

[WARN ] [generic.internal.generic.ChannelState] - Command ‘500’ not supported by type ‘PercentageValue’: Value must be between 0 and 100

When I try to set 100% light temperature, which is very strange since the max value is still 455. When I try to set 0%, the slider falls back to and sticks with ~35%.

Questions

  • Does anyone have any idea how to properly control the color temperature?
  • Does anyone know how to set/control color_mode or color-x/y and what the difference is?



Side question:

The Dimmer item for controlling the brightness channel comes with a Off/On switch in the PaperUI (see screenshot). I can’t use it. When I click it, it yields the following error:

19:28:14.628 [ERROR] [rnal.common.AbstractInvocationHandler] - An error occurred while calling method ‘ThingHandler.handleCommand()’ on ‘org.eclipse.smarthome.binding.mqtt.generic.internal.handler.GenericThingHandler@ad55c0’: null
java.lang.NumberFormatException: null
at java.math.BigDecimal.(BigDecimal.java:494) ~[?:?]
at java.math.BigDecimal.(BigDecimal.java:383) ~[?:?]
at java.math.BigDecimal.(BigDecimal.java:806) ~[?:?]
at org.eclipse.smarthome.core.library.types.DecimalType.(DecimalType.java:57) ~[102:org.eclipse.smarthome.core:0.10.0.oh240]
at org.eclipse.smarthome.core.library.types.PercentType.(PercentType.java:47) ~[102:org.eclipse.smarthome.core:0.10.0.oh240]
at org.eclipse.smarthome.core.library.types.PercentType.valueOf(PercentType.java:63) ~[102:org.eclipse.smarthome.core:0.10.0.oh240]
at org.eclipse.smarthome.binding.mqtt.generic.internal.values.PercentageValue.update(PercentageValue.java:87) ~[?:?]
at org.eclipse.smarthome.binding.mqtt.generic.internal.generic.ChannelState.publishValue(ChannelState.java:302) ~[?:?]
at org.eclipse.smarthome.binding.mqtt.generic.internal.handler.AbstractMQTTThingHandler.handleCommand(AbstractMQTTThingHandler.java:119) ~[?:?]
at sun.reflect.GeneratedMethodAccessor65.invoke(Unknown Source) ~[?:?]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
at java.lang.reflect.Method.invoke(Method.java:498) ~[?:?]
at org.eclipse.smarthome.core.internal.common.AbstractInvocationHandler.invokeDirect(AbstractInvocationHandler.java:153) [102:org.eclipse.smarthome.core:0.10.0.oh240]
at org.eclipse.smarthome.core.internal.common.InvocationHandlerSync.invoke(InvocationHandlerSync.java:59) [102:org.eclipse.smarthome.core:0.10.0.oh240]
at com.sun.proxy.$Proxy155.handleCommand(Unknown Source) [239:org.eclipse.smarthome.binding.mqtt.generic:0.10.0.oh240]
at org.eclipse.smarthome.core.thing.internal.profiles.ProfileCallbackImpl.handleCommand(ProfileCallbackImpl.java:75) [109:org.eclipse.smarthome.core.thing:0.10.0.oh240]
at org.eclipse.smarthome.core.thing.internal.profiles.SystemDefaultProfile.onCommandFromItem(SystemDefaultProfile.java:49) [109:org.eclipse.smarthome.core.thing:0.10.0.oh240]
at sun.reflect.GeneratedMethodAccessor63.invoke(Unknown Source) ~[?:?]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
at java.lang.reflect.Method.invoke(Method.java:498) ~[?:?]
at org.eclipse.smarthome.core.internal.common.AbstractInvocationHandler.invokeDirect(AbstractInvocationHandler.java:153) [102:org.eclipse.smarthome.core:0.10.0.oh240]
at org.eclipse.smarthome.core.internal.common.Invocation.call(Invocation.java:53) [102:org.eclipse.smarthome.core:0.10.0.oh240]
at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:?]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:?]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:?]
at java.lang.Thread.run(Thread.java:748) [?:?]

  • Why is that?
  • How can I fix it?

image

Regards

You need a newer version of the MQTT binding, there have been some issues solved for the upcoming 2.5 version of openHAB.
Release is scheduled for December 15th.
In the meantime, you could check Milestone 6.

Also for using the Dimmer item built-in switch?

PaperUI is intended for configuration and not controlling your devices. Try creating a sitemap and use BasicUI.

Hello,

I faced this problem with the color setting of tradfri bulbs. Maybe you can use it for saturation, too.

My very simple rule

import org.openhab.core.library.types.*

var HSBType hsbValue
var int redValue
var int greenValue
var int blueValue
var String RGBvalues

rule “Set RGB string”
when
Item ColorTest changed
then
hsbValue = ColorTest.state as HSBType

redValue = hsbValue.red.intValue
greenValue = hsbValue.green.intValue
blueValue = hsbValue.blue.intValue

// Concat the string for zigbee2mqtt
RGBvalues= “{“color”:{“r”:” + redValue.toString + “,“g”:”+ greenValue.toString + “,“b”:”+ blue$
sendCommand(ColorLightStringForZig2Mqtt, RGBvalues)
end

As you can see, I convert the color item “ColorTest” to an hsbValue. Accorting to HSB Documenation, there is also a saturation value.

Hope this helps.

Best regards
Chris

@kurztipp Hi Peter, a couples of questions if I can

Where did you find all the attributes for the Ikea bulb?
Why you specify a dimmer type for the information item link quality? I think it’s better a string for it .
Is there a special reason for which you also specify the retain parameter?
Finally, have got the right configuratin for managing color and brughtness values?

@Brignoud

The attributes are listed in the mqtt topic. You can read it from there.

For no specific reason. A string might be better, yes.

Yep, to have a simple persistence.

Brightness: min=0, max=255
ColorTemp: min=154, max=500

At least that’s worked for me. I figured it by sending different values to the bulbs. If it were to high/low I got an error.

1 Like

Sorry, what’s Availability stand for? Didn’t find it in my mqtt topic