# Button Press Next Color

**URL:** <https://discourse.nodered.org/t/button-press-next-color/30674>\
**Category:** Developing Nodes\
**Created:** [24 July 2020 23:46 UTC](https://discourse.nodered.org/t/button-press-next-color/30674 "2020-07-24T23:46:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lethal83](https://avatars.discourse-cdn.com/v4/letter/l/aca169/32.png) [@Lethal83](https://discourse.nodered.org/u/Lethal83)\
**Post date:** [24 July 2020 23:46 UTC](https://discourse.nodered.org/t/button-press-next-color/30674/1 "2020-07-24T23:46:09Z")

</div>

Hi All  
New to Node Red but enjoying it as I'm starting to get my head around it.

I have the 5 button Ikea Tradfi remote that the kids use in their room with a Tasmota flash RGBW globe. Im also using Home assistant.

I need one of the buttons on the remote to cycle through a set of colors like a "next color" type button. So Start on red, then button press to change to next color of blue, button press changes to next color yellow......

Looking in HA I can see a parameter called color\_name. How do I create like a list of colors in Nodered to cycle through?

Thanks in advance

---

<div class="post-metadata">

**Author:** ![ristomatti](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ristomatti/32/5857_2.png) [@ristomatti](https://discourse.nodered.org/u/ristomatti)\
**Post date:** [25 July 2020 19:40 UTC](https://discourse.nodered.org/t/button-press-next-color/30674/2 "2020-07-25T19:40:59Z")

</div>

Hi and welcome to the forum! Are you familiar with JavaScript? I would create an array of the colors and then use node context in a function node to store the previous array index. Every time a `msg` arrives at function node I'd increment the array index by one and using it pick a color from the array. With an added `if` condition I would reset the counter to 0 when it goes higher than the size of the array.

See [https://nodered.org/docs/user-guide/context](https://nodered.org/docs/user-guide/context) for more info on using the context.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [23 September 2020 19:40 UTC](https://discourse.nodered.org/t/button-press-next-color/30674/3 "2020-09-23T19:40:59Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
