Quick question about automation delays

if you put a delay in an automation under Action: and the trigger happens again, will the automation start over again, ignoring the delay?

I have an input dropdown based on arrival. One option is “Just arrived” This stays that way for 10 minutes after I arrive, then changes to home.

I have a motion detector at my door.

Trigger is motion
condition is state of just arrived
action is unlock door.

I want to then delay to have a 10 minute delay, so that if someone else walks up in that same 10 minute period the door does not unlock again. A simple delay in the action seems like it would work.

This is what I was thinking

Trigger is motion
condition is state of just arrived
action is unlock door.
delay 10 minutes

After that the condition would not be met. Not sure I’l lgo this route, but it had me thinking about how automations work in general with delays.

Add a condition to your motion trigger that the state needs to be off for 10 minutes.

- alias: 'When a door opens..'
      - platform: state
          - binary_sensor.motion_sensor
        to: 'on'
        from: 'off'
          minutes: 10
      - condition: state
        entity_id: binary_sensor.arival
        state: 'just_arived'
      - service: lock.unlock
        entity_id: lock.front_door

Cool, thanks. I still have the question about how automations handle delays.

I’m thinking about other scenarios.

If an automation is in progress, waiting (for whatever reason), and the trigger became true again, would it kick off again, starting over? Would it be ingored? Would there be two instances of the same automation running?


Automations will just trigger and if triggered again your will get a repeat action.
There’s no delay in automations but you could stack automations to trigger one after another.

Yes, it’s a bug that doesn’t seem to have been fixed.

The workaround is to prevent it triggering the second time, as suggested by @Landrash or similar.

Spooky, I had the exact same question at the exact same time, I just never got round to asking.

Now… @anon43302295 why is it considered a bug? So long as it is consistent and there is a way to make HA behave in the way you want it to does it matter if an automation can be triggered again before it has finished, or not? Or maybe I missed something…

I had a scenario I was thinking about last night where I think I wanted the automation to be re-triggered even if it was waiting with a delay. (I can’t remember exactly what it was I was thinking about but it was something to do with a Dash button toggling two lights which normally went off at different times, without them getting out of sync.).

In light of the answers here I think my question becomes, in the case where an automation triggers again before the first ends are both active or does the second one kill the first?

But maybe more importantly, is the current behaviour ‘officially’ a bug, because if it is I guess we should work on the principle that it will be fixed one day :slight_smile: and be careful about using logic that utilises the current situation!

I’ve been away from HA for a while, but unless the behaviour has changed you can disable the automation within the action itself, and reenable it on the last step. That way you won’t have it fire while the actions are running.

See Limit automation triggering for details.

Well, I think it’s a bug because if I program an automation that is supposed to wait 5 minutes from a sensor switching on before it does something, then I expect it to wait 5 minutes. I wouldn’t have programmed it that way if it wasn’t the desired result.

For me, if the sensor switches on again 2 minutes later, I should still be 3 minutes from my action, but currently I would get the action straight away on the second trigger.

Interesting to note that a script behaves correctly because when you try to trigger it a second time if it’s already running, it knows it is already running and ignores the second trigger.

Given that the action part of an automation is a script, they should behave the same way.

IMO, obviously, if others have a better use case, I’m not particularly fussed :slight_smile:

@chrio that is exactly what I decided to do. (None of what I wrote last night is properly tested yet though!)

@anon43302295 I don’t disagree with anything you say and yes the fact that scripts behave that way suggest that automations should too.

1 Like