I’m using similar pattern, quickly mocked up one for you. Not tested though.
The idea is to:
- define persons list (as regular expression), see first two nodes:
person\.(name1|name2)
- react on state change of any of them (home or not home)
- count how many of those persons are at home (0 or more)
- if zero, start delay, otherwise, reset delay
- if delay node still handles some message after a time, it will pass it to service node turning the lights off
hope it will work for you. Idea is clean and pretty neat especially in case of more persons (no need to create net of connections to check multiple persons)
but there might be some mistakes since it’s not tested.
[{"id":"6b942e5f.ffe45","type":"tab","label":"Flow 4","disabled":false,"info":""},{"id":"283bf8c2.72ca08","type":"ha-get-entities","z":"6b942e5f.ffe45","server":"6cdd0bc8.b8e434","name":"How many persons in house","rules":[{"property":"entity_id","logic":"is","value":"person\\.(name1|name2)","valueType":"re"},{"property":"state","logic":"is","value":"home","valueType":"str"}],"output_type":"count","output_empty_results":false,"output_location_type":"msg","output_location":"payload","output_results_count":1,"x":520,"y":220,"wires":[["ee918ced.20c918"]]},{"id":"ee918ced.20c918","type":"switch","z":"6b942e5f.ffe45","name":"zero or more","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"num"},{"t":"gt","v":"0","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":750,"y":220,"wires":[["7ec70534.059114"],["41c269c0.9a84b"]]},{"id":"6618a58e.9e08c4","type":"server-state-changed","z":"6b942e5f.ffe45","name":"Some person state changed","server":"6cdd0bc8.b8e434","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"person\\.(name1|name2)","entityidfiltertype":"regex","outputinitially":true,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"for":"","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"x":240,"y":220,"wires":[["283bf8c2.72ca08"]]},{"id":"7ec70534.059114","type":"delay","z":"6b942e5f.ffe45","name":"","pauseType":"delay","timeout":"3","timeoutUnits":"minutes","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":1020,"y":220,"wires":[["1020e3ae.656db4"]]},{"id":"41c269c0.9a84b","type":"change","z":"6b942e5f.ffe45","name":"reset","rules":[{"t":"set","p":"reset","pt":"msg","to":"reset","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":890,"y":320,"wires":[["7ec70534.059114"]]},{"id":"1020e3ae.656db4","type":"api-call-service","z":"6b942e5f.ffe45","name":"","server":"6cdd0bc8.b8e434","version":1,"debugenabled":false,"service_domain":"light","service":"turn_off","entityId":"","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1250,"y":220,"wires":[[]]},{"id":"6cdd0bc8.b8e434","type":"server","name":"Home Assistant"}]
Also you can consider to create in HA group of persons (ie children), then simply check for changing its state.