Can't get lights to flash properly

I’ve been playing around with:

and I can’t quite seem to get it to work the way that it should. When it tries to loop it errors out saying that the script is already running.

got this to work by creating two separate scripts, doesn’t feel like the greatest method tho

Care to share the scripts?

  flash_fire_alarm1:
    alias: Flash fire alarm loop 1
    sequence:
      - alias: Turn all lights on and to red loop 1
        service: homeassistant.turn_on
        data:
          entity_id: light.living_room_lamp
          brightness: 255
          rgb_color: [255,0,0]
      - delay:
          # time for flash light on
          seconds: 1
      - alias: Turn colored lights off loop 1
        service: homeassistant.turn_off
        data:
          entity_id: light.living_room_lamp
      - delay:
          # time for flash light off
          seconds: 1
      - alias: Move to loop 2
        service: script.turn_on
        data:
          entity_id: script.flash_fire_alarm2
  flash_fire_alarm2:
    alias: Flash fire alarm loop 2
    sequence:
      - alias: Turn all lights on and to red loop 2
        service: homeassistant.turn_on
        data:
          entity_id: light.living_room_lamp
          brightness: 255
          rgb_color: [255,0,0]
      - delay:
          # time for flash light on
          seconds: 1
      - alias: Turn colored lights off loop 2
        service: homeassistant.turn_off
        data:
          entity_id: light.living_room_lamp
      - delay:
          # time for flash light off
          seconds: 1
      - alias: Move back to loop 1
        service: script.turn_on
        data:
          entity_id: script.flash_fire_alarm1
1 Like

Here is how I coded my script loop (mine alternates green and red between 2 lights):

christmas_party:
  sequence:
    - service: light.turn_on
      entity_id: light.floor_lamp
      data:
        brightness: 255
        rgb_color: [255, 0, 0]
        transition: 0.5
    - service: light.turn_on
      entity_id: light.table_lamp
      data:
        brightness: 255
        rgb_color: [0, 255, 0]
        transition: 0.5
    - delay: 00:00:02
    - service: light.turn_on
      entity_id: light.floor_lamp
      data:
        brightness: 255
        rgb_color: [0, 255, 0]
        transition: 0.5
    - service: light.turn_on
      entity_id: light.table_lamp
      data:
        brightness: 255
        rgb_color: [255, 0, 0]
        transition: 0.5
    - service: script.turn_on
      entity_id: script.christmas_repeat

christmas_repeat:
  sequence:
    - delay: 00:00:02
    - service: script.turn_on
      entity_id: script.christmas_party

I read somewhere that the original example you linked used to work in old versions of HA. Logically, the script that is already on is calling itself to be on. Since it is already on, nothing happens.

As you have discovered, the new method is to create 2 scripts that call each other, creating the loop.

Yours obviously works, but if you want to change it in the future, you have to remember to make the change it in 2 locations.

4 Likes