How to stop script execution

Hi, I have an automation that increases the volume of the music being played after turning on the light, and does it gradually. To do this step by step I use script. I have a separate automation that lowers the volume immediately (in one step) when the light is turned off. Everything works fine with one exception: when I turn the light on and off while the volume is increasing. Then the “light off” automation doesn’t work, I’m guessing because the script is still executing.
Is it possible to interrupt script execution to force the volume down?

Script to increase the volume for those interested:

repeat:
  sequence:
    - service: media_player.volume_set
      data:
        entity_id: "{{ player1 }}"
        volume_level: "{{ state_attr(player1, 'volume_level') + 0.01 }}"
    - delay:
        hours: 0
        minutes: 0
        seconds: 0
        milliseconds: 300
  while:
    - condition: template
      value_template: "{{ state_attr(player1, 'volume_level') < vol_target }}"

Script call:

player1: media_player.hall_google_home_mini
vol_target: 0.2
- service: script.turn_off
  target:
    entity_id: ...
1 Like

how easy was that! :wink:
Thank you.

1 Like