To be honest I also have troubles reading the color state from a light bulb via z2m and never got it working.
However, as I only control my light via openhab I recognized that there is no need to read the color value, as I only need to write the color value (and OH will always store the correct color state in the item).
Maybe just in case you do not find a solution, that’s an acceptable workaround for you
Ahh I might be able to help here, I think.
This is what I do to get the values from json sent by zigbee devices:
install the json transformation plug-in from the menu “other plug-ins”.
create the channel/configure existing channel
check the “show advanced “ options
scroll allllll the way down and type in “incoming/outgoing value transformation” fields (both of them) the following:
“ jsonpath:$.consumer_connected “
Where “consumer_connected” is the value from the json that I wanted to pick up.
So you’ll want to change that for what you want.
For example “color_temp”
So: jsonpath:$.color_temp
Also I checked zigbee2mqtt.io and confirmed that you should be able to send back rgb values instead:
color_xy: To control the XY color (CIE 1931 color space) publish a message to topic zigbee2mqtt/FRIENDLY_NAME/set with payload {"color": {"x": X_VALUE, "y": Y_VALUE}}(e.g. {"color":{"x":0.123,"y":0.123}}). To read the XY color send a message to zigbee2mqtt/FRIENDLY_NAME/get with payload {"color":{"x":"","y":""}}.
Alternatively it is possible to set the XY color via RGB:
{"color": {"r": R, "g": G, "b": B}} e.g. {"color":{"r":46,"g":102,"b":150}}
{"color": {"rgb": "R,G,B"}} e.g. {"color":{"rgb":"46,102,150"}}
{"color": {"hex": HEX}} e.g. {"color":{"hex":"#547CFF"}}
I’d start by getting an mqtt explorer up and simulating the sending of the packages to the bulb until I got it right, before going to openHAB though.
Those lidl bulbs seem great, and somewhat complex for such tiny and cheap devices.
Edit #462893: I’m not good with the blockquote thinggiemajig….
From my point of view the issue is not to read the mqtt message. The real issue is, that z2m is only sending x&y values for the color but OH is expecting xyY within the color part of the mqtt message.
Therefore you would always need a rule to calculate the correct xyY (or rgb or hex color code) based of the given mqtt message and send it to the item.
Yes, maybe my head was thinking about something different than my fingers where typing
SENDING is working fine with RGB
For READING, in the first post the mqtt message is published and if you just provide the color part with x&y attributes to openhab then OH will complain
OHHhhhhhh….
Crap you’re right. Didn’t think about that.
But… I remember seeing in the community another post, using the openHAB zigbee binding (not z2m) and we could pick between XY, hue or auto.
So definitely this is possible to be done…