Christmas lights with Node-RED

Hi everyone, I’ve been thinking of a way to make my ceiling lights act a bit like Christmas lights and I’ve created a flow to achieve this.

The flow randomises things in three ways. It first randomises which light to receive a new colour. Next, it randomises which colour (out of a set) that will be applied. Finally, it randomises a delay so the lights don’t all change at regular intervals.

Hopefully it can be tweaked for your own setup. I’ve written short descriptions of each node to better explain what they do.

[{"id":"4c54347b.384bbc","type":"tab","label":"Christmas lights","disabled":false,"info":""},{"id":"8b8a0159.196e38","type":"random","z":"4c54347b.384bbc","name":"Light selector","low":"1","high":"8","inte":"true","property":"entity","x":500,"y":160,"wires":[["c44640ac.17414"]],"info":"I have 8 lights to choose from. This chooses a number between 1 and 8, for the msg.entity property."},{"id":"c44640ac.17414","type":"change","z":"4c54347b.384bbc","name":"Convert to entity","rules":[{"t":"change","p":"entity","pt":"msg","from":"1","fromt":"num","to":"light.front_entry","tot":"str"},{"t":"change","p":"entity","pt":"msg","from":"2","fromt":"num","to":"light.lounge_east","tot":"str"},{"t":"change","p":"entity","pt":"msg","from":"3","fromt":"num","to":"light.lounge_west","tot":"str"},{"t":"change","p":"entity","pt":"msg","from":"4","fromt":"num","to":"light.kitchen_east","tot":"str"},{"t":"change","p":"entity","pt":"msg","from":"5","fromt":"num","to":"light.kitchen_west","tot":"str"},{"t":"change","p":"entity","pt":"msg","from":"6","fromt":"num","to":"light.dining_east","tot":"str"},{"t":"change","p":"entity","pt":"msg","from":"7","fromt":"num","to":"light.dining_west","tot":"str"},{"t":"change","p":"entity","pt":"msg","from":"8","fromt":"num","to":"light.bottom_passage","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":730,"y":160,"wires":[["bf3a9c58.919d88"]],"info":"Now let's convert that random number to an entity. Note the data types (integer first, string second)"},{"id":"88570e31.9a3c78","type":"api-call-service","z":"4c54347b.384bbc","name":"Execute","server":"6f063223.2751ac","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"","data":"{\t   \"entity_id\": msg.entity,\t   \"color_name\": msg.color,\t   \"transition\": 4,\t   \"brightness\": 110\t}","dataType":"jsonata","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":true,"x":720,"y":380,"wires":[[]],"info":"This one brings together the light and color to change the particular light. Note that I've used JSONata for this, as it seems to behave better than JSON."},{"id":"436a40f6.53d56","type":"change","z":"4c54347b.384bbc","name":"Convert to color","rules":[{"t":"change","p":"color","pt":"msg","from":"1","fromt":"num","to":"red","tot":"str"},{"t":"change","p":"color","pt":"msg","from":"2","fromt":"num","to":"green","tot":"str"},{"t":"change","p":"color","pt":"msg","from":"3","fromt":"num","to":"aqua","tot":"str"},{"t":"change","p":"color","pt":"msg","from":"4","fromt":"num","to":"orange","tot":"str"},{"t":"change","p":"color","pt":"msg","from":"5","fromt":"num","to":"purple","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":720,"y":240,"wires":[["45d25dcd.f53954"]],"info":"Converting the random number to a color name. I think these colors are christmassy, but your tastes may vary."},{"id":"bf3a9c58.919d88","type":"random","z":"4c54347b.384bbc","name":"Color selector","low":"1","high":"5","inte":"true","property":"color","x":500,"y":240,"wires":[["436a40f6.53d56"]],"info":"Now let's pick the colors. I have 5 colors to pick from, so again this will pick a random color to use."},{"id":"45d25dcd.f53954","type":"random","z":"4c54347b.384bbc","name":"Delay selector","low":"1","high":"4","inte":"true","property":"delay","x":500,"y":320,"wires":[["fc07938b.83b58"]],"info":"To make the lights change a bit more randomly, a random delay is introduced. I have four delays to pick from."},{"id":"fc07938b.83b58","type":"change","z":"4c54347b.384bbc","name":"Convert to timer delay","rules":[{"t":"change","p":"delay","pt":"msg","from":"1","fromt":"num","to":"500","tot":"num"},{"t":"change","p":"delay","pt":"msg","from":"2","fromt":"num","to":"1000","tot":"num"},{"t":"change","p":"delay","pt":"msg","from":"3","fromt":"num","to":"2000","tot":"num"},{"t":"change","p":"delay","pt":"msg","from":"4","fromt":"str","to":"3000","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":740,"y":320,"wires":[["cde7cd48.655b48","26b0c3d6.4eca8c"]],"info":"Converting the selection to a delay in milliseconds (it must be in milliseconds)"},{"id":"cde7cd48.655b48","type":"delay","z":"4c54347b.384bbc","name":"","pauseType":"delay","timeout":"2","timeoutUnits":"seconds","rate":"2","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":480,"y":100,"wires":[["429041.9b3027c"]],"info":"Start everything again, but delay a couple of seconds so as to not flood the flow."},{"id":"26b0c3d6.4eca8c","type":"delay","z":"4c54347b.384bbc","name":"Set delay","pauseType":"delayv","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":480,"y":380,"wires":[["88570e31.9a3c78"]],"info":"Delay per the time provided in msg.delay"},{"id":"901355de.aa887","type":"server-state-changed","z":"4c54347b.384bbc","name":"Switch toggled","server":"6f063223.2751ac","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"input_boolean.christmas_lighting","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"on","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"x":100,"y":160,"wires":[["f4ad9349.3994f"],["3f934c1c.b46264"]],"info":"This flow begins with an input_boolean that is used to toggle it on or off."},{"id":"429041.9b3027c","type":"api-current-state","z":"4c54347b.384bbc","name":"Check switch status","server":"6f063223.2751ac","version":1,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"input_boolean.christmas_lighting","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":740,"y":100,"wires":[["8b8a0159.196e38"],[]],"info":"If the input_boolean is still turned on, start it again"},{"id":"f4ad9349.3994f","type":"api-call-service","z":"4c54347b.384bbc","name":"Turn off Flux","server":"6f063223.2751ac","version":1,"debugenabled":false,"service_domain":"switch","service":"turn_off","entityId":"switch.flux_bottom_floor","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":290,"y":160,"wires":[["8b8a0159.196e38"]],"info":"I use the Flux components for my lights. Obviously this needs to turn off before I can continue."},{"id":"3f934c1c.b46264","type":"api-call-service","z":"4c54347b.384bbc","name":"Turn on Flux","server":"6f063223.2751ac","version":1,"debugenabled":false,"service_domain":"switch","service":"turn_on","entityId":"switch.flux_bottom_floor","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":290,"y":220,"wires":[[]],"info":"Flux will turn back on after the switch has been turned off."},{"id":"6f063223.2751ac","type":"server","name":"Home Assistant"}]
3 Likes

In case anyone else wants to use this, you’ll need the random palette installed.