Flashing Lights Script

Hi everyone,

I’d like to share my flashing lights script which is based upon Rschuttes automation blueprint which did the same thing, this is essentially most of that but as a script rather than an automation.

Features:

  • Blink Your Lights: Select specific lights to blink in a chosen color.
  • Customizable Blinking:
    • Choose how many times the lights blink.
    • Set how long each blink lasts.
    • Option to turn the lights off between blinks or keep their original color.
  • Custom Transition Times:
    • Override default device transition settings with a specified transition length, ensuring smooth and visible blinking effects.
sequence:
  - action: scene.create
    metadata: {}
    data:
      scene_id: flash_restore_state
      snapshot_entities: "{{ light_selection }}"
    alias: Save a restore point for the selected lights
  - alias: Flash the lights the selected number of times
    repeat:
      count: "{{ flash_lights_count }}"
      sequence:
        - action: light.turn_on
          metadata: {}
          data:
            rgb_color: "{{ flash_lights_color }}"
            brightness_pct: "{{ flash_brightness }}"
            transition: "{{ transition_length }}"
          target:
            entity_id: "{{ light_selection }}"
          alias: Flash the selected light a chosen color and brightness
        - delay: "{{ flash_duration }}"
          alias: The selected delay between flashes
        - alias: Flash from off or the original state of the lights
          choose:
            - conditions:
                - condition: template
                  value_template: "{{ flash_from_off }}"
                  alias: Flashing the lights from an off state was requested
              sequence:
                - action: light.turn_off
                  metadata: {}
                  data:
                    transition: "{{ transition_length }}"
                  target:
                    entity_id: "{{ light_selection }}"
                  alias: Turn off the selected lights
            - conditions:
                - condition: template
                  value_template: "{{ not flash_from_off }}"
                  alias: Flashing the lights from the original state was requested
              sequence:
                - action: scene.turn_on
                  metadata: {}
                  data: {}
                  target:
                    entity_id: scene.flash_restore_state
                  alias: Restore the original state of the lights
        - delay: "{{ flash_duration }}"
          alias: The selected delay between flashes
  - action: scene.turn_on
    metadata: {}
    data: {}
    target:
      entity_id: scene.flash_restore_state
    alias: Restore the original state of the lights
  - alias: Delete the saved light scene
    action: scene.delete
    metadata: {}
    data: {}
    target:
      entity_id: scene.flash_restore_state
fields:
  light_selection:
    name: 💡 Light Selection
    description: Select which lights to flash
    selector:
      entity:
        multiple: true
        domain: light
    required: true
  flash_lights_color:
    selector:
      color_rgb: {}
    name: 🎨 Flash Lights Color
    description: What color should the lights flash?
    default:
      - 0
      - 0
      - 0
    required: true
  flash_brightness:
    selector:
      number:
        min: 1
        max: 100
        step: 1
    name: 🌞 Flash Brightness
    description: How bright should the flash be?
    default: 90
    required: true
  flash_lights_count:
    selector:
      number:
        min: 1
        max: 15
        step: 1
    name: 🔢 Flash Lights Count
    description: How many times should the lights flash?
    required: true
    default: 10
  flash_duration:
    selector:
      number:
        min: 0.1
        max: 5
        step: 0.1
    name: ⏱️ Flash Duration
    description: Length of time between flashes (in seconds)
    default: 1
    required: true
  flash_from_off:
    selector:
      boolean: {}
    name: 🌙 Flash From Off
    description: Should the lights turn off between flashes?
    default: true
    required: false
  transition_length:
    selector:
      number:
        min: 0
        max: 5
        step: 0.1
    name: 🔁 Transition Length
    description: Set a custom transition time for the lights (In seconds)
    default: 0.3
    required: true
alias: Flash the Selected Lights
description: >-
  Flash the selected lights from either the current or off state then return to
  the original lighting scene
mode: restart

2 Likes

Getting a “No valid blueprint found in the topic. Blueprint syntax blocks need to be marked as YAML or no syntax.” so I’m presuming it hasn’t liked the reference. I’m very new to sharing my scripts and making them to be fair.

I copied the direct link to the post without success, i think its looking for a specific formatting? I’ll need to do a bit of reading on how to do that. This is just a straight script for people at the moment.

