Is continuing script execution after a if-then block not possible?

Hello,

I added a if-then block in a script to switch a template fan off only if it is on, because it is controlled using infrared and it is the same command to switch it on or off.
On that side all is OK, it is only stopped if needed.
But I wish to execute some actions after that if-then block because I have to do a work around for a Google Assistant bug :slight_smile: but I have the same behavior as conditions, the rest of the script is not executed when except an indentation error from me, the delay and the call to the service are out of the if-then block.
I checked it using debugging script, it stops after the if-then block where nothing is executed because the fan was off.
If I believe this example of the script documentation, script should continue.

Has someone an idea of what I missed?

The script:

heure_du_coucher:
  description: éteint toutes les lumières et verrouille la porte d'entrée
  alias: Heure du coucher
  sequence:
    - service: lock.lock
      data: {}
      entity_id: lock.porte_d_entree
    - service: esphome.diffuseur_chambre_night_diffusion
    - service: light.turn_off
      entity_id:
        - light.lustre_chambre
        - light.lumieres_salon
    - service: switch.turn_off
      entity_id:
        - switch.lustre_bureau
    - delay: 00:00:01
    - service: fan.turn_off
      entity_id:
        - fan.ventilateur_bureau
        - fan.diffuseur_bureau
        - fan.diffuseur_salon
    - if:
        - condition: state
          entity_id: fan.ventilateur_chambre
          state: "on"
      then:
        - service: fan.turn_off
          entity_id: fan.ventilateur_chambre
    - delay: 01:05:01
    - service: media_player.media_stop
      target:
        entity_id: media_player.enceinte_chambre
  mode: single

Sure, the delay is really particular, but I don’t think it is the cause because it is not executed :slight_smile:

The script should continue, but I do find the 1 hour+ delay a bit odd. Did you intend that long a delay?

Also check that all the needed parameters are there for the media_player command. Sometimes it requires empty parameters, like data.

1 Like

Yes, because night sound from relaxing sounds in Google Assistant are played in loop so I want to be sure it is stoped after a little than an hour.

I’ve tested using developer tools->Service and it worked fine.
And by reading the script trace of last execution, the delay does not look like executed, last occurrence is the if block which passed with no action, as expected for this block.

What are you doing while you’re testing this? Are you just running it and wating or doing other things with HA? Because in case you’re not aware delays don’t survive an HA restart or reload. So if you call script.reload or restart HA while that delay is in progress it will simply stop and not get to the remaining steps.

Note that if you save, create or delete any script in the HA UI that calls script.reload behind the scenes and stops all running scripts. As does pressing the scripts button in Developer tools → yaml

1 Like

I tested it in real situation, Google Assistant runs it in the good night routine.
After that I don’t touch Home Assistant, just stay in my bed :slight_smile:

Can a call from Google Assistant restrict the time of execution of a script?

Nothing else that may cause an automation reload at night? Another reason could be the action executed above throws an error. Maybe try a continue on error?

1 Like

It finally works, since I has to restart Home Assistant.
I might have made a mistake when reloading scripts when I modified this one (wrong button or something else stupid).

Thanks for all your help.