Rainbow Effect directly in Node-RED for RGB Spots

Hey guys,

I have a new setup in my flat with some Hue RGB SpotLights connected with a conbee stick/bridge.
Everything works great, I can set the colors with the Colorpicker and the brightness and so on.

I don't have any Idea how to realise a smooth fading rainbow effect on these lights if I choose such an effect in a dropdownlist on the dashboard.
Every function node is sending one msg and will stop after "return msg".
F.e.

If I code my Rainbow with a "for loop" and in this "for loop" I have one "return msg;" it will stop the for loop :confused:
So how is the best way to get a solution for this? Delaynode after function node that is connected to the Input of the function node?

Thank you all in advance.

Please look it up in the documentation.
You can use node.send in a loop.

1 Like

mhhh @bakman2 looking around the docu but can't find anything that belongs to node.send.

EDIT: ok got it... last post I clicked on I found it => for everyone else that is looking for it as well => https://nodered.org/docs/user-guide/writing-functions

Mhhh, tryed it with the node.send but node-red seems to freeze realy often and now I did it this way:

the button is for turning on / off the Rainbow Effect and the 1st function node looks like this:


if (rainbow) {
    flow.set('rainbowOn', false);
    msg.effect = "Start Rainbow";
} else {
    flow.set('rainbowOn', true);
    flow.set('inta', 0);
    msg.effect = "Stop Rainbow";
}
return msg;

and the 2nd function node like this:

var rainbow = flow.get('rainbowOn');
var inta = flow.get('inta');

if (rainbow) {
    inta++;
    if (inta >= 361) {
        inta = 0;
    }
    flow.set('inta', inta);
    return {
        hue: Math.floor(inta/360*65536)
    };
}

the limiter is for a smooth transition.

but node-red seems to freeze realy often

Ofcourse: you are creating loops.
The hue api has an option for an effect which could be a rainbow as well.

found this: http://rsmck.co.uk/hue

colorloop as effect <3