Here’s an updated flow I created to be able to test this with Hue lights.
[{"id":"cb40f23231a4d26e","type":"function","z":"b84e61f8ff473dab","name":"List","func":"if (msg.devices) {\n var devices = msg.devices.split(\",\");\n if (devices.length > 0) {\n var firstDevice = devices.shift();\n var remainingDevices = devices.join(\",\");\n var newMsg = { device: firstDevice, devices: remainingDevices };\n newMsg.data = msg.data;\n newMsg.topic = msg.topic;\n newMsg.target = msg.target;\n node.send(newMsg);\n } else {\n node.warn(\"The input msg.devices is empty\");\n }\n} else {\n node.warn(\"The input msg.devices is missing\");\n}\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":330,"y":2400,"wires":[["4aa3c040b63441bb","088803648811567d"]]},{"id":"b9a400c262c7dcaa","type":"change","z":"b84e61f8ff473dab","name":"","rules":[{"t":"set","p":"reset","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":760,"y":2400,"wires":[["af69145241bd9b87"]]},{"id":"72bdc96fe937acf6","type":"debug","z":"b84e61f8ff473dab","name":"waituntil_separate_ok","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1000,"y":2700,"wires":[]},{"id":"4aa3c040b63441bb","type":"switch","z":"b84e61f8ff473dab","name":"end?","property":"device","propertyType":"msg","rules":[{"t":"eq","v":"end","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":510,"y":2440,"wires":[["b9a400c262c7dcaa"],["bc8cdefb63574206","87af21aba4d6c287","74b511448e29fbaa"]]},{"id":"87af21aba4d6c287","type":"ha-wait-until","z":"b84e61f8ff473dab","d":true,"name":"1) ENABLE EITHER THIS","server":"8a86b0cc.b2bac","version":3,"outputs":2,"entities":{"entity":["{{device}}"],"substring":[],"regex":[]},"property":"data.new_state.last_updated","comparator":"is_not","value":"0","valueType":"str","timeout":"23","timeoutType":"num","timeoutUnits":"seconds","checkCurrentState":false,"blockInputOverrides":true,"outputProperties":[],"entityLocation":"data","entityLocationType":"none","x":690,"y":2520,"wires":[["0d7fc763889fcaba","62cdb4c707691ef7"],["0d7fc763889fcaba","8082d66bdcc10ebf"]]},{"id":"bc8cdefb63574206","type":"debug","z":"b84e61f8ff473dab","name":"next device","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"device","targetType":"msg","statusVal":"","statusType":"auto","x":750,"y":2440,"wires":[]},{"id":"088803648811567d","type":"debug","z":"b84e61f8ff473dab","name":"debug devicelist","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"devices","targetType":"msg","statusVal":"","statusType":"auto","x":540,"y":2360,"wires":[]},{"id":"6a8df29af0d3f859","type":"ha-wait-until","z":"b84e61f8ff473dab","name":"Light 1","server":"8a86b0cc.b2bac","version":3,"outputs":2,"entities":{"entity":["light.tv_light_hue"],"substring":[],"regex":[]},"property":"data.event.new_state.last_updated","comparator":"is_not","value":"0","valueType":"str","timeout":"23","timeoutType":"num","timeoutUnits":"seconds","checkCurrentState":false,"blockInputOverrides":true,"outputProperties":[],"entityLocation":"data","entityLocationType":"none","x":710,"y":2640,"wires":[["0d7fc763889fcaba","72bdc96fe937acf6"],["5943f872251b4383"]]},{"id":"74b511448e29fbaa","type":"switch","z":"b84e61f8ff473dab","name":"2) OR THIS","property":"device","propertyType":"msg","rules":[{"t":"eq","v":"light.tv_light_hue","vt":"str"},{"t":"eq","v":"light.door_bulb_hue","vt":"str"},{"t":"eq","v":"light.globe_light_hue","vt":"str"}],"checkall":"true","repair":false,"outputs":3,"x":490,"y":2640,"wires":[["6a8df29af0d3f859"],["b30a045490d44ca2"],["613e6e535283cc93"]]},{"id":"b30a045490d44ca2","type":"ha-wait-until","z":"b84e61f8ff473dab","name":"Light 2","server":"8a86b0cc.b2bac","version":3,"outputs":2,"entities":{"entity":["light.door_bulb_hue"],"substring":[],"regex":[]},"property":"data.event.new_state.last_updated","comparator":"is_not","value":"0","valueType":"str","timeout":"23","timeoutType":"num","timeoutUnits":"seconds","checkCurrentState":false,"blockInputOverrides":true,"outputProperties":[],"entityLocation":"data","entityLocationType":"none","x":710,"y":2680,"wires":[["0d7fc763889fcaba","72bdc96fe937acf6"],["5943f872251b4383"]]},{"id":"613e6e535283cc93","type":"ha-wait-until","z":"b84e61f8ff473dab","name":"Light 3","server":"8a86b0cc.b2bac","version":3,"outputs":2,"entities":{"entity":["light.globe_light_hue"],"substring":[],"regex":[]},"property":"data.event.new_state.last_updated","comparator":"is_not","value":"0","valueType":"str","timeout":"23","timeoutType":"num","timeoutUnits":"seconds","checkCurrentState":false,"blockInputOverrides":true,"outputProperties":[],"entityLocation":"data","entityLocationType":"none","x":710,"y":2720,"wires":[["0d7fc763889fcaba","72bdc96fe937acf6"],["5943f872251b4383"]]},{"id":"5943f872251b4383","type":"debug","z":"b84e61f8ff473dab","name":"waituntil_separate_timeout","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1020,"y":2740,"wires":[]},{"id":"dc0cdc9fe14ea8e1","type":"inject","z":"b84e61f8ff473dab","name":"Device List 1","props":[{"p":"devices","v":"light.tv_light_hue,light.door_bulb_hue,light.globe_light_hue,end","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":130,"y":2460,"wires":[["cb40f23231a4d26e"]]},{"id":"98e92fce6d295276","type":"link in","z":"b84e61f8ff473dab","name":"NEXT","links":["0d7fc763889fcaba","d15e1afd77fc168c","202951defb7e5f21"],"x":150,"y":2400,"wires":[["cb40f23231a4d26e"]],"l":true},{"id":"0d7fc763889fcaba","type":"link out","z":"b84e61f8ff473dab","name":"NEXT","mode":"link","links":["98e92fce6d295276"],"x":950,"y":2520,"wires":[],"l":true},{"id":"126c26d667790842","type":"inject","z":"b84e61f8ff473dab","name":"Stop","props":[{"p":"devices","v":"end","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":110,"y":2580,"wires":[["cb40f23231a4d26e"]]},{"id":"e4d0d300826a0c4a","type":"inject","z":"b84e61f8ff473dab","name":"Device List 2","props":[{"p":"devices","v":"light.door_bulb_hue,light.globe_light_hue,light.tv_light_hue,end","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":130,"y":2520,"wires":[["cb40f23231a4d26e"]]},{"id":"b2a416dc9a65f762","type":"link in","z":"b84e61f8ff473dab","name":"RESET","links":["af69145241bd9b87"],"x":510,"y":2720,"wires":[["87af21aba4d6c287","6a8df29af0d3f859","b30a045490d44ca2","613e6e535283cc93"]],"l":true},{"id":"af69145241bd9b87","type":"link out","z":"b84e61f8ff473dab","name":"RESET","mode":"link","links":["b2a416dc9a65f762"],"x":950,"y":2400,"wires":[],"l":true},{"id":"62cdb4c707691ef7","type":"debug","z":"b84e61f8ff473dab","name":"waituntil_single_ok","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":990,"y":2560,"wires":[]},{"id":"8082d66bdcc10ebf","type":"debug","z":"b84e61f8ff473dab","name":"waituntil_single_timeout","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1010,"y":2600,"wires":[]},{"id":"8a86b0cc.b2bac","type":"server","name":"Home Assistant R","version":5,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":"30","areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"friendlyName","statusSeparator":"at: ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"h23","statusTimeFormat":"h:m","enableGlobalContextStore":true}]
It is different to the blinds because the blinds take around 20 seconds to fully open or close, and then they report a state change. The lights report the change immediately, so I removed the call service from this flow. The way to test this is:
- Edit the device list in the Inject node (Device List 1) with three Hue lights (different light brands might report their state change in a different path, this can be changed in the wait-until parameter inside the wait-until node).
- Edit the Light 1, 2 and 3 wait-until nodes with these devices.
- Activate the Inject node.
- Toggle each light in the order that you set them in the list.
This should always output the message from the first output of the wait nodes (to the debug nodes that end in _ok). This is the way it currently works for me after the update, but it is not dynamic to different sets of devices that can be configured just from the message in the Inject node.
Now, this is the way it worked before:
[{"id":"cb40f23231a4d26e","type":"function","z":"b84e61f8ff473dab","name":"List","func":"if (msg.devices) {\n var devices = msg.devices.split(\",\");\n if (devices.length > 0) {\n var firstDevice = devices.shift();\n var remainingDevices = devices.join(\",\");\n var newMsg = { device: firstDevice, devices: remainingDevices };\n newMsg.data = msg.data;\n newMsg.topic = msg.topic;\n newMsg.target = msg.target;\n node.send(newMsg);\n } else {\n node.warn(\"The input msg.devices is empty\");\n }\n} else {\n node.warn(\"The input msg.devices is missing\");\n}\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":330,"y":2400,"wires":[["4aa3c040b63441bb","088803648811567d"]]},{"id":"b9a400c262c7dcaa","type":"change","z":"b84e61f8ff473dab","name":"","rules":[{"t":"set","p":"reset","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":760,"y":2400,"wires":[["af69145241bd9b87"]]},{"id":"72bdc96fe937acf6","type":"debug","z":"b84e61f8ff473dab","name":"waituntil_separate_ok","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1000,"y":2700,"wires":[]},{"id":"4aa3c040b63441bb","type":"switch","z":"b84e61f8ff473dab","name":"end?","property":"device","propertyType":"msg","rules":[{"t":"eq","v":"end","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":510,"y":2440,"wires":[["b9a400c262c7dcaa"],["bc8cdefb63574206","87af21aba4d6c287","74b511448e29fbaa"]]},{"id":"87af21aba4d6c287","type":"ha-wait-until","z":"b84e61f8ff473dab","name":"1) ENABLE EITHER THIS","server":"8a86b0cc.b2bac","version":3,"outputs":2,"entities":{"entity":["{{device}}"],"substring":[],"regex":[]},"property":"data.new_state.last_updated","comparator":"is_not","value":"0","valueType":"str","timeout":"23","timeoutType":"num","timeoutUnits":"seconds","checkCurrentState":false,"blockInputOverrides":true,"outputProperties":[],"entityLocation":"data","entityLocationType":"none","x":690,"y":2520,"wires":[["0d7fc763889fcaba","62cdb4c707691ef7"],["0d7fc763889fcaba","8082d66bdcc10ebf"]]},{"id":"bc8cdefb63574206","type":"debug","z":"b84e61f8ff473dab","name":"next device","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"device","targetType":"msg","statusVal":"","statusType":"auto","x":750,"y":2440,"wires":[]},{"id":"088803648811567d","type":"debug","z":"b84e61f8ff473dab","name":"debug devicelist","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"devices","targetType":"msg","statusVal":"","statusType":"auto","x":540,"y":2360,"wires":[]},{"id":"6a8df29af0d3f859","type":"ha-wait-until","z":"b84e61f8ff473dab","name":"Light 1","server":"8a86b0cc.b2bac","version":3,"outputs":2,"entities":{"entity":["light.tv_light_hue"],"substring":[],"regex":[]},"property":"data.event.new_state.last_updated","comparator":"is_not","value":"0","valueType":"str","timeout":"23","timeoutType":"num","timeoutUnits":"seconds","checkCurrentState":false,"blockInputOverrides":true,"outputProperties":[],"entityLocation":"data","entityLocationType":"none","x":710,"y":2640,"wires":[["0d7fc763889fcaba","72bdc96fe937acf6"],["5943f872251b4383"]]},{"id":"74b511448e29fbaa","type":"switch","z":"b84e61f8ff473dab","d":true,"name":"2) OR THIS","property":"device","propertyType":"msg","rules":[{"t":"eq","v":"light.tv_light_hue","vt":"str"},{"t":"eq","v":"light.door_bulb_hue","vt":"str"},{"t":"eq","v":"light.globe_light_hue","vt":"str"}],"checkall":"true","repair":false,"outputs":3,"x":490,"y":2640,"wires":[["6a8df29af0d3f859"],["b30a045490d44ca2"],["613e6e535283cc93"]]},{"id":"b30a045490d44ca2","type":"ha-wait-until","z":"b84e61f8ff473dab","name":"Light 2","server":"8a86b0cc.b2bac","version":3,"outputs":2,"entities":{"entity":["light.door_bulb_hue"],"substring":[],"regex":[]},"property":"data.event.new_state.last_updated","comparator":"is_not","value":"0","valueType":"str","timeout":"23","timeoutType":"num","timeoutUnits":"seconds","checkCurrentState":false,"blockInputOverrides":true,"outputProperties":[],"entityLocation":"data","entityLocationType":"none","x":710,"y":2680,"wires":[["0d7fc763889fcaba","72bdc96fe937acf6"],["5943f872251b4383"]]},{"id":"613e6e535283cc93","type":"ha-wait-until","z":"b84e61f8ff473dab","name":"Light 3","server":"8a86b0cc.b2bac","version":3,"outputs":2,"entities":{"entity":["light.globe_light_hue"],"substring":[],"regex":[]},"property":"data.event.new_state.last_updated","comparator":"is_not","value":"0","valueType":"str","timeout":"23","timeoutType":"num","timeoutUnits":"seconds","checkCurrentState":false,"blockInputOverrides":true,"outputProperties":[],"entityLocation":"data","entityLocationType":"none","x":710,"y":2720,"wires":[["0d7fc763889fcaba","72bdc96fe937acf6"],["5943f872251b4383"]]},{"id":"5943f872251b4383","type":"debug","z":"b84e61f8ff473dab","name":"waituntil_separate_timeout","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1020,"y":2740,"wires":[]},{"id":"dc0cdc9fe14ea8e1","type":"inject","z":"b84e61f8ff473dab","name":"Device List 1","props":[{"p":"devices","v":"light.tv_light_hue,light.door_bulb_hue,light.globe_light_hue,end","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":130,"y":2460,"wires":[["cb40f23231a4d26e"]]},{"id":"98e92fce6d295276","type":"link in","z":"b84e61f8ff473dab","name":"NEXT","links":["0d7fc763889fcaba","d15e1afd77fc168c","202951defb7e5f21"],"x":150,"y":2400,"wires":[["cb40f23231a4d26e"]],"l":true},{"id":"0d7fc763889fcaba","type":"link out","z":"b84e61f8ff473dab","name":"NEXT","mode":"link","links":["98e92fce6d295276"],"x":950,"y":2520,"wires":[],"l":true},{"id":"126c26d667790842","type":"inject","z":"b84e61f8ff473dab","name":"Stop","props":[{"p":"devices","v":"end","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":110,"y":2580,"wires":[["cb40f23231a4d26e"]]},{"id":"e4d0d300826a0c4a","type":"inject","z":"b84e61f8ff473dab","name":"Device List 2","props":[{"p":"devices","v":"light.door_bulb_hue,light.globe_light_hue,light.tv_light_hue,end","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":130,"y":2520,"wires":[["cb40f23231a4d26e"]]},{"id":"b2a416dc9a65f762","type":"link in","z":"b84e61f8ff473dab","name":"RESET","links":["af69145241bd9b87"],"x":510,"y":2720,"wires":[["87af21aba4d6c287","6a8df29af0d3f859","b30a045490d44ca2","613e6e535283cc93"]],"l":true},{"id":"af69145241bd9b87","type":"link out","z":"b84e61f8ff473dab","name":"RESET","mode":"link","links":["b2a416dc9a65f762"],"x":950,"y":2400,"wires":[],"l":true},{"id":"62cdb4c707691ef7","type":"debug","z":"b84e61f8ff473dab","name":"waituntil_single_ok","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":990,"y":2560,"wires":[]},{"id":"8082d66bdcc10ebf","type":"debug","z":"b84e61f8ff473dab","name":"waituntil_single_timeout","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1010,"y":2600,"wires":[]},{"id":"8a86b0cc.b2bac","type":"server","name":"Home Assistant R","version":5,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":"30","areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"friendlyName","statusSeparator":"at: ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"h23","statusTimeFormat":"h:m","enableGlobalContextStore":true}]
(I just disabled the “2)” wait-until node and enabled the “1)”).
As I explained before with the blinds, this is working correctly only for th first device it receives (goes to the _ok debug node), and then with the next device, it gets stuck and timeouts.
This makes me remember that I don’t know if this is the right way to check for a state change. I’m setting the wait-until node to wait until the data.new_state.last_updated attribute “is not 0”.
Any help on trying to make this work as before is appreciated. Thanks!
Rodrigo