Allow Automations to wait for another automation to finish

I have many different types of notification automatons. I cannot combine them because some require a trigger ID for the text that is read, while others require a state to be read.

I would like to be able string multiple automatons together but not have them overlap by allowing for a wait for automation to complete before the next automation can be run with a timeout period in case an automation was nut run.

All you have to do is put a wait template before each of your announcements:

- wait_template: "{{ not is_state('media_player.your_player_here', 'playing') }}"
  timeout: "00:01:00" # just in case

Thanks but it will not quite wok for my scenarios. Now if there was a wait template for an automation to finish it’s run, that would be great.

Why won’t it work?

Each automation will wait until the player is idle before playing.

There is but it is not the best way to do this.

- wait_template: "{{ is_state_attr('automation.your_automation_to_wait_for_here', 'current', '0') }}"
  timeout: "00:01:00" # just in case

IMHO you should re-think your whole announcement logic. You should not need to do this.

You are probably right but it’s extremely complicated with 12 different option choices and the text that is spoken or messaged depending on where I am, is either the trigger id or the state of a input_text sensor that is being generated by a separate automation that adds multiple text lines together, haha.

I want to convert the choice options to if-then as well but I don’t want to start over.

Security System turns on by an input boolean
This triggers an automation to turn on security which controls a bunch of blue iris cameras and changes the presets to looking at different areas.
The automation then triggers another input boolean to trigger a security summary automation
The security summary automation will check various scenarios such as if the cameras are online and if all doors are locked and closed and sensors are online. Based on these if statements an input_text sensor is built with text such as “All Cameras are Online and all Doors are locked”. If any scenario fails the text could be something like “All Cameras are Online and One Door is Unlocked”.
Meanwhile, the input boolean that triggered the security summary automation is also a trigger to start the Notification automation.
The notification automation will play a google tts based on where I am in the home or out of home. If I am at home and in the living room, the notification will play on my living room home hub. If I am away from home, the automation will send a message via notification to my phone.
The notification automation will play the text of either a trigger id such as “Security On”, or it will play the result of the security summary automation if the input_boolean was triggered.

The end result of all of this =)

  1. I turn on my bedtime scene via voice and google assistant from a google home hub.
  2. The security scene starts and turns all cameras on, locks all doors, turns of hall lights off, turns on air purifier
  3. My Sonos speaker then tells me the security system is on, then that the garage and front door have been locked, then gives me a read out of all my security information such as cameras being online and in the correct preset mode.
  4. Next my bedroom lights turn off, fan turns on, and my sonos speakers play always sunny for 30 minutes before falling asleep. The sonos speaker then stops playing.
  5. Security system them is turned off and everything resets when bedtime scene ends based on a sonos alarm.
  6. Sonos alarm time is set if based on a beast mode input boolean. If Beast Mode is on, alarm time goes off at 5:30 am. If Beast Mode is off, alarm time goes off at 7:30 am.
  7. Beast Mode input boolean is turned on if I have worked out during the day. IOS shortcuts will send a service call to HA to turn on beast mode input boolean. Basically if I am working out, I want to keep waking up at 5:30 am. If I don’t feel like working out, I want to wake p at the standard 7:30 am.

Wow it took me writing this out to see how crazy this is and how much you can do with home assistant,

I agree with tom_l that it’s already possible and simply depends on creatively daisy-chaining the execution sequence as well as some judicious use of waiting/timeout mechanisms.

In your bedtime application, which part must wait for another part to complete before it is allowed to proceed?

Also, it’s possible for a script to be called in a blocking manner (execution sequence waits for the script to complete before proceeding to the next action).

Hi,
I just needed to implement this to one of my automation, and found the following approach:

wait_for_trigger:
  - platform: state
    entity_id:
      - automation.<id_of_automation_to_wait_for>
    attribute: current
    to: "0"

I´m leveraging here the attirbute “current” which shows how many instances of the automation are currently running.

1 Like

@fraintt, I tried your suggestion but it was not working for me as-is.

It only worked if I edited the yaml and changed to: "0" to to: 0. The value in the state is an integer and I guess it was comparing to 0 to "0".

wait_for_trigger:
  - platform: state
    entity_id:
      - automation.<id_of_automation_to_wait_for>
    attribute: current
    to: 0

This result in a warning that it cannot be edited by the Visual editor but at least it works.