# Rainbow Effect directly in Node-RED for RGB Spots

**URL:** <https://discourse.nodered.org/t/rainbow-effect-directly-in-node-red-for-rgb-spots/18501>\
**Category:** General\
**Created:** [27 November 2019 08:47 UTC](https://discourse.nodered.org/t/rainbow-effect-directly-in-node-red-for-rgb-spots/18501 "2019-11-27T08:47:06Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![nicedevil](https://avatars.discourse-cdn.com/v4/letter/n/858c86/32.png) [@nicedevil](https://discourse.nodered.org/u/nicedevil)\
**Post date:** [27 November 2019 08:47 UTC](https://discourse.nodered.org/t/rainbow-effect-directly-in-node-red-for-rgb-spots/18501/1 "2019-11-27T08:47:06Z")

</div>

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 😕  
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.

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [27 November 2019 09:20 UTC](https://discourse.nodered.org/t/rainbow-effect-directly-in-node-red-for-rgb-spots/18501/2 "2019-11-27T09:20:48Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![nicedevil](https://avatars.discourse-cdn.com/v4/letter/n/858c86/32.png) [@nicedevil](https://discourse.nodered.org/u/nicedevil)\
**Post date:** [27 November 2019 12:06 UTC](https://discourse.nodered.org/t/rainbow-effect-directly-in-node-red-for-rgb-spots/18501/3 "2019-11-27T12:06:30Z")

</div>

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](https://nodered.org/docs/user-guide/writing-functions)

---

<div class="post-metadata">

**Author:** ![nicedevil](https://avatars.discourse-cdn.com/v4/letter/n/858c86/32.png) [@nicedevil](https://discourse.nodered.org/u/nicedevil)\
**Post date:** [27 November 2019 14:42 UTC](https://discourse.nodered.org/t/rainbow-effect-directly-in-node-red-for-rgb-spots/18501/4 "2019-11-27T14:42:49Z")

</div>

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

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/7/709f74ad4eb1f71727a8869d5fefcd0cbc49b355.png)

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

```auto

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:

```auto
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.

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [27 November 2019 15:38 UTC](https://discourse.nodered.org/t/rainbow-effect-directly-in-node-red-for-rgb-spots/18501/5 "2019-11-27T15:38:28Z")

</div>

> 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.

---

<div class="post-metadata">

**Author:** ![nicedevil](https://avatars.discourse-cdn.com/v4/letter/n/858c86/32.png) [@nicedevil](https://discourse.nodered.org/u/nicedevil)\
**Post date:** [27 November 2019 18:47 UTC](https://discourse.nodered.org/t/rainbow-effect-directly-in-node-red-for-rgb-spots/18501/6 "2019-11-27T18:47:01Z")

</div>

found this: [http://rsmck.co.uk/hue](http://rsmck.co.uk/hue)

colorloop as effect \<3
