I am fairly new to node-red and JavaScript and I am trying to write a function to generate a smooth rainbow effect across a row of 6 RGB lights. The idea is to have the rainbow run dusk to dawn. The lights I am trying to trigger are DMX landscape lights that are set up in HA via the Home Assistant DMX over IP Light Platform (Art-Net) integration.
Here’s what I’ve got so far:
[{"id":"6fced553.1b116c","type":"function","z":"8a65e184.b6b8a","name":"Rainbow Effect","func":"var numberOfLEDs = 6;\n\nfor(i=0; i<255; i++){\n \n for(j=0; j<numberOfLEDs; j++){\n \n var pos = 0;\n pos = Math.round(((j*255/numberOfLEDs)+i))&255;\n \n if(pos<85){\n var red = pos*3;\n var green = 255-pos*3;\n var blue = 0;\n }\n else if(pos < 170){\n pos -= 85;\n var red = 255 - pos*3;\n var green = 0;\n var blue = pos*3;\n }\n else{\n pos -= 170;\n var red = 0;\n var green = pos*3;\n var blue = 255-pos*3;\n }\n \n var rgb_color = red +','+ green +','+ blue;\n var entity_id = 'light.pridegroup'+ j;\n \n node.send({payload:'{\"entity_id\": \"' + entity_id + '\", \"rgb_color\": \"' + rgb_color +'\"}'});\n }\n}","outputs":1,"noerr":0,"x":480,"y":260,"wires":[["72d96033.8598d"]]}]
Rainbow function credit: https://randomnerdtutorials.com/node-red-with-ws2812b-addressable-rgb-led-strip/
I seem to be having issues passing the correct payload to the service call. I would love some help getting this over the finish line. Thanks!