Add delay in script / automation based on condition


I am working on automating my TV with a RM Mini 3. I have scripts to send specific IR commands. I want to make sure that the TV is already on before I send any command. Therefore, I added a delay of 20 seconds (time RM Mini need to boot, since it is powered on with the TV power socket). Is there a way to only have the delay used if the TV is not yet switched on in HASS?

My scripts look like follows:

I removed the delay for easier testing, since the TV is currently on.

You can create 2 automations:

   condition: state
   state: 'on'

And in the second one you add the delay:

   condition: state
   state: 'off'
    - service: switch.turn_on
    - delay: '00:00:20'

Thanks. That works!
However, I was hoping there is a more efficient way, since I needed to duplicate my already 3 automations. But that is fine for now.

You could do a wait_until entry that checks the state of the TV for it to be on. Then you don’t need to guess on the length of time it will take.

Why not keep the broadlink always on?

The TV is powered on by a 433Mhz power socket. Therefore, the state changes immediatly, while the TV is still “booting”.

It would save some seconds. But I would still need to wait some seconds until the devices accept IR commands, since I switch them on/off with a 433Mhz power socket.