Closed Andre1Becker closed 1 year ago
Well - i have made a mistake... my in and output transformation was wrong... so it seems to work fine now:
openHAB channel config:
channels:
- id: LEDKochinselXY
channelTypeUID: mqtt:color
label: LEDKochinselXY
description: null
configuration:
commandTopic: zigbee2mqtt/LEDKochinsel/set
colorMode: XYY
transformationPatternOut: JS:zigbeeColorOUT.js
formatBeforePublish: "%"
stateTopic: zigbee2mqtt/LEDKochinsel
transformationPattern: JS:zigbeeColorIN.js
transformation scripts:
zigbeeColorOUT.js
(function(color){
// convert 100% to 254 Steps of brightness
var bright = Number(color.split(/[,:]/)[2]) * 2.54;
// example output to mqtt: {"brightness":239,"color":{"x":0.601297,"y":0.311017}}
return '{"brightness":' + bright.toFixed(0) + ',"color":{"x":' + color.split(/[,:]/)[0] + ',"y":' + color.split(/[,:]/)[1] + '}}';
})(input)
zigbeeColorIN.js
// example input: {"brightness":50,"color":{"hue":359,"saturation":100,"x":0.6942,"y":0.2963},"color_mode":"xy","color_temp":158}
(function(color){
// convert 254 Steps to 100% of brightness
var bright = Number(color.split(/[,:]/)[1]) / 2.54;
// example output to openHAB: x,y,brightness - f.e.: 0.6942,0.2963,50
return color.split(/[,:]/)[8] + "," + color.split(/[,:}]/)[10] + "," + bright.toFixed(0);
})(input)
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days
Is your feature request related to a problem? Please describe
Hi all,
So here is a short description of my "Problem":
i've got two Miboxer FUT038Z LED Strip controllers. If i set the color via zigbee2mqtt webfrontend (expose), the json output looks like this (which makes no sense for me as it is a mix of HUE and xyY):
{"brightness":50,"color":{"hue":359,"saturation":100,"x":0.6942,"y":0.2963},"color_mode":"xy","color_temp":158}
Which looks fine at first. But if i want to use this output as a input with openhab, i have to do some "ugly" transformation to get thinks working.
here is an example of my color channel in openHAB: configuration: commandTopic: zigbee2mqtt/LEDKochinsel/set colorMode: XYY formatBeforePublish: '{"color":{"x":"%1$s","y":"%2$s"}}' stateTopic: zigbee2mqtt/LEDKochinsel transformationPattern: REGEX:s/{"brightness":(.?),"color":{(?<=)"hue":(.?),"saturation":(.?)(?=),"x":(.?),"y":(.?)},.}/$4,$5,$1/g
Describe the solution you'd like
So here is my request: Implement a possibility to configure the in and output format for the color types that exists out there f.e.:
HSB: HUE, SATURATION, BRIGHTNESS xyY :
{"color":{"x":%s,"y":"%s"},"brightness":"%s"}
RGB: Red,Green,BlueI dont know if there ist a MQTT "Standard" for JSON Color syntax - but i guess not. So it would be nice to set this in zigbee2mqtt if the receiving app could not prase oder transform the output / input message.
Update:
Well first of all would it be nice if the input has the same syntax as the output. So if xyY is outputed then the input should be accept the same formart.
As in my case this is different:
Output from zigbee2mqtt:
{"brightness":50,"color":{"hue":359,"saturation":100,"x":0.6942,"y":0.2963},"color_mode":"xy","color_temp":158}
expected input:
{"color":{"x":0.123,"y":0.123}}
Which is obviously different from the output :-) - and also missing the brightness part...I hope this makes sense to anyone ;-) Cheers