Simple ... flashing light's via on off and delay. Restore previous light states

Tags: #<Tag:0x00007fc4194f9f40> #<Tag:0x00007fc4194f9e78>

This is a simple blueprint for flashing light’s via on/off and delay. Activated and deactived via input_boolean and restore previous light state.

Link to Blueprint: https://github.com/myGithub-Markus/home-assistant_blueprints/blob/main/flashing_lights.yaml

blueprint:
  name: flashing lights
  description: >
     Flashing lights via on off and delay and finally restore the previous light states.
  domain: automation
  source_url: https://github.com/myGithub-Markus/home-assistant_blueprints/edit/main/flashing_lights.yaml
  input:
    activated:
        name: Activated
        description: "Toggle to activated or deactivated flashing. E.g. for fire alarm"
        selector:
            entity:
                domain: input_boolean
    target_lights:
        name: Lights
        description: "To flashing lights"
        selector:
          target:
            entity:
              domain: light
    delay:
      name: (OPTIONAL) Delay
      description: "Delay flashing lights"
      default: 1000
      selector:
        number:
          min: 0
          max: 20000
          unit_of_measurement: milliseconds

mode: restart
max_exceeded: silent

trigger:
  - platform: state
    entity_id: !input activated
    to: 'on'

variables:
  activated: !input activated
  delay: !input delay
  target_lights: !input target_lights

condition: []

action:
  - service: scene.create
    data:
        scene_id: all_lights_snapshot
        snapshot_entities: >
               {% set lights = states.light
                 | map(attribute='entity_id') | join(',') %}
                 {{lights}}
  - service: light.turn_on
    target: !input target_lights
  - repeat:
      while:
      - condition: template
        value_template: "{{ activated == none or is_state(activated, 'on') }}"
      sequence:
      - delay: 
          milliseconds: "{{ delay }}"
      - service: light.toggle
        target: !input target_lights
  - service: scene.turn_on
    data:
      entity_id: scene.all_lights_snapshot

Preview Blueprint Automation GUI

3 Likes

This is very useful, thank you!

I installed it and noticed that it only works with entity types : light. I adapted this to show also type: switch but it did not work (although the entities -> switch can be selected). Any clue what more we need to adapt to the script? Thanks in advance!

Could this be set to select a red colour and flash it?

Could. When it wouldn’t be buggy.

I’m still pretty new but under “Activated” I cant choose anything to trigger the flashing. I want to choose my doorbell here.

same. nothing is showing up on mine either.

the current blueprint only supports input_boolean under “Activated”. So if you configured any input_boolean it should be available under Activated.

input_boolean:
  flashing_lights:
    name: Activated and deactivated flashing lights
- id: '4711'
  alias: flashing lights
  description: ''
  use_blueprint:
    path: .../flashing_lights.yaml
    input:
      delay: '1000'
      activated: input_boolean.flashing_lights
      target_lights:
        entity_id: light.all_indoor

Brilliant - thank you!

Many thanks for it! it’s very useful for me since I’m deaf and I use this to trigger light when the doorbell is pressed.

If I understand the flashing count is based on how long the status is “on” + delay?

However is there a possibility to configure counts of flashing because I would love to determine source/trigger based on count of flashing.
For example:
Doorbell = 3 times
Fire alarm = 6 times
burglar alarm = 10 times

1 Like

Markus78 I use your blueprint choosing a device to activate the flashing light. It worked but the only way to stop it was stopping the automation. Then I create an input_boolean and modified the automation including also the delay. No results. Can you please help me to understand how it works and how to fix it in order to stop after a certain time or event? Thanks

@markus78, I have one idea to work around the issue of restoring light states when some lights are off:

  1. Save the state as scene_old.
  2. Turn on all the lights configured in the automation.
  3. Wait a short delay to make sure they are turned on.
  4. Save the state as scene_on.
  5. Continue the blinking light automation/blueprint as normal. Go nuts!
  6. Wait a short delay before activating any scene.
  7. Activate scene_on.
  8. Wait another short delay before activating another scene.
  9. Activate scene_old.
  10. END

This should make sure the “off” state is correctly saved and restored, because the on/off state is saved first, then the light properties are saved next; and they are restored in reverse order. In theory, because I haven’t tested it myself (and I likely won’t test any time soon). So, if this solution sounds plausible, please test if it works.

My only suggestion is the “short delay” should be an input variable with a default value. The default delay should work for most people, but being a parameter lets each person to fine-tune it to their setup.

I added a RGB name and brigthness selector to the blueprint for those who would like to use it on LED RGB lights. The RGB works fine, not sure about the brightness, still have to do some tests.

blueprint:
  name: flashing lights
  description: 'Flashing lights via on off and delay and finally restore the previous
    light states.

    '
  domain: automation
  source_url: https://community.home-assistant.io/t/simple-flashing-lights-via-on-off-and-delay-restore-previous-light-states/258099
  input:
    activated:
      name: Activated
      description: Enter the Entity Name for Trigger (On-Off)
      selector:
        entity:
          domain: input_boolean
    target_lights:
      name: Lights
      description: To flashing lights
      selector:
        target:
          entity:
            domain: light
    color_rgb:
      name: RGBColor
      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_rgb:
      name: (OPTIONAL) Light Brightness
      description: Color Brigthness between 0 to 255
      selector:
        number:
          min: 0
          max: 255
          unit_of_measurement: RGB
          step: 1.0
          mode: slider
    delay:
      name: (OPTIONAL) Delay
      description: Delay flashing lights
      default: 1000
      selector:
        number:
          min: 0.0
          max: 20000.0
          unit_of_measurement: milliseconds
          step: 1.0
          mode: slider
mode: restart
max_exceeded: silent
trigger:
- platform: state
  entity_id: !input 'activated'
  to: 'on'
variables:
  activated: !input 'activated'
  delay: !input 'delay'
  target_lights: !input 'target_lights'
condition: []
action:
- 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: !input 'brightness_rgb'
- repeat:
    while:
    - condition: template
      value_template: '{{ activated == none or is_state(activated, ''on'') }}'
    sequence:
    - delay:
        milliseconds: '{{ delay }}'
    - service: light.toggle
      target: !input 'target_lights'
- service: scene.turn_on
  data:
    entity_id: scene.all_lights_snapshot

You can add whatever color names you like (as long as they are CSS color names). A full list of color names can be found here (make sure they are written small caps).

CSS Color Names

Cheers!

1 Like

Tried this, but it doesn’t display and trigger entity’s for me. The dropdown list is empty. Any suggestions?

You’re probably trying to call “switches” not “lights”. For switches to show up in the selector, you need to define the switches as lights first. You can do so in the configuration.yaml in a very simple manner. See code below. Just add the entity name of your switches and under name you can add whatever you want. It’s probably a good idea to add all your switches here which are in fact switches that turn on lights. Test your config and then restart your server and the entities should show up in scripts or automations aso that need lights as entity or device inputs. Hope that helps!

# Tell Home Assistant that the following switches are lights, so they appear in script and other GUIs
light:
  - platform: switch
    name: Enter Name Here01
    entity_id: switch.sonoff_yourswitchentity01
  - platform: switch
    name: Enter Name Here02
    entity_id: switch.sonoff_yourswitchentity02
  - platform: switch
    name: Enter Name Here03
    entity_id: switch.sonoff_yourswitchentity03

That should do the trick.

Hope you have a great day!
Cheers!

1 Like

Hi, great suggestion! Having the same issue, could you please provide more instructions on how i can do this? (fairly new to it all)

I think you can start with the official documentation: Automating Home Assistant - Home Assistant