Still get an error when trying to import it myself I’ll try again later tonight

Didn’t know that existed but yeah it would be better. I don’t have permission to delete this though :frowning: I’d need to delete the other ones i posted too.

Works great, thank you!

1 Like

Thanks for the script!

For some reason, the script wouldn’t restore the state if the lights were in an off state to begin with, so if I flashed them green, it would turn the lights back off, but when I would normally turn them back on, they would be green.

The workaround I found for this is to turn them on initially and turn them off if the state was off to begin with.

sequence:
  - variables:
      original_state: "{{ states(light_selection) }}"
    alias: Save initial state
  - action: light.turn_on
    metadata: {}
    data: {}
    target:
      entity_id: "{{ light_selection }}"
    enabled: true
    alias: Turn on the lights
  - action: scene.create
    metadata: {}
    data:
      scene_id: flash_restore_state
      snapshot_entities: "{{ light_selection }}"
    alias: Save a restore point for the selected lights
  - alias: Flash the lights the selected number of times
    repeat:
      count: "{{ flash_lights_count }}"
      sequence:
        - action: light.turn_on
          metadata: {}
          data:
            rgb_color: "{{ flash_lights_color }}"
            brightness_pct: "{{ flash_brightness }}"
            transition: "{{ transition_length }}"
          target:
            entity_id: "{{ light_selection }}"
          alias: Flash the selected light a chosen color and brightness
        - delay: "{{ flash_duration }}"
          alias: The selected delay between flashes
        - alias: Flash from off or the original state of the lights
          choose:
            - conditions:
                - condition: template
                  value_template: "{{ flash_from_off }}"
                  alias: Flashing the lights from an off state was requested
              sequence:
                - action: light.turn_off
                  metadata: {}
                  data:
                    transition: "{{ transition_length }}"
                  target:
                    entity_id: "{{ light_selection }}"
                  alias: Turn off the selected lights
            - conditions:
                - condition: template
                  value_template: "{{ not flash_from_off }}"
                  alias: Flashing the lights from the original state was requested
              sequence:
                - action: scene.turn_on
                  metadata: {}
                  data: {}
                  target:
                    entity_id: scene.flash_restore_state
                  alias: Restore the original state of the lights
        - delay: "{{ flash_duration }}"
          alias: The selected delay between flashes
  - action: scene.turn_on
    metadata: {}
    data: {}
    target:
      entity_id: scene.flash_restore_state
    alias: Restore the original state of the lights
  - alias: Delete the saved light scene
    action: scene.delete
    metadata: {}
    data: {}
    target:
      entity_id: scene.flash_restore_state
    enabled: true
  - condition: template
    value_template: "{{ original_state == 'off' }}"
    alias: Test if lights were initially off
  - action: light.turn_off
    metadata: {}
    data: {}
    target:
      entity_id: "{{ light_selection }}"
    alias: Turn off the lights
fields:
  light_selection:
    name: 💡 Light Selection
    description: Select which lights to flash
    selector:
      entity:
        multiple: false
        domain: light
    required: true
  flash_lights_color:
    selector:
      color_rgb: {}
    name: 🎨 Flash Lights Color
    description: What color should the lights flash?
    default:
      - 0
      - 0
      - 0
    required: true
  flash_brightness:
    selector:
      number:
        min: 1
        max: 100
        step: 1
    name: 🌞 Flash Brightness
    description: How bright should the flash be?
    default: 90
    required: true
  flash_lights_count:
    selector:
      number:
        min: 1
        max: 15
        step: 1
    name: 🔢 Flash Lights Count
    description: How many times should the lights flash?
    required: true
    default: 10
  flash_duration:
    selector:
      number:
        min: 0.1
        max: 5
        step: 0.1
    name: ⏱️ Flash Duration
    description: Length of time between flashes (in seconds)
    default: 1
    required: true
  flash_from_off:
    selector:
      boolean: {}
    name: 🌙 Flash From Off
    description: Should the lights turn off between flashes?
    default: true
    required: false
  transition_length:
    selector:
      number:
        min: 0
        max: 5
        step: 0.1
    name: 🔁 Transition Length
    description: Set a custom transition time for the lights (In seconds)
    default: 0.3
    required: true
