Script question: stop running instance by condition?

Hi all:

I have made a generic script to do colour transition for my lights at home, and since it’s generic I set mode=parallel so multiple instances of the script can run in parallel for multiple rooms. However what I’m really looking after is “mode=restart” for the same room, but allow multiple rooms to run in parallel. I’m aware it is not supported out of box, is there a way for me to tag a running instance of script and later in another instance to stop it? Or please suggest if there is a better way to achieve this?

Appreciate your input!

Any idea how to workaround it? Thanks

How should we have any opinions when what you ask for does not exist and we have not seen the script you are talking about.

Hi ok sorry for the unclear question, below is the script I have made:

alias: Lighting Transition
mode: parallel
fields:
  rooms:
    description: List of light entity IDs (e.g., ['bedroom', 'livingroom'])
    example: "['bedroom']"
    required: true
  start_hsb:
    description: Optional starting HSB color as [hue, saturation, brightness]
    example: "[40, 60, 40]"
    required: false
    default: []
  end_hsb:
    description: Final HSB color as [hue, saturation, brightness]
    example: "[20, 90, 1]"
    required: true
  transition:
    description: Transition time in seconds
    example: 100
    required: true
    default: 120
sequence:
  - choose:
      - conditions:
          - condition: template
            value_template: "{{ start_hsb | length == 3 }}"
        sequence:
          - repeat:
              for_each: "{{ rooms }}"
              sequence:
                - target:
                    entity_id: light.{{ repeat.item }}
                  data:
                    hs_color:
                      - "{{ start_hsb[0] | int }}"
                      - "{{ start_hsb[1] | int }}"
                    brightness: "{{ start_hsb[2] | int }}"
                  action: light.turn_on
  - repeat:
      for_each: "{{ rooms }}"
      sequence:
        - target:
            entity_id: light.{{ repeat.item }}
          data:
            hs_color:
              - "{{ end_hsb[0] | int }}"
              - "{{ end_hsb[1] | int }}"
            brightness: "{{ end_hsb[2] | int }}"
            transition: "{{ transition }}"
          action: light.turn_on
  - choose:
      - conditions:
          - condition: template
            value_template: "{{ end_hsb[2] | int == 1 }}"
        sequence:
          - delay:
              seconds: "{{ transition | int + 1 }}"
          - repeat:
              for_each: "{{ rooms }}"
              sequence:
                - target:
                    entity_id: light.{{ repeat.item }}
                  action: light.turn_off
description: ""

The idea is to have a generic script that allows light to transit from one colour to another, primary use-case is to simulate wake-up sunrise and sunset (lights fade off). Since it’s generic it runs in parallel for all rooms, however due to the limit of turn_off doesn’t support colour transition I made a workaround to change to brightness 1 then turn off, that mean the script has a delay element. If the same room starts sunset, and later runs it again, since 2 instances are running in parallel the previous turn_off will interrupt the 2nd run.

Yeah I know it’s a rare case but I’m still learning HA so would like to try all techy challenges :slight_smile: