Solved: Zigbee2MQTT and openHAB colors

Hello,

I’m an openHAB user for over 5 years from now, but I still don’t get the Color Items working with Zigbee2MQTT. I spend so many days in researching, trying, scripting and failing. It’s so frustrating.

Can someone help me on this?
I’m using openHAB 3 with the MQTT binding.
All devices in my home are working with zigbee and are connected with Zigbee2MQTT.
I have devices from LIDL, Tuya, IKEA and so on.
I can control all the devices with openHAB except the Color.

What I learned:

  1. There are different ways to define color (color spaces, CIE 1931 xyz, RGB, HSV/HSB)
  2. openHAB provides an Item of the type Color.
  3. A color picker in the UI only works with an Color Item.
  4. In the mqtt binding there is also an Item of the type Color.
  5. If I select a Color (e.g. red) in the color picker the Item gets updated with the matching HSV/HSB value e.g. 0,100,100 (H,S,B) and the MQTT binding sends it to the configured MQTT topic “zigbee2mqtt/bulb1/set”.
  6. Zigbee2MQTT supports different vendors of color light bulbs.
  7. Different vendors use different ways to define color (IKEA & LIDL: xy or RGB)
  8. Zigbee2MQTT needs a specific formatted MQTT message and a matching Color definition to work with the Color Items. e.g. {“color”: {“rgb”: “R,G,B”}} or {“color”: {“x”: X_VALUE, “y”: Y_VALUE}}
  9. To do this, I have to write a transformationPatternOut in the MQTT Thing to convert HSV/HSB to RGB (I did not find a conversion for xy)
  10. Now I can set the color with the Color picker in openHAB and the bulb turns to the right Color.
  11. But I get a warning on console, because Zigbee2MQTT sends an “answer” to the MQTT topic of the state of the bulb “zigbee2mqtt/bulb1” with converted xy values {“color”:{“x”:0.6307692307692307,“y”:0.3230769230769231}}.
  12. openHAB does not understand the value of the data, I would need to add an additional transformationPattern in the MQTT Thing to convert it back to HSV (I did not find a conversion for this)

This is very complex.
Is there an easier way to to this?
Is there a way to get the openHAB Color picker working with Zigbee2MQTT?

Thank you for your help, I really appreciate it!

Have a look at this.

@clinophobic Thank you, that’s it. I’m so happy, that it works now! It could have been so easy, I already had this idea, but it did not work at my try. :smiling_face_with_tear:

1 Like

Thank you joke24 for detailled listing of your steps and findings. I went through the same process!!!
I am running OH 3.4 and went through the learning curve - upgrading from 2.4 to 3.4. The automatic upgrade worked fine, but eventually I decided to start clean and do everything within the new environment, so I started from scratch and I don’t regret that!

Here is a short description on how I got the Color Picker working in OH 3.4 (sorry its in German):

1. ITEM "Color" erstellen und eindeutige ID und Label vergeben, dann speichern
2. unter "Add Metadata" unter "Default Standalone Widget" "Color Picker Card" auswählen und als Modul z.B. das "Color wheel" auswählen.
3. Speichern
4. Nun ein THING z.B. MQTT, General MQTT Thing erstellen.
5. Dann Channel mit Funktion "Color" und entsprechende "Color Mode" erstellen.
6. MQTT Command Topic z.B. "zigbee2mqtt/LED SchlaZi farbig/set"
7. Advanced Settings ---> Outgoing Value Format Beispiel: {"color": {"x": %s, "y": %s}} Profil bleibt aus "Standard"
8. alles abspeichern und Channel mit dem erstellten ITEM linken
9. und es sollte funktionieren, bei mir hat es mit einer IKEA color light bulb einwandfrei funktioniert!