alias: Flash the Selected Lights
description: >-
  Flash the selected lights from either the current or off state then return to
  the original lighting scene
mode: restart

There’s probably a more elegant way to go about this, but this is what I could come up with in case someone else had a similar issue.

Just tried this and It’s showing as the colour i selected if i manually turn them back on after still, I’ll play around with it some more

Hi. This seems the most current flashing light blueprint. Above, there’s some discussion of getting it to import. I can’t see a solution and when I import from this thread’s URL I get the same error as in post #2. Is it importable yet, or how do I use this?

I’m looking for a script with infinite flashing - stay flashing until I turn it off. Can this blueprint do that?
Thanks!

Hey, it’s a script, not a blueprint so just copy it, open a new script, edit the script via yaml and paste it in.

This script works great when using one light, but anytime I add more than 1 light I receive the error - “Failed to perform the action script/flash_lights. TypeError: unhashable type: ‘list’”
I’m lost as to how to resolve this - any guidance would be appreciated!

Weird, i can flash multiple lights with it. How are you adding the multiple, are you selecting them individually or as a group?

I’ve used the selector on the script page, and have tried adding two individual lights; a single light and a group of lights; two groups… all with the same message.
Here is the code for the script - if I take out either of those lights (and change multiple to false) everything works as expected…
Appreciate any insights you may have

sequence:
  - variables:
      original_state: "{{ states(light_selection) }}"
    alias: Save initial state
  - action: light.turn_on
    metadata: {}
    data: {}
    target:
      entity_id: "{{ light_selection }}"
    enabled: true
    alias: Turn on the lights
  - action: scene.create
    metadata: {}
    data:
      scene_id: flash_restore_state
      snapshot_entities: "{{ light_selection }}"
    alias: Save a restore point for the selected lights
  - alias: Flash the lights the selected number of times
    repeat:
      count: "{{ flash_lights_count }}"
      sequence:
        - action: light.turn_on
          metadata: {}
          data:
            rgb_color: "{{ flash_lights_color }}"
            brightness_pct: "{{ flash_brightness }}"
            transition: "{{ transition_length }}"
          target:
            entity_id: "{{ light_selection }}"
          alias: Flash the selected light a chosen color and brightness
        - delay: "{{ flash_duration }}"
          alias: The selected delay between flashes
        - alias: Flash from off or the original state of the lights
          choose:
            - conditions:
                - condition: template
                  value_template: "{{ flash_from_off }}"
                  alias: Flashing the lights from an off state was requested
              sequence:
                - action: light.turn_off
                  metadata: {}
                  data:
                    transition: "{{ transition_length }}"
                  target:
                    entity_id: "{{ light_selection }}"
                  alias: Turn off the selected lights
            - conditions:
                - condition: template
                  value_template: "{{ not flash_from_off }}"
                  alias: Flashing the lights from the original state was requested
              sequence:
                - action: scene.turn_on
                  metadata: {}
                  data: {}
                  target:
                    entity_id: scene.flash_restore_state
                  alias: Restore the original state of the lights
        - delay: "{{ flash_duration }}"
          alias: The selected delay between flashes
  - action: scene.turn_on
    metadata: {}
    data: {}
    target:
      entity_id: scene.flash_restore_state
    alias: Restore the original state of the lights
  - alias: Delete the saved light scene
    action: scene.delete
    metadata: {}
    data: {}
    target:
      entity_id: scene.flash_restore_state
    enabled: true
  - condition: template
    value_template: "{{ original_state == 'off' }}"
    alias: Test if lights were initially off
  - action: light.turn_off
    metadata: {}
    data: {}
    target:
      entity_id: "{{ light_selection }}"
    alias: Turn off the lights
