Hello,
my kitchen ceiling has a grid of spot lights, so I thought I would animate the turn on to add a little variety. I’ll probably create a few different animations and then script how / when they are triggered.
My first animation was simply to have each light come on in sequence - so I wired a node-red flow with the nodes position matching the physical layout:
This works well enough, but I thought I’d see if I could learn a bit about looping in NR.
I came up with this:
[{"id":"2f94c78c1d6e33db","type":"ha-get-entities","z":"a5b3949bf2d9cf01","name":"","server":"2be748d3.da7088","version":0,"rules":[{"property":"entity_id","logic":"starts_with","value":"light.kitchen_spot","valueType":"str"}],"output_type":"array","output_empty_results":false,"output_location_type":"msg","output_location":"payload","output_results_count":1,"x":290,"y":2360,"wires":[["ff72949c1a400ba5","4c995df7153949aa"]]},{"id":"7530c4d096b88b5a","type":"inject","z":"a5b3949bf2d9cf01","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":100,"y":2360,"wires":[["2f94c78c1d6e33db"]]},{"id":"ff72949c1a400ba5","type":"debug","z":"a5b3949bf2d9cf01","name":"list","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":310,"y":2420,"wires":[]},{"id":"4c995df7153949aa","type":"sort","z":"a5b3949bf2d9cf01","name":"","order":"ascending","as_num":false,"target":"payload","targetType":"msg","msgKey":"entity_id","msgKeyType":"jsonata","seqKey":"payload","seqKeyType":"msg","x":450,"y":2360,"wires":[["c674cb3eccb82eac","37b7c27eaa5551f9"]]},{"id":"c674cb3eccb82eac","type":"debug","z":"a5b3949bf2d9cf01","name":"sort","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":450,"y":2420,"wires":[]},{"id":"37b7c27eaa5551f9","type":"split","z":"a5b3949bf2d9cf01","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"key","x":590,"y":2360,"wires":[["b8850625f3983f8e","1b651e15b12b4284"]]},{"id":"1b651e15b12b4284","type":"delay","z":"a5b3949bf2d9cf01","name":"","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"3","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":760,"y":2360,"wires":[["cdc2d1c556a7be79"]]},{"id":"b8850625f3983f8e","type":"debug","z":"a5b3949bf2d9cf01","name":"each","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":590,"y":2420,"wires":[]},{"id":"392a09970b256c96","type":"debug","z":"a5b3949bf2d9cf01","name":"debug 172","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":930,"y":2420,"wires":[]},{"id":"cdc2d1c556a7be79","type":"api-call-service","z":"a5b3949bf2d9cf01","name":"","server":"2be748d3.da7088","version":5,"debugenabled":false,"domain":"light","service":"turn_on","areaId":[],"deviceId":[],"entityId":["{{payload.entity_id}}"],"data":"{ \"transition\": 2}","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":930,"y":2360,"wires":[["392a09970b256c96"]]},{"id":"2be748d3.da7088","type":"server","name":"Home Assistant","addon":true}]
I found that the get entities node would not retrieve the nodes in any particular order, so I added a sort node, then a split node to trigger each light individually.
Before I used a delay node before the light.turn on, but I found all the nodes delays and turn-ons were executed in parallel. A bit more digging and I got it to work using the limit node.
To animate this in a more interesting way I would like send a series of light.turn on commands at specified times. Each command could have different parameters (fade-in time, colour, brightness). Potentially calling the same lights multiple times or multiple lights in parallel.
Do you have an advice / suggestions on how to approach this - I was thinking to start with a HA helper containing the entities and states?
Steve