Delay after Trigger but before check conditions

I would like to check the following.

If a door is opened, wait 30 seconds, and then check the conditions.

I need those 30 seconds for the presence detection.
So after I opened the door, the fritzbox sensor needs time to see the phones, so the group.family will be changing to “home” which would then NOT run the automation.
Where do I need to put in the delay, if possible.
Right now I am working with a litte time window but this is not optimal.

As the entry will be closed very fast, it will not stay open for 30 seconds, so I can not work the with “for” condition (if open for 30 seconds etc)

- alias: entry open 
  trigger:
    platform: state
    entity_id: binary_sensor.door_window_sensor_xxx
    to: 'on'
  condition:
  - condition: time
    after: '18:30'
    before: '17:20'  
  - condition: state
    entity_id: group.family
    state: 'not_home'
  action:
    service: notify.all
    data:
      message: "Alarm "

You can remove the conditions from your automation and call a script in the action.

    action:
      - service: homeassistant.turn_on
        entity_id: script.your_script

In the script you can use delays, conditions, call services and so on.

The action part of an automation is a script, there’s no point launching a script as the only action of the automation unless you’re going to use it multiple times.

1 Like
- alias: entry open 
  trigger:
    platform: state
    entity_id: binary_sensor.door_window_sensor_xxx
    to: 'on'
  action:
    - delay: 00:00:30
    - condition: time
      after: '18:30'
      before: '17:20'  
    - condition: state
      entity_id: group.family
      state: 'not_home'
    - service: notify.all
      data:
        message: "Alarm "
8 Likes

Hi,

yes I only need the once.

I was not aware that I can use condition in the action section, so in case after the 30 seconds, the state of the group.familiy is “home” the action will stop and no message will be send ?

Regards

That’s exactly right :+1:

Thanks a lot.

Will test this asap :slight_smile:

1 Like

Sorry to dig up an old topic, but is it possible to do the same with conditions like a delay before an or and condition?

I’m pretty sure that’s not possible just due to the nature of trigger vs conditions.

Yes…

automation:
  alias: the amazing mf-social strikes again 
  trigger:
    platform: state 
    entity_id: binary_sensor.something
    to: 'on'
  action:
    - service: homeassistant.turn_on 
      entity_id: light.livingroom
    - delay: 00:00:30 
    - condition: or 
      conditions:
        - condition: state
          entity_id: input_number.people_count
          state: '0'
        - condition: time
          after: '18:30'
          before: '17:20'
    - service: homeassistant.turn_on 
      entity_id: light.porch
2 Likes

Amazing thank you

1 Like

Oh, I thought you wanted to do that in the “condition:” section not the “action:” section.

never mind…