I recently bought a GIDEALED ZC05M RGBW LED strip and use it with Z2M (in attribute output mode). After reading this thread, I managed to send HSB values through openHAB (via the colorpicker) to Z2M. This works so far. However, I can’t get openHAB to receive external state updates originating e.g. from the Z2M Web UI. The strip changes colors, but the openHAB HSB color item still keeps the value set via openHAB. Here’s the relevant config:
Things:
Thing mqtt:topic:LightbandStairs "Lichtband Treppe" (mqtt:broker:mosquitto) @ "Treppe" {
Channels:
Type number : hue [ stateTopic="zigbee2mqtt/Lightband_Stairs/color-hue", commandTopic="zigbee2mqtt/Lightband_Stairs/set/color-hue", min=0, max=360 ]
Type dimmer : saturation [ stateTopic="zigbee2mqtt/Lightband_Stairs/color-saturation", commandTopic="zigbee2mqtt/Lightband_Stairs/set/color-saturation", min=0, max=100 ]
Type number : brightness [ stateTopic="zigbee2mqtt/Lightband_Stairs/brightness", commandTopic="zigbee2mqtt/Lightband_Stairs/set/brightness", min=0, max=254 ]
Type color : color_hsb [ stateTopic="zigbee2mqtt/Lightband_Stairs/color-hsb", commandTopic="zigbee2mqtt/Lightband_Stairs/set", formatBeforePublish="{\"color\":{\"hue\":%s,\"saturation\":%s},\"brightness\":%s}", onBrightness=50 ]
Type dimmer : color_temp [ stateTopic="zigbee2mqtt/Lightband_Stairs/color_temp", commandTopic="zigbee2mqtt/Lightband_Stairs/set/color_temp", min=153, max=500 ]
Type switch : state [ stateTopic="zigbee2mqtt/Lightband_Stairs/state", commandTopic="zigbee2mqtt/Lightband_Stairs/set/state" ]
}
Items:
Number LightbandStairsHue "Licht Treppe (Hue)" { channel="mqtt:topic:LightbandStairs:hue" }
Dimmer LightbandStairsSaturation "Licht Treppe (Saturation)" { channel="mqtt:topic:LightbandStairs:saturation" }
Number LightbandStairsBrightness "Licht Treppe (Brightness)" { channel="mqtt:topic:LightbandStairs:brightness" }
Switch LightbandStairs "Licht Treppe [MAP(de.map):%s]" { channel="mqtt:topic:LightbandStairs:state" }
Dimmer LightbandStairsColorTemp "Licht Treppe Farbtemperatur [%s]" { channel="mqtt:topic:LightbandStairs:color_temp" }
Color LightbandStairsColorHSB "Licht Treppe Farbe (HSB) [%s]" { channel="mqtt:topic:LightbandStairs:color_hsb" }
Strip state example from (Z2M Web UI):
{
"brightness": 100,
"color": {
"hue": 359,
"saturation": 100,
"x": 0.6942,
"y": 0.2963
},
"color_mode": "xy",
"color_temp": 158,
"color_temp_startup": 65535,
"last_seen": "2023-01-24T16:19:34+01:00",
"linkquality": 29,
"power_on_behavior": "off",
"state": "OFF"
}
As I said, sending HSB color updates through MQTT works. However, I have to use the above formatBeforePublish. If I use the proposed/default {“color”: “hsb”: “%s,%s,%s”}, the brightness won’t be updated. As a fix for the “openHAB doesn’t get external changes” problem, I introduced a rule to sync hue, saturation and brightness to the openHAB HSB color item, if the three attributes are changed externally, because these (attribute) changes are picked up by openHAB:
rule "Compensate for broken MQTT color state topic updates"
when
Item LightbandStairsHue changed or
Item LightbandStairsSaturation changed or
Item LightbandStairsBrightness changed
then
LightbandStairsColorHSB.postUpdate(LightbandStairsHue.state + "," + LightbandStairsSaturation.state + "," + LightbandStairsBrightness.state)
end
Now, I can change colors using openHAB, Z2M or MQTT and everyone is happy - i.e. the states in sync. But is there a way to get rid of the rule fix? I’d even go the “output attribute_and_json route”, if the solution is more elegant. For example, I don’t know if the stateTopic for color_hsb is right. No matter what I’ve tried so far (no postfix, color, color-hsb), nothing changes. Maybe there’s some magic hidden somewhere that I’m not aware of?