Just sharing some thoughts and hoping to polish the code. Alexa remote allows to set an array of devices whithin the Speak feature under the Routine node, so I thought of building a dynamic array of devices according to different occupancy conditions such as: PIRs, Computer on, light to max, somebody sleeping, etc…
Supose I have 3 rooms in my house, a PIR in every room and I assume that if motion’s been detected over the last minute, then it’s occupied, otherwise it isn’t.
[{"id":"c6b01ac0.648728","type":"api-current-state","z":"937ef78.ec6b408","name":"PIR A off for 1'?","server":"9405c3fe.d0a6c","version":3,"outputs":2,"halt_if":"off","halt_if_type":"str","halt_if_compare":"is","entity_id":"binary_sensor.pir_a","state_type":"str","blockInputOverrides":true,"outputProperties":[],"for":"1","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":500,"y":700,"wires":[[],["f22fcfda.e5c7a"]]},{"id":"ad7b8b0.4e64078","type":"comment","z":"937ef78.ec6b408","name":"Room A","info":"","x":470,"y":640,"wires":[]},{"id":"16f18b3e.5b1785","type":"api-current-state","z":"937ef78.ec6b408","name":"PIR B off for 1'?","server":"9405c3fe.d0a6c","version":3,"outputs":2,"halt_if":"off","halt_if_type":"str","halt_if_compare":"is","entity_id":"binary_sensor.pir_b","state_type":"str","blockInputOverrides":true,"outputProperties":[],"for":"1","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":500,"y":820,"wires":[[],["9b156541.e89ed8"]]},{"id":"2a1674fd.7ff7bc","type":"comment","z":"937ef78.ec6b408","name":"Room B","info":"","x":470,"y":760,"wires":[]},{"id":"70c18298.dc04bc","type":"api-current-state","z":"937ef78.ec6b408","name":"PIR C off for 1'?","server":"9405c3fe.d0a6c","version":3,"outputs":2,"halt_if":"off","halt_if_type":"str","halt_if_compare":"is","entity_id":"binary_sensor.pir_c","state_type":"str","blockInputOverrides":true,"outputProperties":[],"for":"1","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":500,"y":940,"wires":[[],["da20f4c4.480168"]]},{"id":"82be0bb1.50e338","type":"comment","z":"937ef78.ec6b408","name":"Room A","info":"","x":470,"y":880,"wires":[]},{"id":"f22fcfda.e5c7a","type":"change","z":"937ef78.ec6b408","name":"set Echo device A","rules":[{"t":"set","p":"tts_source","pt":"msg","to":"G0914xxxxxxxxxxx","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":730,"y":700,"wires":[["4cfacee8.aca16"]]},{"id":"9b156541.e89ed8","type":"change","z":"937ef78.ec6b408","name":"set Echo device B","rules":[{"t":"set","p":"tts_source","pt":"msg","to":"G0014xxxxxxxxxxx","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":730,"y":820,"wires":[["4cfacee8.aca16"]]},{"id":"da20f4c4.480168","type":"change","z":"937ef78.ec6b408","name":"set Echo device B","rules":[{"t":"set","p":"tts_source","pt":"msg","to":"G0014xxxxxxxxxxx","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":730,"y":940,"wires":[["4cfacee8.aca16"]]},{"id":"4cfacee8.aca16","type":"join","z":"937ef78.ec6b408","name":"","mode":"custom","build":"array","property":"tts_source","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"1","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":970,"y":820,"wires":[["8b0b43de.554e9"]]},{"id":"8b0b43de.554e9","type":"change","z":"937ef78.ec6b408","name":"Set global","rules":[{"t":"set","p":"tts_source","pt":"global","to":"tts_source","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1120,"y":820,"wires":[[]]},{"id":"bace9bae.345168","type":"inject","z":"937ef78.ec6b408","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"1.2","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":230,"y":820,"wires":[["c6b01ac0.648728","16f18b3e.5b1785","70c18298.dc04bc"]]},{"id":"9405c3fe.d0a6c","type":"server","name":"Home Assistant","version":2,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":30}]
Now what I’d like to polish. The join node is set to wait for 1 second in order to know whether it’s received all the needed info. Is there a better way of doing this taking into consideration the resulting length of the array is dynamic? Can the 1 second timeout be avoided somehow?
I thought of creating helpers and split flows for every helper then using the get entities node but I was hoping to avoid that too… I’ll do that if need be. Not sure this is what you mean.
Besides that, and considering I have zero knownledge using the function node, could that example be adjusted to my actual flow? yes/no will suffice, don’t bother yourself coding everything.
[{"id":"e53dd506.bf7318","type":"api-current-state","z":"937ef78.ec6b408","name":"PIR L off 1'?","server":"9405c3fe.d0a6c","version":3,"outputs":2,"halt_if":"off","halt_if_type":"str","halt_if_compare":"is","entity_id":"binary_sensor.pir_lavabo","state_type":"str","blockInputOverrides":true,"outputProperties":[],"for":"1","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":830,"y":980,"wires":[["638f3376.4d6dfc"],["997783f0.62e61"]]},{"id":"638f3376.4d6dfc","type":"api-current-state","z":"937ef78.ec6b408","name":"Q L on?","server":"9405c3fe.d0a6c","version":3,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","entity_id":"light.q_lavabo","state_type":"str","blockInputOverrides":true,"outputProperties":[{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"for":0,"forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":840,"y":1020,"wires":[["d06a918.5b1197"],["1f84c7d0.6a6318"]]},{"id":"d06a918.5b1197","type":"switch","z":"937ef78.ec6b408","name":"","property":"data.attributes.brightness","propertyType":"msg","rules":[{"t":"eq","v":"255","vt":"num"},{"t":"else"}],"checkall":"false","repair":false,"outputs":2,"x":955,"y":1020,"wires":[["997783f0.62e61"],["1f84c7d0.6a6318"]],"l":false},{"id":"997783f0.62e61","type":"change","z":"937ef78.ec6b408","name":"ducha","rules":[{"t":"set","p":"tts_source","pt":"msg","to":"deviceB","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1170,"y":1000,"wires":[["f3decb58.502038"]]},{"id":"6137cbeb.2c1e44","type":"comment","z":"937ef78.ec6b408","name":"lavabo","info":"","x":810,"y":940,"wires":[]},{"id":"1f84c7d0.6a6318","type":"api-current-state","z":"937ef78.ec6b408","name":"PIR E off 1'?","server":"9405c3fe.d0a6c","version":3,"outputs":2,"halt_if":"off","halt_if_type":"str","halt_if_compare":"is","entity_id":"binary_sensor.pir_entrada","state_type":"str","blockInputOverrides":true,"outputProperties":[],"for":"1","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":830,"y":1060,"wires":[[],["997783f0.62e61"]]},{"id":"af5feda4.2a5dc","type":"comment","z":"937ef78.ec6b408","name":"cuarto de E","info":"","x":830,"y":1100,"wires":[]},{"id":"ad2a683c.3509b8","type":"api-current-state","z":"937ef78.ec6b408","name":"Edu awake?","server":"9405c3fe.d0a6c","version":3,"outputs":2,"halt_if":"off","halt_if_type":"str","halt_if_compare":"is","entity_id":"input_boolean.eduardo_duerme","state_type":"str","blockInputOverrides":true,"outputProperties":[],"for":0,"forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":670,"y":1140,"wires":[["97c46f2b.cc12d"],[]]},{"id":"97c46f2b.cc12d","type":"api-current-state","z":"937ef78.ec6b408","name":"PIR E off 1'?","server":"9405c3fe.d0a6c","version":3,"outputs":2,"halt_if":"off","halt_if_type":"str","halt_if_compare":"is","entity_id":"binary_sensor.pir_entrada","state_type":"str","blockInputOverrides":true,"outputProperties":[],"for":"1","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":830,"y":1140,"wires":[["7f5bf68b.ec7d98"],["5b50641.5cccb9c"]]},{"id":"7f5bf68b.ec7d98","type":"api-current-state","z":"937ef78.ec6b408","name":"PIR Ed off 1'?","server":"9405c3fe.d0a6c","version":3,"outputs":2,"halt_if":"off","halt_if_type":"str","halt_if_compare":"is","entity_id":"binary_sensor.pir_eduardo","state_type":"str","blockInputOverrides":true,"outputProperties":[],"for":"1","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":840,"y":1180,"wires":[[],["5b50641.5cccb9c"]]},{"id":"c8df6840.b82bf8","type":"comment","z":"937ef78.ec6b408","name":"cuarto de P","info":"","x":830,"y":1220,"wires":[]},{"id":"657e0fa6.90172","type":"api-current-state","z":"937ef78.ec6b408","name":"P awake?","server":"9405c3fe.d0a6c","version":3,"outputs":2,"halt_if":"off","halt_if_type":"str","halt_if_compare":"is","entity_id":"input_boolean.pamen_duerme","state_type":"str","blockInputOverrides":true,"outputProperties":[],"for":0,"forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":660,"y":1260,"wires":[["c0a774da.4be468"],[]]},{"id":"c0a774da.4be468","type":"api-current-state","z":"937ef78.ec6b408","name":"PIR B off 1'?","server":"9405c3fe.d0a6c","version":3,"outputs":2,"halt_if":"off","halt_if_type":"str","halt_if_compare":"is","entity_id":"binary_sensor.pir_barra","state_type":"str","blockInputOverrides":true,"outputProperties":[],"for":"1","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":830,"y":1260,"wires":[["e5232082.0eef2"],["5a4a1d76.5e4dd4"]]},{"id":"e5232082.0eef2","type":"api-current-state","z":"937ef78.ec6b408","name":"PIR P off 1'?","server":"9405c3fe.d0a6c","version":3,"outputs":2,"halt_if":"off","halt_if_type":"str","halt_if_compare":"is","entity_id":"binary_sensor.pir_pamen","state_type":"str","blockInputOverrides":true,"outputProperties":[],"for":"1","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":830,"y":1300,"wires":[[],["5a4a1d76.5e4dd4"]]},{"id":"5b50641.5cccb9c","type":"change","z":"937ef78.ec6b408","name":"Eduardo","rules":[{"t":"set","p":"tts_source","pt":"msg","to":"deviceC","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1160,"y":1160,"wires":[["f3decb58.502038"]]},{"id":"5a4a1d76.5e4dd4","type":"change","z":"937ef78.ec6b408","name":"Pamen","rules":[{"t":"set","p":"tts_source","pt":"msg","to":"deviceE","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1160,"y":1280,"wires":[["f3decb58.502038"]]},{"id":"f3decb58.502038","type":"join","z":"937ef78.ec6b408","name":"","mode":"custom","build":"array","property":"tts_source","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"1","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":1410,"y":1160,"wires":[["2ad4ee99.fec632"]]},{"id":"257c191a.abbb66","type":"change","z":"937ef78.ec6b408","name":"dot","rules":[{"t":"set","p":"tts_source","pt":"msg","to":"deviceA","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1170,"y":920,"wires":[["f3decb58.502038"]]},{"id":"dad99819.1b6868","type":"change","z":"937ef78.ec6b408","name":"","rules":[{"t":"set","p":"tts_source","pt":"global","to":"tts_source","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1690,"y":1160,"wires":[[]]},{"id":"c0ac4e7e.52b4e","type":"server-state-changed","z":"937ef78.ec6b408","name":"Rest","server":"9405c3fe.d0a6c","version":3,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"light.q_lavabo, input_boolean.eduardo_duerme, input_boolean.pamen_duerme, input_boolean.startup","entityidfiltertype":"substring","outputinitially":true,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":false,"for":"0","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[],"x":390,"y":860,"wires":[["a91d06d6.eac658"]]},{"id":"2f8d832.170dd7c","type":"server-state-changed","z":"937ef78.ec6b408","name":"PIRs on?","server":"9405c3fe.d0a6c","version":3,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"binary_sensor.pir_","entityidfiltertype":"substring","outputinitially":false,"state_type":"str","haltifstate":"on","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":false,"for":"0","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"},{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"}],"x":220,"y":920,"wires":[["cf5d16c9.a1dec8","a91d06d6.eac658"],["cf5d16c9.a1dec8"]]},{"id":"a91d06d6.eac658","type":"trigger","z":"937ef78.ec6b408","name":"","op1":"","op2":"","op1type":"pay","op2type":"payl","duration":"1250","extend":false,"overrideDelay":false,"units":"ms","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":515,"y":900,"wires":[["ad2a683c.3509b8","657e0fa6.90172","b7ae20a4.97a65","e53dd506.bf7318"]],"l":false},{"id":"cf5d16c9.a1dec8","type":"trigger","z":"937ef78.ec6b408","name":"","op1":"","op2":"","op1type":"nul","op2type":"payl","duration":"1","extend":false,"overrideDelay":false,"units":"min","reset":"on","bytopic":"topic","topic":"topic","outputs":1,"x":390,"y":960,"wires":[["a91d06d6.eac658"]]},{"id":"2ad4ee99.fec632","type":"switch","z":"937ef78.ec6b408","name":"","property":"tts_source.length","propertyType":"msg","rules":[{"t":"lte","v":"4","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":1525,"y":1160,"wires":[["dad99819.1b6868"]],"l":false},{"id":"b7ae20a4.97a65","type":"api-current-state","z":"937ef78.ec6b408","name":"Edu awake?","server":"9405c3fe.d0a6c","version":3,"outputs":2,"halt_if":"off","halt_if_type":"str","halt_if_compare":"is","entity_id":"input_boolean.eduardo_duerme","state_type":"str","blockInputOverrides":true,"outputProperties":[],"for":0,"forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":830,"y":860,"wires":[["257c191a.abbb66"],["afcfc865.bac1c8"]]},{"id":"afcfc865.bac1c8","type":"api-current-state","z":"937ef78.ec6b408","name":"P awake?","server":"9405c3fe.d0a6c","version":3,"outputs":2,"halt_if":"off","halt_if_type":"str","halt_if_compare":"is","entity_id":"input_boolean.pamen_duerme","state_type":"str","blockInputOverrides":true,"outputProperties":[],"for":0,"forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":820,"y":900,"wires":[["257c191a.abbb66"],[]]},{"id":"cece09ad.910cd8","type":"comment","z":"937ef78.ec6b408","name":"tts source","info":"","x":220,"y":800,"wires":[]},{"id":"f64b8b2e.9ea918","type":"comment","z":"937ef78.ec6b408","name":"Dot","info":"","x":810,"y":820,"wires":[]},{"id":"9405c3fe.d0a6c","type":"server","name":"Home Assistant","version":2,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":30}]
I would change the join node to a node that sets a flow variable to an array of the pir reference to if a room is occupied. Then use that array to build the global var.
Hey, thanks for the tip but I don’t believe I know how to do that. I’d love to learn though.
For now I ended up creating an occupancy sensor for each room. Sensor goes either off or, when all conditions check, it displays the echo device serial as its state.
You basically did what I suggested but used the entity node in place of a flow context variable. I don’t see anything wrong with how you have it set now. Whatever gets the job done is good in my book.
Regarding this. I more or less know how to set a flow variable for each room, but how would you build the array? add an element, delete an element, etc… ?