Firstly I have done a bunch of searching without coming up with a solution.
Using Node-RED, I would like to change the colour of a RGB lamp, based on a changing variable from a illumination sensor. The sensor outputs on a scale of 0-1000 lux. I would like the lamp to change from red, through orange, yellow, etc to blue as the brightness increases.
I have written some script for a Function Node that I believe will suit my needs:
//An alternative that uses hr_color //variable 'aa' has a range of 0-1000 //the hue colour wheel is 360, but the red to blue spectrum //covers 0-250 //See: https://www.w3schools.com/colors/colors_hsl.asp //Gather variables var aa = parseFloat(msg.payload); let hr_color = aa/4; //gives a number between 0-250 //with low illum indicated by red, high by blue, as above msg.payload = hr_color; return msg;
The msg.payload will be a number between zero and 250, which I hope to pass to the RGB lamp as the Hue part of an ‘hr_color’ command.
I have searched for a method to do this extensively, including nodes that accept Mustache Templates, with no luck.
I have succeeded with a granular (5 step) flow using a Switch node and Call Service nodes, but I hope to get greater colour resolution.
Any advice would be appreciated