I just try to achieve the same.
However Iam at a different point. Could you show me your outgoing transformation ? For some reason the colorpicker gives me a RGB value and not xy color mode …
Thx ! This exactly.
I was looking at it in MQTT Explorer and I was sure the bulb expects the color information in CIE xyY. Neither I would have tried to send it out formated as RGB nor referring to a value which even does not show
While this solution works to set the RGB value I was a little bit unhappy that within the color picker the slider below does not set the brightness nicely.
So I tried something else and found a way to address the color with CIE XYY:
- id: Color
channelTypeUID: mqtt:color
label: Farbe
description: ""
configuration:
commandTopic: zigbee2mqtt/Livingroom_Floorlamp/set
colorMode: XYY
formatBeforePublish: '{"color":{"x":"%s","y":"%s"},"brightness":"%s"}'
stateTopic: zigbee2mqtt/Livingroom_Floorlamp
transformationPattern: JSONPATH:$.color
Only issue left: The last %s value for the brightness is a percentage (0-100) where the value expected is 1-254…
Any ideas in that ?
I solved this via min/max-Definition in the channel-config.
Thing topic light_tradfri "light_tradfri" {
Channels:
Type switch : state "state" [ stateTopic = "zigbee2mqtt/light_tradfri/state", commandTopic = "zigbee2mqtt/light_tradfri/set/state", on = "ON", off = "OFF" ]
Type dimmer : brightness "brightness" [ stateTopic = "zigbee2mqtt/light_tradfri/brightness", commandTopic = "zigbee2mqtt/light_tradfri/set/brightness", min = 0, max = 254 ]
Type dimmer : color_temp "color_temp" [ stateTopic = "zigbee2mqtt/light_tradfri/color_temp", commandTopic = "zigbee2mqtt/light_tradfri/set/color_temp", min = 250, max = 454 ]
Type string : effect "effect" [ stateTopic = "zigbee2mqtt/light_tradfri/effect" ]
Type string : power_on_behavior "power_on_behavior" [ stateTopic = "zigbee2mqtt/light_tradfri/power_on_behavior" ]
Type number : linkquality "linkquality" [ stateTopic = "zigbee2mqtt/light_tradfri/linkquality" ]
}
BTW, I’v made a groovy script to convert zigbee2mqtt-devices to Things. (see attachement)
mqtt2things.groovy (4.3 KB)
I switched from deconz to zigbee2mqtt today and i didn’t want to waste my time with copy/paste and repetetive typing
- rename it to mqtt2things.groovy
- pipe topic
zigbee2mqtt/bridge/devices
in to it. This generates above output.
mosquitto_sub -t zigbee2mqtt/bridge/devices -C 1 | groovy ./mqtt2things.groovy -n light_tradfri
Then -n
parameter is optional. It restricts procession to the given device-name
Hi,
did you find a solution for the brightness problem?
@p_schlarb
I solved that by using an additional JS script for the necessary transformation.
My channel using the XYY format for the color and brightness looks as follows:
- id: Color
channelTypeUID: mqtt:color
label: Farbe
description: ""
configuration:
commandTopic: zigbee2mqtt/Livingroom_Floorlamp/set
postCommand: true
colorMode: XYY
transformationPatternOut: JS:mqtt_brightness.js
stateTopic: zigbee2mqtt/Livingroom_Floorlamp
transformationPattern: JSONPATH:$.color
The mqtt_brightness.js script is quite simple and just returns the correct formated string with the correct value for the brightness:
(function (x) {
var tmp = x.split(',');
// The brightness value is received as percentage but needed as integer 1-254
tmp[2] = tmp[2] * 2.54;
return '{"color":{"x":"' + tmp[0] + '","y":"' + tmp[1] + '"},"brightness":"' + tmp[2] + '"}'
})(input)
I hope that helps.
Yes, that helps a lot und pointed me into the right direction! I wrote a second script to also transform the incoming value. To summarize for other users, here is my complete solution (looks little different cause i use config files:
Thing:
Thing mqtt:topic:zbltbed01 "Zigbee - Light Schlafzimmer 01" (mqtt:broker:mosquitto) @ "Bedroom"
{
Type color : color "Farbe" [
stateTopic="zigbee/light_bedroom_01",
transformationPattern="JS:tradfri_brightness_in.js",
colorMode="XYY",
commandTopic="zigbee/light_bedroom_01/set",
transformationPatternOut="JS:tradfri_brightness_out.js"
]
}
tradfri_brightness_in.js
(function (x) {
var tmp = JSON.parse(x);
// The brightness value is received as integer 1-254 but needed as percentage
var brightness = Math.round(tmp.brightness / 254 * 100);
return tmp.color.x + ',' + tmp.color.y + ',' + brightness
})(input)
tradfri_brightness_out.js
(function (x) {
var tmp = x.split(',');
// The brightness value is received as percentage but needed as integer 1-254
tmp[2] = tmp[2] * 2.54;
return '{"color":{"x":"' + tmp[0] + '","y":"' + tmp[1] + '"},"brightness":"' + tmp[2] + '"}'
})(input)
Thanks for your help
Hi Helge,
I have the same Problem with the slider. Did you remove the bulb only in OH or in zigbee2mqtt configuation.yml? THX
Mark
Hi everyone,
I’ve got troubles trying to make work a Sonoff SNZB-02 Sensor with zigbee2mqtt/openhab even following the instructions in the first message of this topic.
My thing has an UNKNOWN status…
My Zigbee coordinator is up to date, my zigbee2mqtt also (1.25.2).
Zigbee2mqtt configuration has these parameters:
homeassistant: true
advanced:
output: 'attribute_and_json'
It seems just setting output to attribute is no longer supported as I had an error while starting z2m (“Error: Home Assistant integration is not possible with attribute output!”).
I guess activating both JSON and Attribute can’t hurt.
My item is discovered by OH (3.2 then tried with 3.3.0-M7).
But its states remains ‘UNKNOWN’ and I’m unable to grab any value from the sensor (even if they are available/published in MQTT).
Example:
zigbee2mqtt/0x00124b00251ce9eb/temperature=23.23
and from z2m log file:
info 2022-06-21 18:57:33: MQTT publish: topic 'zigbee2mqtt/0x00124b00251ce9eb/temperature', payload '23.23'
NOTE: I’m not sure experimental/output is still used (unable to find an official doc about this attribute). I think advanced is now the same, but using a different name (unable to find a confirmation either…).
Any clue?
EDIT: obviously, if I set homeassistant to “false”, the item becomes ONLINE… (even if for an unknown reason, temperature is still NULL whereas voltage, battery, humidity have values…)
BUT if homeassistant if set to “false”, the item is not discoverable…