Home Assistant Sensor, state based on series of events

Had a sudden thought about this functionality and I’m not sure if HA currently has anything like this implemented. Move me to a correct sub-forum if necessary…

So, I’m looking to trigger e.g. some input boolean based on pre-defined series of events, such as:

  1. Door sensor #1 state to ‘open’
  • in the next 30 seconds:
  1. Light #1 state to ‘on’
  • in the next 20 seconds:
  1. Door sensor #1 state to ‘closed’

If the above happened, turn boolean switch on. If there was too long wait period between events, reset the script to wait for door #1 to open again.

This script would let me know that someone turned on the light #1 by entering from a specific door and went back through that same door.

Any thoughts?

That’s a simple Node-RED flow

[{"id":"c41dc4ca.354788","type":"tab","label":"Flow 8","disabled":false,"info":""},{"id":"4856ba76.e75f54","type":"server-state-changed","z":"c41dc4ca.354788","name":"","server":"ef392d83.86c5a","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"binary_sensor.front_door","entityidfiltertype":"exact","outputinitially":false,"state_type":"habool","haltifstate":"true","halt_if_type":"bool","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"x":190,"y":260,"wires":[["c9056a92.4604d8"],[]]},{"id":"c9056a92.4604d8","type":"ha-wait-until","z":"c41dc4ca.354788","name":"","server":"ef392d83.86c5a","outputs":2,"entityId":"light.kitchen_light","property":"state","comparator":"is","value":"on","valueType":"str","timeout":"30","timeoutUnits":"seconds","entityLocation":"","entityLocationType":"none","checkCurrentState":true,"blockInputOverrides":true,"x":500,"y":300,"wires":[["6f7a08f5.fa6468"],[]]},{"id":"6f7a08f5.fa6468","type":"ha-wait-until","z":"c41dc4ca.354788","name":"","server":"ef392d83.86c5a","outputs":2,"entityId":"binary_sensor.front_door","property":"state","comparator":"is","value":"off","valueType":"str","timeout":"20","timeoutUnits":"seconds","entityLocation":"","entityLocationType":"none","checkCurrentState":false,"blockInputOverrides":true,"x":720,"y":340,"wires":[["bc22dc03.f5f23"],[]]},{"id":"bc22dc03.f5f23","type":"api-call-service","z":"c41dc4ca.354788","name":"","server":"ef392d83.86c5a","version":1,"debugenabled":false,"service_domain":"input_boolean","service":"turn_on","entityId":"input_boolean.frontdoor_sensor","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1040,"y":360,"wires":[[]]},{"id":"ef392d83.86c5a","type":"server","z":"","name":"Home Assistant","legacy":false,"hassio":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]

I’ve not been using Node-RED, so that could be the solution.
But does the “wait_until” wait indefinitely? Can I reset back to waiting for the front_door if the second condition does not happen in X seconds?

the two outputs of the change state node is true or false
the wait until will output through the first output once the value is true, if time out occurs then it output through the second output instead.

Just for your information, you can vote for your own feature request :wink:

I can see your use case for this, however I don’t fully agree on this:

What about when a person enters a room through the door, turns the light on and then closes the door but stays in the room, like in a bathroom for example? These series of events doesn’t allow you to determine whether the person that closed the door left the room or stayed inside the room.

Completely agree, i though it was better as a Confirmation that Someone came home
opened the door, turned the light on, Put their bag down, and finally closed the door

1 Like

HA supports wait templates in scripts.

yeah i know, but i sux at yaml automations.
so I can’t offer him help there, and you couldn’t do it as simply as its done in Node-RED

I think this is going to be more like Cluedo,
Who left the light on ?

Thanks @sjee , this might be just what I’ve been looking for!