Use dashboard color picker for deconz conbee2 RGBW stripe

Good evening everybody.

I'm new to Node RED and have no real java experience.
I'm using node red on a raspberry pi with a conbee2 stick in combination with node-red-contrib-deconz.
Switching the stripe on and off, changing the color temperature and these things work fine.
Unfortunately I don't manage to get the RGB colors changed. I think I need to modify RGB to CIE. I didn't find a color converter doing this job for me so I tried several things including modifying the code shown here:


I don't want to bore you with all my tries to get it done, becaus my java skills are basically non existent.
I could live with just picking pre-defined colors as a plan B which also doesn't work for me.
When I use FHEM with HUE and the same conbee2 stick I can change colors to for example red the following output on debug can be seen:
8.12.2020, 23:32:20[node: RGB_Stripe State output](http://172.18.143.20:1880/#)msg.payload : Object
object
alert: null
bri: 10
colormode: "xy"
ct: 153
effect: "colorloop"
hue: 0
on: true
reachable: true
sat: 254
xy: array[2]
0: 0.7291
1: 0.2783

Do you have any ideas on how to set the xy array correctly within node red? Preferred of course with the color picker.

Thank you very much in adance! I'm spending about 3 evenings on that issue now...

Best regards,
Georg

You can set the colour picker to return an RGB object and then use the function you pointed at - for example as below - Not sure what you then want to do with the result but hey...

[{"id":"442a1104.d9411","type":"ui_colour_picker","z":"2988ea8b.bedff6","name":"","label":"","group":"61ae4ef4.28011","format":"rgb","outformat":"object","showSwatch":true,"showPicker":false,"showValue":false,"showHue":false,"showAlpha":false,"showLightness":true,"square":"false","dynOutput":"false","order":0,"width":0,"height":0,"passthru":true,"topic":"","x":240,"y":320,"wires":[["cbae7de9.f5e34"]]},{"id":"cbae7de9.f5e34","type":"function","z":"2988ea8b.bedff6","name":"","func":"\nfunction rgb_to_cie(red, green, blue)\n{\n\t//Apply a gamma correction to the RGB values, which makes the color more vivid and more the like the color displayed on the screen of your device\n\tvar red \t= (red > 0.04045) ? Math.pow((red + 0.055) / (1.0 + 0.055), 2.4) : (red / 12.92);\n\tvar green \t= (green > 0.04045) ? Math.pow((green + 0.055) / (1.0 + 0.055), 2.4) : (green / 12.92);\n\tvar blue \t= (blue > 0.04045) ? Math.pow((blue + 0.055) / (1.0 + 0.055), 2.4) : (blue / 12.92); \n\n\t//RGB values to XYZ using the Wide RGB D65 conversion formula\n\tvar X \t\t= red * 0.664511 + green * 0.154324 + blue * 0.162028;\n\tvar Y \t\t= red * 0.283881 + green * 0.668433 + blue * 0.047685;\n\tvar Z \t\t= red * 0.000088 + green * 0.072310 + blue * 0.986039;\n\n\t//Calculate the xy values from the XYZ values\n\tvar x \t\t= (X / (X + Y + Z)).toFixed(4);\n\tvar y \t\t= (Y / (X + Y + Z)).toFixed(4);\n\n\tif (isNaN(x))\n\t\tx = 0;\n\tif (isNaN(y))\n\t\ty = 0;\t \n\treturn [x, y];\n}\n\nmsg.payload = rgb_to_cie(msg.payload.r, msg.payload.g, msg.payload.b);\nconsole.log(msg.payload);\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":430,"y":320,"wires":[["c3301e99.a53ae"]]},{"id":"c3301e99.a53ae","type":"debug","z":"2988ea8b.bedff6","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":630,"y":320,"wires":[]},{"id":"61ae4ef4.28011","type":"ui_group","name":"Group 1","tab":"5c9690fd.741cc","order":1,"disp":true,"width":"6","collapse":false},{"id":"5c9690fd.741cc","type":"ui_tab","name":"Home","icon":"dashboard","order":1,"disabled":false,"hidden":false}]

Thank you very much for your help. I'm definately one step further.
I modified the following line in order to press the array into msg.payload.xy instead of msg.payload

msg.payload.xy = rgb_to_cie(msg.payload.r, msg.payload.g, msg.payload.b);

It seems that the x and y values are send as string instead of float. I guess that's the issue that it still doesn't work.

Screenshot from a correct payload generated via FHEM:
correct_payload_example

Payload generated within node-red:
incorrect_payload

The result should be that the color picker can adjust my RGB stripe via deconz. Deconz seems to just accept xy input as RGB value. Hue doesn't have any effect in my case. Please also see all available options in the ouput node:

Ah didn't spot that - just remove the .toFixed(4) from the two lines in formula.
toFixed truncates to 4 decimal places but also converts to a string...

Cheers again! That also did the trick.
Anyway my RGB color changes just work from FHEM.

Brightness, on/off and even color temperature for the 2 additional WW/CW-leds work fine within node-red.

Do you have any further ideas? Please find attached my complete flow including working switches / brighness controll and the non-working RGB logic.

Sorry to bother you with these beginner questions!

[{"id":"5dc3e86c.3246a8","type":"tab","label":"RGB...","disabled":false,"info":""},{"id":"91e8f0ea.63ee9","type":"deconz-output","z":"5dc3e86c.3246a8","name":"RGB_stripe: bri slider","server":"d261a0f2.dd789","device":"58:8e:81:ff:fe:e2:d6:08-01","device_name":"LED_stripe : Extended color light","command":"bri","commandType":"deconz_cmd","payload":"payload","payloadType":"msg","transitionTime":"","x":860,"y":120,"wires":[]},{"id":"84323554.1fa7e8","type":"deconz-input","z":"5dc3e86c.3246a8","name":"RGB_stripe","server":"d261a0f2.dd789","device":"58:8e:81:ff:fe:e2:d6:08-01","device_name":"LED_stripe : Extended color light","topic":"","state":"0","output":"always","outputAtStartup":true,"x":90,"y":120,"wires":[["2bbef0da.c5402","a80cd64d.069a48","9bc1c7f8.4a45a8"],["a8666c8b.5e30d"]]},{"id":"2bbef0da.c5402","type":"debug","z":"5dc3e86c.3246a8","name":"RGB_Stripe State output","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":270,"y":320,"wires":[]},{"id":"a8666c8b.5e30d","type":"debug","z":"5dc3e86c.3246a8","name":"RGB_stripe Homekit output","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":260,"y":360,"wires":[]},{"id":"1ec55ef6.2f5501","type":"ui_slider","z":"5dc3e86c.3246a8","name":"brightness slider","label":"RGB Helligkeit","tooltip":"","group":"db3115ee.3d0d58","order":2,"width":0,"height":0,"passthru":true,"outs":"end","topic":"","min":"1","max":"255","step":1,"x":580,"y":120,"wires":[["91e8f0ea.63ee9"]]},{"id":"6bc87841.1ee9e8","type":"deconz-output","z":"5dc3e86c.3246a8","name":"RGB_stripe: switch","server":"d261a0f2.dd789","device":"58:8e:81:ff:fe:e2:d6:08-01","device_name":"LED_stripe : Extended color light","command":"on","commandType":"deconz_cmd","payload":"payload","payloadType":"msg","transitionTime":"","x":850,"y":60,"wires":[]},{"id":"74c0806d.09185","type":"ui_switch","z":"5dc3e86c.3246a8","name":"Switch","label":"Schalter","tooltip":"","group":"db3115ee.3d0d58","order":1,"width":0,"height":0,"passthru":true,"decouple":"false","topic":"","style":"","onvalue":"true","onvalueType":"bool","onicon":"","oncolor":"","offvalue":"false","offvalueType":"bool","officon":"","offcolor":"","x":550,"y":60,"wires":[["6bc87841.1ee9e8"]]},{"id":"a80cd64d.069a48","type":"function","z":"5dc3e86c.3246a8","name":"Filter auf \"on\"","func":"var newMsg = { payload: msg.payload.on };\nreturn newMsg;","outputs":1,"noerr":0,"x":380,"y":60,"wires":[["74c0806d.09185"]]},{"id":"9bc1c7f8.4a45a8","type":"function","z":"5dc3e86c.3246a8","name":"Filter auf \"bri\"","func":"var newMsg = { payload: msg.payload.bri };\nreturn newMsg;","outputs":1,"noerr":0,"x":380,"y":120,"wires":[["1ec55ef6.2f5501"]]},{"id":"59ccb2f9.208b7c","type":"deconz-output","z":"5dc3e86c.3246a8","name":"RGB_stripe: Farbe","server":"d261a0f2.dd789","device":"58:8e:81:ff:fe:e2:d6:08-01","device_name":"LED_stripe : Extended color light","command":"xy","commandType":"deconz_cmd","payload":"payload.xy","payloadType":"msg","transitionTime":"","x":850,"y":180,"wires":[]},{"id":"114c0c60.c9d024","type":"ui_colour_picker","z":"5dc3e86c.3246a8","name":"","label":"","group":"db3115ee.3d0d58","format":"rgb","outformat":"object","showSwatch":true,"showPicker":false,"showValue":false,"showHue":false,"showAlpha":false,"showLightness":true,"square":"false","dynOutput":"false","order":0,"width":0,"height":0,"passthru":true,"topic":"","x":410,"y":180,"wires":[["dd7f5d72.a919f"]]},{"id":"dd7f5d72.a919f","type":"function","z":"5dc3e86c.3246a8","name":"RGB_CIE","func":"\nfunction rgb_to_cie(red, green, blue)\n{\n\t//Apply a gamma correction to the RGB values, which makes the color more vivid and more the like the color displayed on the screen of your device\n\tvar red \t= (red > 0.04045) ? Math.pow((red + 0.055) / (1.0 + 0.055), 2.4) : (red / 12.92);\n\tvar green \t= (green > 0.04045) ? Math.pow((green + 0.055) / (1.0 + 0.055), 2.4) : (green / 12.92);\n\tvar blue \t= (blue > 0.04045) ? Math.pow((blue + 0.055) / (1.0 + 0.055), 2.4) : (blue / 12.92); \n\n\t//RGB values to XYZ using the Wide RGB D65 conversion formula\n\tvar X \t\t= red * 0.664511 + green * 0.154324 + blue * 0.162028;\n\tvar Y \t\t= red * 0.283881 + green * 0.668433 + blue * 0.047685;\n\tvar Z \t\t= red * 0.000088 + green * 0.072310 + blue * 0.986039;\n\n\t//Calculate the xy values from the XYZ values\n\tvar x \t\t= (X / (X + Y + Z));\n\tvar y \t\t= (Y / (X + Y + Z));\n\n\tif (isNaN(x))\n\t\tx = 0;\n\tif (isNaN(y))\n\t\ty = 0;\t \n\treturn [x, y];\n}\n\nmsg.payload.xy = rgb_to_cie(msg.payload.r, msg.payload.g, msg.payload.b);\nconsole.log(msg.payload);\nreturn msg;\n\n\n","outputs":1,"noerr":0,"x":620,"y":180,"wires":[["b25e5efd.28759","59ccb2f9.208b7c"]]},{"id":"b25e5efd.28759","type":"debug","z":"5dc3e86c.3246a8","name":"Debug-output_RGB_CIE","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":870,"y":220,"wires":[]},{"id":"d261a0f2.dd789","type":"deconz-server","z":"","name":"Phoscon-GW","ip":"172.18.143.20","port":"80","apikey":"9EEA49359E","ws_port":"443","secure":false,"polling":"15"},{"id":"db3115ee.3d0d58","type":"ui_group","z":"","name":"Licht","tab":"d8bd116e.0c143","order":2,"disp":true,"width":"6","collapse":false},{"id":"d8bd116e.0c143","type":"ui_tab","z":"","name":"Home","icon":"dashboard","disabled":false,"hidden":false}]

I've still issues with the RGB color in Node Red. I already attached the payload generated by Nodered and by FHEM in a post before. FHEM can set the color, node red not.

I furthermore would like to attach the payload of the color temperature switch from Node red which works fine. This is from an output device from the deconz module
ct

I thought I need to reconstruct the complete payload but this also seems not to work. Maybe it is due to the r g b a values...

This is the output of FHEM when switching a color:

2020-12-20 14:28:29 HUEDevice HUEDevice2 xy: 0.7291,0.2783
2020-12-20 14:28:29 HUEDevice HUEDevice2 rgb: ed0000

FHEM seems to just send the xy values if the log gives me the full picture.

Any further ideas?

It works. For whatever reason it didn't work before the solution is attached:

[{"id":"59ccb2f9.208b7c","type":"deconz-output","z":"5dc3e86c.3246a8","name":"RGB_stripe: Farbe","server":"d261a0f2.dd789","device":"58:8e:81:ff:fe:e2:d6:08-01","device_name":"LED_stripe : Extended color light","command":"xy","commandType":"deconz_cmd","payload":"payload","payloadType":"msg","transitionTime":"","x":850,"y":240,"wires":[]},{"id":"114c0c60.c9d024","type":"ui_colour_picker","z":"5dc3e86c.3246a8","name":"","label":"RGB","group":"db3115ee.3d0d58","format":"rgb","outformat":"object","showSwatch":true,"showPicker":false,"showValue":false,"showHue":false,"showAlpha":false,"showLightness":true,"square":"false","dynOutput":"false","order":4,"width":0,"height":0,"passthru":true,"topic":"","x":450,"y":240,"wires":[["dd7f5d72.a919f"]]},{"id":"dd7f5d72.a919f","type":"function","z":"5dc3e86c.3246a8","name":"RGB_CIE","func":"\nfunction rgb_to_cie(red, green, blue)\n{\n\t//Apply a gamma correction to the RGB values, which makes the color more vivid and more the like the color displayed on the screen of your device\n\tvar red \t= (red > 0.04045) ? Math.pow((red + 0.055) / (1.0 + 0.055), 2.4) : (red / 12.92);\n\tvar green \t= (green > 0.04045) ? Math.pow((green + 0.055) / (1.0 + 0.055), 2.4) : (green / 12.92);\n\tvar blue \t= (blue > 0.04045) ? Math.pow((blue + 0.055) / (1.0 + 0.055), 2.4) : (blue / 12.92); \n\n\t//RGB values to XYZ using the Wide RGB D65 conversion formula\n\tvar X \t\t= red * 0.664511 + green * 0.154324 + blue * 0.162028;\n\tvar Y \t\t= red * 0.283881 + green * 0.668433 + blue * 0.047685;\n\tvar Z \t\t= red * 0.000088 + green * 0.072310 + blue * 0.986039;\n\n\t//Calculate the xy values from the XYZ values\n\tvar x \t\t= (X / (X + Y + Z));\n\tvar y \t\t= (Y / (X + Y + Z));\n\n\tif (isNaN(x))\n\t\tx = 0;\n\tif (isNaN(y))\n\t\ty = 0;\t \n\treturn [x, y];\n}\nmsg.payload = rgb_to_cie(msg.payload.r, msg.payload.g, msg.payload.b);\nconsole.log(msg.payload);\nreturn msg;\n\n\n","outputs":1,"noerr":0,"x":620,"y":240,"wires":[["b25e5efd.28759","59ccb2f9.208b7c"]]},{"id":"b25e5efd.28759","type":"debug","z":"5dc3e86c.3246a8","name":"Debug-output_RGB_CIE","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":870,"y":300,"wires":[]},{"id":"d261a0f2.dd789","type":"deconz-server","z":"","name":"Phoscon-GW","ip":"172.18.143.20","port":"80","apikey":"9EEA49359E","ws_port":"443","secure":false,"polling":"15"},{"id":"db3115ee.3d0d58","type":"ui_group","z":"","name":"LED Stripe","tab":"d8bd116e.0c143","order":2,"disp":true,"width":"6","collapse":false},{"id":"d8bd116e.0c143","type":"ui_tab","z":"","name":"Home","icon":"dashboard","disabled":false,"hidden":false}]

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