JSONPath control light for ESPresense

Hey guys,
I´m now using RBG light with ESPresense via MQTT.
State = espresense/rooms/eingang/led_1
Command = espresense/rooms/eingang/led_1/set
the JSON output = {“state”:“ON”,“brightness”:255,“color”:{“r”:255,“g”:158,“b”:242}}

Now I need help with the configuration in textual. I copied a thing from a light from zigbee2mqtt,
Type color : Ausenbeleuchtung “Außenbeleuchtung” [
stateTopic=“espresense/rooms/eingang/led_1”,
commandTopic=“espresense/rooms/eingang/led_1/set”,
transformationPatternOut= “JS:bright-zigbee-out.js”,
formatBeforePublish= “%s”,
colorMode= “XYY”,
transformationPattern= “JS:bright-zigbee-in.js”,
off= “0”,
onBrightness= 100,
on= “1” ]

but zigbee2mqtt is using colermode=XYY and ESPresense use RGB.
Can someone tell me a transformation .js how can I control my light.

Thx Joe

Have you tried replacng the XYY with RGB? MQTT Things and Channels - Bindings | openHAB

here is the solution if anybody else need it.

transformation bright-zigbee-in.js

(function(color){
var data = JSON.parse(color);
var bright = Number(data.brightness) / 2.54;
return data.color.r.toString() + “,” + data.color.g.toString() + “,” + data.color.b.toString();
})(input)

transformation bright-zigbee-out.js

(function(color){
var bright = Number(color.split(“,”)[2]) * 2.54;
return ‘{“color”:{“r”:"’ + color.split(“,”)[0] + ‘“,“g”:”’ + color.split(“,”)[1] + ‘“,“b”:”’ + color.split(“,”)[2] +‘"}}’;
})(input)

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.