Automation based on the sequence that 2 sensors are triggered

I’m trying to create an automation to trigger my entrance hall light in a specific scenario only but can’t find any detail on how best to achieve it.

I have 2 sensors, a window/door sensor on the entrance door and a PIR in the entrance hallway.

I want to trigger the hallway light to come on only if the door sensor triggers first and then the PIR (suggesting I came in the house).
I don’t want the PIR to trigger the light by itself, that would get annoying every time I walk past the door.
I also only want this to happen when it’s dark. (happy to use the sunset for this for now, I will maybe get a lux sensor at some point to account for a cloudy day when it would be dark enough to warrant the light on before sunset).

I just dont know how to combine the sequence of 1. Door Sensor triggered then 2. PIR triggered to run the automation.

alias: example
trigger:
  - platform: state
    entity_id: binary_sensor.door
    from: 'off'
    to: 'on'
condition: []
action:
  - wait_for_trigger:
      - platform: state
        entity_id: binary_sensor.motion
        from: 'off'
        to: 'on'
    timeout:
      minutes: 1
    continue_on_timeout: false
  - service: light.turn_on
    target:
      entity_id: light.hall

Reference

wait_for_trigger

@123
Thought i’d just share my thanks for this . Fairly new to HA and been trying to figure out a similar automaiton on my porch door and then front door to determine if somone is leaving or entering the house. I’d been totally over engineering it, but this simple script seems to be working perfectly.

1 Like