Scripts that have delays can be interrupted, but there’s no way to specify a final sequence of steps that are guaranteed to execute upon completion.
For example, the below doesn’t set the variable back to enabled unless the script runs to completion.
disable_camect_events_for_15_min:
sequence:
- service: vantage.set_variable_vid
data:
vid: 7237
value: 0 # disable
- delay: '0:15'
- service: vantage.set_variable_vid
data:
vid: 7237
value: 1 # re-enable
Ideally, one could write (in !included scripts.yaml):
disable_camect_events_for_15_min:
sequence:
- service: vantage.set_variable_vid
data:
vid: 7237
value: 0 # disable
- delay: '0:15'
finally:
- service: vantage.set_variable_vid
data:
vid: 7237
value: 1 # re-enable
And the sequence of steps in the finally block would execute always, even if the script is terminated mid-execution.