Script Blueprint to flash a custom color light a x amount of times and restore its previous state

This blueprint will create a script that flashes some lights a certain amount of times and restores them at their previous state.

You can customize the number of flashes, color, brightness and the delay between each light.toggle action.

This was inspired by @markus78 's blueprint simple-flashing-lights-via-on-off-and-delay-restore-previous-light-states

blueprint:
  name: Flash lights
  description: Create a script that flashes lights and restore them at their previous state.
  domain: script
  input:
    target_lights:
      name: Lights
      description: Lights to flash
      selector:
        target:
          entity:
            domain: light
    number_of_times:
      name: Number of times to flash
      description: How many times to flash the lights
      selector:
        number:
          min: 0
          max: 100
          mode: box
          unit_of_measurement: times    
    color_rgb:
      name: RGB Color
      description: Choose the color for blinking lights
      selector:
        select:
          options:
            - white   
            - red
            - green
            - lime
            - blue
            - navy
            - yellow
            - orange
            - turquoise
            - violet
            - magenta
            - aliceblue
            - antiquewhite
            - aquamarine
            - aqua
            - cadetblue
            - coral
            - cornflowerblue
            - crimson
            - darkblue
            - darkorange
            - darkorchid
            - darksalmon
            - darkslategray
            - deeppink
            - darkviolet
            - deepskyblue
            - ghostwhite
            - gold
            - lawngreen
            - lightcoral
            - lightgreen
            - lightseagreen
    brightness_pct:
      name: Brightness
      description: Color Brightness percentage
      selector:
        number:
          min: 0
          max: 100
          unit_of_measurement: '%'
          step: 1.0
          mode: slider
    delay:
      name: (OPTIONAL) Delay
      description: Delay flashing lights 1s=1000ms
      default: 1000
      selector:
        number:
          min: 0.0
          max: 20000.0
          unit_of_measurement: ms
          step: 1.0
          mode: slider
mode: restart
max_exceeded: silent
sequence:
- service: scene.create
  data:
    scene_id: all_lights_snapshot
    snapshot_entities: "{% set lights = states.light\n  | map(attribute='entity_id')\
      \ | join(',') %}\n  {{lights}}\n"
- service: light.turn_on
  target: !input 'target_lights'
  data:
    color_name: !input 'color_rgb'
    brightness_step_pct: !input 'brightness_pct'
- repeat:
    count: !input 'number_of_times'
    sequence:
    - service: light.toggle
      data: {}
      target: !input 'target_lights'
    - delay:
            hours: 0
            minutes: 0
            seconds: 1
            milliseconds: 500
    - service: light.toggle
      data: {}
      target: !input 'target_lights'
    - delay:
            hours: 0
            minutes: 0
            seconds: 1
            milliseconds: 500
- service: scene.turn_on
  data:
    entity_id: scene.all_lights_snapshot

preview:

2 Likes

Hi. I have been using this for an indicator light in my kitchen that flashes when my boiler turns on.

The same script runs a few times a day. Every so often, however, the snapshot reset step seems to turn on every smart light in my house, rather than just return the indicator light to the previous state. I can see this in the logs for any of these accidentally toggled lights but only one device is defined in the blueprint script that triggers them.

Any ideas whether this snapshot step can lose the device id and just activate light entity types?

The blueprint creates a snapshot of all lights in your house.

Ideally it should create a snapshot of only the lights that will be flashed (not all lights).

Exactly… it’s possible to take a snapshot of just a bunch of lights but unfortunately i don’t know how to pass them from the blueprint interface to the template that creates the snapshot.

I’ve this Blueprint to blinking lights:

Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.

it will blink lights. You will have some configurable parameters like number of blinks, time for each light status change and the scene to activate before (it’s very useful if you need to have a specific color).

I use it with Alarmo actions to blink internal and external lights if the alarm is triggered.

1 Like

How can i use this code in home assistan?

Like this:

1 Like

Maybe you can replace:

snapshot_entities with: {{ (states.light|selectattr('state','eq','on')|rejectattr('attributes.hue_type', 'in', ['room', 'zone'])|map(attribute='entity_id')|list+['light.dummy'])|join(',') }}

This should only take a snapshot from lights which are on and don’t touch lights which are off.

Unfortunately this blueprint works only with lights which are turned on. Lights which are turned off will not flash.