How to replace delay by condition in a script?

hi all,

i’ve made a script who

  • open the tv
  • launch a scene who set up the good source
  • launch a scene who set up the good volume
  • launch a scene who turn on a light

my problem is that sometimes the set up of the source is not done.
i suppose that sometimes there a little delay, and so when the set up of the source is launched, the TV is not yet powered and so the source is not set up.

ofcourse i can put a arbitrary delay of x seconds, but i would like to know if there is a way to put a conditional delay, like the same things we do for the status of the switch like {{is_state('media_player', 'playing')}}

- delay:
    seconds: >
      {{ 5 if is_state('media_player.xxx', 'playing') else 0 }}

This template will wait 5 seconds if the media player is playing, otherwise it will not wait.

1 Like

So, you mean like a wait template?

# Wait until media player starts playing
- wait_template: "{{ is_state('media_player.floor', 'playing') }}"
2 Likes

Is there a way to use a wait_template to delay the trigger of an automation?

I want an automation triggered just after some seconds the triggering of another automation which run at the same time and with the same trigger and conditions…But with different actions…

ho ! i haven’t see that in the doc.

Yes, wait until is exactly what i need.