fields:
  light_selection:
    selector:
      entity:
        multiple: true
        domain: light
    default:
      - light.office_ceiling_light
      - light.guestroom_ceiling_light
  flash_lights_color:
    selector:
      color_rgb: {}
    name: 🎨 Flash Lights Color
    description: What color should the lights flash?
    default:
      - 0
      - 0
      - 0
    required: true
  flash_brightness:
    selector:
      number:
        min: 1
        max: 100
        step: 1
    name: 🌞 Flash Brightness
    description: How bright should the flash be?
    default: 90
    required: true
  flash_lights_count:
    selector:
      number:
        min: 1
        max: 15
        step: 1
    name: 🔢 Flash Lights Count
    description: How many times should the lights flash?
    required: true
    default: 10
  flash_duration:
    selector:
      number:
        min: 0.1
        max: 5
        step: 0.1
    name: ⏱️ Flash Duration
    description: Length of time between flashes (in seconds)
    default: 1
    required: true
  flash_from_off:
    selector:
      boolean: {}
    name: 🌙 Flash From Off
    description: Should the lights turn off between flashes?
    default: true
    required: false
  transition_length:
    selector:
      number:
        min: 0
        max: 5
        step: 0.1
    name: 🔁 Transition Length
    description: Set a custom transition time for the lights (In seconds)
    default: 0.3
    required: true
alias: flash_lights
description: >-
  Flash the selected lights from either the current or off state then return to
  the original lighting scene
mode: restart

I’m not sure if this was the reason the people below and I were having issues running the script, but… I’ve migrated it to the latest blueprint syntax, and it’s working great for me as below:

mode: restart

blueprint:
  domain: script
  name: Blink some lights
  description: >-
    Flash the selected lights from either the current or off state then return to
    the original lighting scene.
    
  source_url: https://community.home-assistant.io/t/flashing-lights-script/827417/21?u=igorsantos07

  input:
    light_entities:
      name: 💡 Light entities
      description: Select which lights to flash
      selector:
        entity:
          multiple: true
          domain: light
      
    flash_lights_color:
      selector:
        color_rgb: {}
      name: 🎨 Lights color
      description: What color should the lights flash?
      default:
        - 0
        - 0
        - 0
      
    flash_brightness:
      selector:
        number:
          min: 0.5
          max: 100
          step: 0.5
      name: 🌞 Final brightness
      description: How bright should the flash be?
      default: 90
      
    flash_lights_count:
      selector:
        number:
          min: 1
          max: 50
          step: 1
      default: 10
      name: 🔆 Blinking count
      description: How many times should the lights flash?
      
    flash_duration:
      selector:
        number:
          min: 0.1
          max: 5
          step: 0.1
      default: 1
      name: ⏱️ Flash duration
      description: How many seconds between flashes?
      
    flash_from_off:
      selector:
        boolean: {}
      name: 🌙 Flash from off
      description: Should the lights turn off between flashes, or flash from the original state?
      default: true
      
    transition_length:
      selector:
        number:
          min: 0
          max: 5
          step: 0.1
      name: 🔁 Transition time
      description: How many seconds between the off/original state and the final brightness?
      default: 0.3
      

sequence:
  - alias: Save a restore point for the selected lights
    action: scene.create
    metadata: {}
    data:
      scene_id: flash_restore_state
      snapshot_entities: !input light_entities
      
  - alias: Flash the lights the selected number of times
    repeat:
      count: !input flash_lights_count
      sequence:
        - alias: Flash the selected light a chosen color and brightness
          action: light.turn_on
          metadata: {}
          data:
            rgb_color: !input flash_lights_color
            brightness_pct: !input flash_brightness
            transition: !input transition_length
          target:
            entity_id: !input light_entities
        - alias: The selected delay between flashes
          delay: !input flash_duration
        - alias: Flash from off or the original state of the lights
          choose:
            - conditions:
                - condition: template
                  value_template: !input flash_from_off
                  alias: Flashing the lights from an off state was requested
              sequence:
                - action: light.turn_off
                  metadata: {}
                  data:
                    transition: !input transition_length
                  target:
                    entity_id: !input light_entities
                  alias: Turn off the selected lights
            - conditions:
                - condition: template
                  value_template: "{{ not flash_from_off }}"
                  alias: Flashing the lights from the original state was requested
              sequence:
                - action: scene.turn_on
                  metadata: {}
                  data: {}
                  target:
                    entity_id: scene.flash_restore_state
                  alias: Restore the original state of the lights
        - delay: !input flash_duration 
          alias: The selected delay between flashes
          
  - alias: Restore the original state of the lights
    action: scene.turn_on
    metadata: {}
    data: {}
    target:
      entity_id: scene.flash_restore_state
      
    
  - alias: Delete the saved light scene
    action: scene.delete
    metadata: {}
    data: {}
    target:
      entity_id: scene.flash_restore_state