Exploring Rainbow Lighting Automation with Node-RED

Hey everyone! I’m really excited to share my recent project where I set up a smooth rainbow effect for my RGB lights using Node-RED and JavaScript. It’s been a fun challenge, and I’d love to hear your thoughts or tips on improving it further!

So, here’s the backstory: I’ve been wanting to create a dynamic lighting setup that cycles through colors smoothly, especially during the evenings. After some research, I came across a Node-RED function that generates a rainbow effect. The idea was to have this effect run from dusk to dawn, adding a nice touch to my home’s ambiance.

The setup involved my DMX landscape lights integrated into Home Assistant via the Art-Net platform. I’ve got six RGB lights in a row, and the goal was to have the rainbow effect transition smoothly across all of them. Here’s a quick look at the flow I created:

javascript
var numberOfLEDs = 6;

for(i=0; i<255; i++){
for(j=0; j<numberOfLEDs; j++){
var pos = 0;
pos = Math.round(((j*255/numberOfLEDs)+i))&255;

if(pos<85){
  var red = pos*3;
  var green = 255-pos*3;
  var blue = 0;
}
else if(pos < 170){
  pos -= 85;
  var red = 255 - pos*3;
  var green = 0;
  var blue = pos*3;
}
else{
  pos -= 170;
  var red = 0;
  var green = pos*3;
  var blue = 255-pos*3;
}

var rgb_color = red +','+ green +','+ blue;
var entity_id = 'light.pridegroup'+ j;

node.send({payload:'{"entity_id": "' + entity_id + '", "rgb_color": "' + rgb_color +'"}'});

}
}

At first, I faced some issues with the payload not being recognized correctly by Home Assistant. After some troubleshooting and adjusting the payload format, everything started working smoothly. Now, the rainbow effect transitions beautifully across all six lights, creating a mesmerizing display!

I’d love to hear if anyone else has experimented with similar setups or has suggestions for enhancing the effect. Maybe adding a sunrise/sunset automation or adjusting the speed dynamically based on time? Let me know your thoughts!

Cheers and happy tinkering! :rainbow::sparkles: