RBG LED Strip Color Flow

Hi,

I found this color loop script on reddit. This script works for controlling rgb led strips in node red. But how can I make colors fade rather than hard change.

[{"id":"c41004d0.f859c8","type":"tab","label":"Flow 2","disabled":false,"info":""},{"id":"ca2fdb94.80fa68","type":"template","z":"c41004d0.f859c8","name":"admin","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{ \"data\": {\"entity_id\" : \"light.living_room_leds\", \"rgb_color\" : {{payload.data.rgb_color}} }}","output":"str","x":550,"y":160,"wires":[["641593c4.0e8a6c"]],"icon":"node-red-contrib-color-convert/color-convert.png"},{"id":"4b8418dd.8231b8","type":"function","z":"c41004d0.f859c8","name":"change rgb","func":"var i = flow.get(\"i\");\nvar red   = Math.round(Math.sin(0.3*i + 0) * 127 + 128);\nvar green = Math.round(Math.sin(0.3*i + 2) * 127 + 128);\nvar blue  = Math.round(Math.sin(0.3*i + 4) * 127 + 128);\n\ni++;\nif (i>=32) {\n    i = 0;\n}\n\nflow.set(\"i\", i);\n\nmsg.payload = {};\nmsg.payload.data = {};\nmsg.payload.data.rgb_color = \"[\" + red + \", \" + green + \", \" + blue + \"]\";\n\nreturn msg;","outputs":1,"noerr":0,"x":390,"y":160,"wires":[["ca2fdb94.80fa68","d9de34be.d7ff48"]]},{"id":"5c72b59a.a9203c","type":"function","z":"c41004d0.f859c8","name":"set var","func":"flow.set(\"i\", 0);\n\nreturn msg;","outputs":1,"noerr":0,"x":230,"y":160,"wires":[["4b8418dd.8231b8"]]},{"id":"d9de34be.d7ff48","type":"delay","z":"c41004d0.f859c8","name":"","pauseType":"delay","timeout":"2","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":400,"y":240,"wires":[["4b8418dd.8231b8"]]},{"id":"641593c4.0e8a6c","type":"api-call-service","z":"c41004d0.f859c8","name":"Cycle","server":"cc5f2328.3e1bd","version":1,"debugenabled":false,"service_domain":"homeassistant","service":"turn_on","entityId":"","data":"{}","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":694,"y":161,"wires":[["4263ce66.9afa4"]]},{"id":"4263ce66.9afa4","type":"debug","z":"c41004d0.f859c8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":580,"y":340,"wires":[]},{"id":"8c9169d.160a298","type":"inject","z":"c41004d0.f859c8","name":"","props":[{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":80,"y":100,"wires":[["5c72b59a.a9203c"]]},{"id":"ca2a3edd.cba26","type":"comment","z":"c41004d0.f859c8","name":"Rainbow","info":"","x":340,"y":40,"wires":[]},{"id":"cc5f2328.3e1bd","type":"server","name":"Home Assistant","legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]

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