Automation - wait for a second sensor

I have an automation wich turns on some lights, if I enter the flat. (There is an other automation for triggering the lights inside the flat. Different lights)

As “IF” I have

  • a presense sensor (FP2)
  • a normal PIR sensor
    assuming the “if part” is an “OR-Condition”, isnt it ?

Before I changed my automation (by adding the presense sensor), there was only a PIR sensor, but sometimes the cats triggered the sensor and it was not working.

As Condition I have a door sensor. (Homematic)

With only the PIR sensor, the door sensor was faster than the PIR sensor and the automation was working.

Now sometimes the Presense sensor is faster than the door sensor.
Is there a way to add a kind of “waiting” for the other sensor ? 1-2 seconds are enough. Difficult to explain. ^^

At the moment it is:
Movement / Presence detected AND Door is already open → Light on

I need this:
Movement / Presence detected AND Door is already open OR will be opened in 1-2 seconds → Light on

I can not change the order (IF and CONDITION), because if I leave the flat and open the door, it will turn on the light because there is already presense detected.

alias: "Bewegungsmelder: Flur bei Tür auf automatisch EIN"
description: ""
trigger:
  - type: motion
    platform: device
    device_id: 2475f05c3ef9383e0e7b9faa61ec0882
    entity_id: 7f00fab50b8e454bc825a26587ab4a35
    domain: binary_sensor
    enabled: false
  - type: occupied
    platform: device
    device_id: 572f2f1551d0181ca79a3994ee622fee
    entity_id: 9d5ff28aafc158c7f25d11819c6c6e8c
    domain: binary_sensor
condition:
  - condition: state
    entity_id: binary_sensor.eingangstur
    state: "on"
action:
  - type: turn_on
    device_id: dcbf8fb07a86922e8e7d045b433ae667
    entity_id: a25d838198b4fef8a741a9cc418c7575
    domain: light
mode: single

Use a wait_for_trigger with a 2 second time out in the action section.

Thx for you reply but it is not working

action:
  - wait_for_trigger:
      - platform: state
        entity_id: binary_sensor.eingangstur
        to: "on"
    timeout:
      seconds: 2
  - type: turn_on
    device_id: dcbf8fb07a86922e8e7d045b433ae667
    entity_id: a25d838198b4fef8a741a9cc418c7575
    domain: light

complete code

alias: "Bewegungsmelder: Flur bei Tür auf automatisch EIN"
description: ""
trigger:
  - type: motion
    platform: device
    device_id: 2475f05c3ef9383e0e7b9faa61ec0882
    entity_id: 7f00fab50b8e454bc825a26587ab4a35
    domain: binary_sensor
    enabled: false
  - type: occupied
    platform: device
    device_id: 572f2f1551d0181ca79a3994ee622fee
    entity_id: 9d5ff28aafc158c7f25d11819c6c6e8c
    domain: binary_sensor
condition:
  - condition: state
    entity_id: binary_sensor.eingangstur
    state: "on"
action:
  - wait_for_trigger:
      - platform: state
        entity_id: binary_sensor.eingangstur
        to: "on"
    timeout:
      seconds: 2
  - type: turn_on
    device_id: dcbf8fb07a86922e8e7d045b433ae667
    entity_id: a25d838198b4fef8a741a9cc418c7575
    domain: light
mode: single

What’s binary_sensor.eingangstur? Is it the occupancy or motion sensor?

Is it part of one of the two Device Triggers? We can’t tell from your example because a Device Trigger’s entity_id is an alphanumeric identifier.

Probably because the condition requires binary_sensor.eingangstur to be on and then the wait_for_trigger requires it to change to on (but it’s already on). So it simply times out after 2 seconds. It continues to the next action because that’s the default behavior after a timeout.

this is the door sensor

I want this:
door open (before motion) and motion detected → light on
motion detect 1st and door open inside 2 seconds after motion was detected → light on

For the search function, now its working.
The solution was to remove the door sensor from the condition part.
After this, I added the sensor again from the GUI with the type “opened” and continue_on_timeout: false
The code in the condition part is only a switch in the dashboard to disable the automation. The 2nd trigger is removed, because it is not longer needed.

alias: "Bewegungsmelder: Flur bei Tür auf automatisch EIN"
description: ""
trigger:
  - type: occupied
    platform: device
    device_id: 572f2f1551d0181ca79a3994ee622fee
    entity_id: 9d5ff28aafc158c7f25d11819c6c6e8c
    domain: binary_sensor
condition:
  - condition: state
    entity_id: input_boolean.lichtbeiturautomatischein
    state: "on"
action:
  - wait_for_trigger:
      - type: opened
        platform: device
        device_id: 3596d0ee60eaa1551362574b6273c442
        entity_id: 96b47b19b21d2d65e987c35b3d8bea84
        domain: binary_sensor
    timeout:
      seconds: 2
    continue_on_timeout: false
  - type: turn_on
    device_id: dcbf8fb07a86922e8e7d045b433ae667
    entity_id: a25d838198b4fef8a741a9cc418c7575
    domain: light
  - service: notify.alexa_media_wc_dot
    metadata: {}
    data:
      message: Hallo Boss und Hallo Bossine. Willkommen zu Hause.
mode: single

Thx for the help :slight_smile: