how can we stop a script, that has several other sub actions and repeats, to finally end itself?
play_sleep_radio:
alias: Play sleep radio
mode: restart
sequence:
-
-
- wait_template: >
{% set trigger = states('sensor.time')%}
{{(now() - state_attr('script.play_sleep_radio','last_triggered')).total_seconds()
> states('input_number.onsleep_delay')|int * 60}}
- service: script.turn_off
entity_id: script.play_sleep_radio
the wait_template itself is working fine (though boy checks per minute, and hence has a possible accuracy issue of a minute…) but the most important thing is to cancel the script itself.I’ve thought about wrapping this complete script in a ‘while’ and ‘until’ construction, but that only goes for loops?
the only other option I see now it an extra automation:
- alias: Sleep radio off
id: Sleep radio off
trigger:
platform: template
value_template: >
{% set trigger = states('sensor.time')%}
{{(now() - state_attr('script.play_sleep_radio','last_triggered')).total_seconds()
> states('input_number.onsleep_delay')|int * 60}}
action:
service: script.turn_off
entity_id: script.play_sleep_radio
thanks for having a look?