Automation that waits for a trigger once another trigger has fired

I’d like to configure an automation to do the following:

  • Commence when Trigger A is received
  • Once active, wait for Trigger B to be received before executing some actions

In other words, start the automation on one trigger, but don’t proceed until a different, subsequent trigger is received. Generally speaking, the time delta between Triggers A and B is variable, so a “for” statement isn’t useful here.

Try with a helper but like this.
Trigger A turns on a Boolean helper, trigger B starts the automation but doesn’t complete the action unless the helper is on.

The way you initially want it you may need to use some if-thens with delays, but you would have to know how long you want the delay to be.

Don’t use a helper, that’s crazy.

There is a proper option for this: wait_for_trigger. Unfortunately it’s buried in the Script docs rather than Automation docs.

In your example create an Automation with Trigger A in the main Trigger section, then add any Conditions you may want, finally in the Action part of the Automation you first use a wait_for_trigger and put your Trigger B in there.

1 Like

That makes perfect sense! Do I need to add the wait_for_trigger and the action in a Sequence, or will the wait block the automation from continuing to the next action until its condition has been satisfied?

No, Sequence is only needed for Scripts or for ‘run in parallel’ stuff. The automation will just wait until that second trigger occurs. There is an optional timeout you can specify to either make the automation continue after the timeout, or just quit without continuing.

Hi Dave,

This will work if the next trigger is expected in a short time, say half hour or so, Longer that that you run a better and better risk of the sequence failing. HA restarts and other things will interfere with this ‘wait’ just like it does for a delay. My suggestion is one automation sets a helper on and off. The second automation uses the helper as a condition to allow the action after the second trigger. That will always work. I would add a homeassistant_start trigger to the first automation as well, though to update the helper to current after a restart.

While you are correct regards to restarts etc, I think we are at a point where we don’t have to stress about these so much these days. 5 years ago I was restarting HA (or recovering from crashes) a lot but not anymore. I’ll go a good week or so and normally only restart due to an update.

Sure, if the wait time is excessive then it might not be a good idea. Personally I use this function for a few TTS announcements where I want it to announce after a set time of day but wait for me to enter a specific room. In this case it’s not waiting all that long and has worked perfectly for years.

1 Like

It certainly works well when the expected time is short, but I have helped several people that have been using multi-hours delay and asked why a couple of times a week it failed, and it was some interruption like this.

I use a repeat until for a blueprint related to a door or cover open too long. Works great there.

Just providing options.

@darrendavid
What kind of range of time do you expect between the first trigger and the second. Read above for options and reasons.