# How to create a color gradient for RGB bulbs

**URL:** <https://discourse.nodered.org/t/how-to-create-a-color-gradient-for-rgb-bulbs/35561>\
**Category:** General\
**Created:** [8 November 2020 19:37 UTC](https://discourse.nodered.org/t/how-to-create-a-color-gradient-for-rgb-bulbs/35561 "2020-11-08T19:37:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ToonMeynen](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/toonmeynen/32/31635_2.png) [@ToonMeynen](https://discourse.nodered.org/u/ToonMeynen)\
**Post date:** [8 November 2020 19:37 UTC](https://discourse.nodered.org/t/how-to-create-a-color-gradient-for-rgb-bulbs/35561/1 "2020-11-08T19:37:23Z")

</div>

Hi,

I'm looking for a method to go from one hex color to another in a gradient.  
I found this wonderful website which gives me an array of hex codes. That all together create a gradient from one color to the other. The end goal is to send this to my RGB bulbs.  
Is there a node that just does this? Or do I need to program this somehow in a function node ?

> **[RGB #E56800 | RGB Chart & Multi Tool](http://www.perbang.dk/rgb/FAF9F5/)**

  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/b/1ba6cc17d9e207c84d610c5a7e82c5eeb5e67199.png)

---

<div class="post-metadata">

**Author:** ![ToonMeynen](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/toonmeynen/32/31635_2.png) [@ToonMeynen](https://discourse.nodered.org/u/ToonMeynen)\
**Post date:** [9 November 2020 20:12 UTC](https://discourse.nodered.org/t/how-to-create-a-color-gradient-for-rgb-bulbs/35561/2 "2020-11-09T20:12:26Z")

</div>

I'm going to replay on my own question because I pulled something very basic together. Still wondering if there is a better way to accomplish this.

```auto
[{"id":"74bf0bd5.d64774","type":"tab","label":"Color Gradient (development)","disabled":false,"info":""},{"id":"7cf5bfb4.18927","type":"function","z":"74bf0bd5.d64774","name":"select hex","func":"//color array\nvar gradient = ['FFF9E5', 'FFF4CC', 'FFEFB2','FFEA99', 'FFE47F','FFDF66','FFDA4C','FFDA4C','FFDA4C','FFD533','FFCF19','FFCA00'];\nvar max_index = 11;\n//counter\nvar count = context.get('count')||0;\nif (count == max_index){\n count = 0;\n}else{\n count += 1; \n}\n// store the value back\ncontext.set('count',count);\n//output and store hex value\nvar hex = gradient[count];\ncontext.set(\"hue\", \"#\"+hex);\nmsg.payload = {\"color\": {\"hex\":\"#\"+hex},\"transition\": 1};\nreturn msg;\n\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":620,"y":300,"wires":[["d80870e4.736ed"]]},{"id":"da902d7e.b5479","type":"inject","z":"74bf0bd5.d64774","name":"","props":[{"p":"payload"}],"repeat":"1","crontab":"","once":false,"onceDelay":"3","topic":"","payload":"","payloadType":"date","x":190,"y":300,"wires":[["7cf5bfb4.18927"]]},{"id":"d80870e4.736ed","type":"mqtt out","z":"74bf0bd5.d64774","name":"","topic":"zigbee2mqtt/ikea_rbg_1/set","qos":"","retain":"","broker":"6fb7644f.31a0bc","x":1040,"y":300,"wires":[]},{"id":"6fb7644f.31a0bc","type":"mqtt-broker","name":"","broker":"mosquitto","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"zigbee2mqtt/bridge/log","birthQos":"0","birthPayload":"zigbee2mqtt","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]

```

---

<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:** [8 January 2021 20:12 UTC](https://discourse.nodered.org/t/how-to-create-a-color-gradient-for-rgb-bulbs/35561/3 "2021-01-08T20:12:43Z")

</div>

Closed on 8 January 2021 20:12 UTC

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