I use openHAB 2.5 with the MQTT binding and koenks Zigbee2mqtt. In the files mqtt.things and mqtt.items I made corresponding entries for some Philips Hue and Innr devices. So far this works quite well. I also managed to display a color wheel on the sitemap and control the Hue light strip accordingly when the color changes. Unfortunately I can’t manage to transport a change of color from the light strip back to the HSB Color Item. For example, if I change the color of the light strip with another app, the item on the site map should also change. Specifically, the problem is that changing the color results in 2 to 3 MQTT Topics. But then these have to change a single channel and item. How do I solve this problem?
mqtt.things:
Type colorHSB : color "Color" [ commandTopic="zigbee2mqtt/<friendlyname>/set/color", formatBeforePublish="{\"hsb\":\"%s,%s,%s\"}"]
mqtt.items:
Color Kitchen_Worktop_Light_Color "Color" {channel="mqtt:topic:mosquitto:<friendlyname>:color"}
At this point I have to mention that I use Zigbee2mqtt with the output: attribute option. This is currently considered an improvement. But I have the feeling that this could be the cause that I do not get the 3 HSB values back into the item. What do you think?
Now you’ve got the detail in one MQTT payload, you can use a javascript transform to extract individual elements and collect as a single string to be returned to an openHAB Item
Thank you so much. This was exactly what I needed. I completed my code with corresponding outbound transformation:
mqtt.things
Type colorHSB : color "Color" [ stateTopic="zigbee2mqtt/<friendlyname>", commandTopic="zigbee2mqtt/<friendlyname>/set/color", transformationPattern="JS:colorjson2csv.js", transformationPatternOut="JS:colorcsv2json.js"]
mqtt.items
Color Kitchen_Worktop_Light_Color "Color" {channel="mqtt:topic:mosquitto:<friendlyname>:color"}