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

@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!

4 Likes

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!

3 Likes

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

Great Blueprint @markus78 - I can see this being used in many of my automations.

With the idea of flashing my LED strip when the doorbell rings, am I correct in my thinking such that I need an automation to set my input boolean to “on” when the doorbell is pressed, eg:

alias: Set Doorbell_Pressed = ON when the doorbell is pressed
description: ''
trigger:
  - platform: device
    device_id: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    domain: nest
    type: doorbell_chime
condition: []
action:
  - service: input_boolean.turn_on
    target:
      entity_id: input_boolean.doorbell_pressed
  - delay:
      hours: 0
      minutes: 0
      seconds: 15
      milliseconds: 0
  - service: input_boolean.turn_off
    target:
      entity_id: input_boolean.doorbell_pressed
mode: single

This seems to successfully change the boolean value to ON, and keeps it on for 15 seconds before changing it back to OFF.

Then, I have another automation which is your blueprint that is triggered when my input_boolean.doorbell_pressed has changed to ON.

This seems to work well - when the doorbell is pressed, the lights flash on and off for 15 seconds, and the initial on/off state of the light is preserved, great! Can you confirm that this is the correct usage? Or did you design it in a way that could simplify my implementation?

Nice addition @avviano - I’m now able to specify that I would like my LED strip to flash specifically in RED.

Is it possible to use alternating colour into this? So for example to accommodate choosing 2 RGB colours, and respective Brightness. Then when the condition is triggered, it alternates (e.g. RED then BLUE and then continue the repeat / while block)

I’ll be honest, as a yaml noob, I thought I’d have a try but gave up after 10 minutes :frowning: - is this a possible feature that can be edited?

Hi, it may be possible to make the blinking turn on after a certain second interval?

@avviano & @markus78 - great work on this. It’s my first use of blueprints, and it looks like it could be very useful! I am intending to use this to ‘alert’ of different calls to action - ie doorbell/answer the front/back door, a meal is ready so come to eat, etc etc. Each circumstance uses lights which are already possibly in use.

I have found that if the lights are already on, and the boolean is turned off when the flashing is in the ‘off’ state, all works as it should.

However if the boolean is turned off when the flasher is in the ‘on’ state, the scene snapshot return doesn’t work, and the lights stay off - although the gui shows the light as having successfully returned to the snapshotted scene.

Also, if the lights are off but set to (eg) yellow, when a red flasher blueprint finishes, when the light is next turned on it will be red, not the previous colour.

Have i misunderstood the usage of this blueprint?

1 Like

This is a great blueprint! This is exactly what I have been looking for and my first attempt at using a blueprint. I edited the blueprint a little to use a binary_sensor (doorbell button) and I think that is what is causing my issue. In the original blueprint, the scene created is set to repeat as long as the input_boolean is set to “on”, am correct in how I’m reading this? If so, how can I define the repeat length to be selectable between 1-30 seconds or even just a set amount of time to repeat and then go to previous state?

I updated the blueprint. Now you are able the use any activated sensor and any individuel state. Additional you can set a max timeout. If this timeout is timeouted the blueprint stops also if the activated sensor is true. And last new feature you can now use a alternative light scene. For example if you want to flash your lights for max. 30 seconds than set ‘activated_timeout’ to 30. Hope that helps.

I’m fairly new to Blueprints. I have added it in, but in the options for the automation, I don’t see any field or drop down for RGB color choice or brightness. Was this removed in subsequent updates?

Has anyone updated their automation to include conditions for ‘which light’ you’re updating, based on condition? I’ve set up a crying sensor that kicks off from Alexa on IFTTT, and based on time of day, may want different lights to flash to alert me. I’ve taken the approach of creating two automations of of this blueprint, then having a conditional script change an input boolean to determine which one to trigger. This is cumbersome though and not the cleanest solution I’m sure.

@markus78
Would it be possible to update the blueprint with the changes that @avviano had suggested to include the brightness and RGB color options? I have tried to tweak my own blueprint and it seems to work, although I’m having some difficulty with it returning to the previous state (on/off, color, brightness level).

I believe that the scene.create does not capture the color or brightness settings when the light is off, so it seems possible to briefly turn the light on to grab these attributes before making changes, as suggested in this thread. (Return light to previous state after automation - #6 by Speezle)
Any chance you’d be able to incorporate this into the blueprint? Thanks!

This blueprint runs once then doesn’t run again

hey man, first of all thanks alot for this brilliant code! Everything seems to be working, until the moment where all (yes literally, all) lights are enabled, instead of the ones that i’ve selected. Have you come across this already?

code

edit: so i’ve been delving in this automation and it looks to be the case that this automation snapshots every light in my house. Would it be possible to add the option where i can choose/select the entity that i want snapshotted?

I’m experiencing this behaviour.

Thank you Markus. This could save my marriage! Not really but could help reduce stress and improve WAF. I have a media room (soon to be) that is where I spend a lot of time on my computer and doing electronics ‘stuff’. The room is well soundproofed and one floor away from wife’s main turf. You get the idea.
I had something mocked up in seconds!

Q

thank you @markus78 i really enjoy your blueprint. I just met an unwanted behaviour, the automation in my use case may run for a long time, and i noticed that the log is flooded by a lot of INFO from automation. this goes for days until my HA stops responding and i have to reboot it.

here some [INFO] example from my log, anyone knows how to reduce the log writing ?

2023-08-01 21:46:21.735 INFO (MainThread) [homeassistant.components.automation.app_bp_flash_lavatrice] APP - BP - Flash Lavatrice: Choose at step 2: choice 2: Repeat at step 1: Executing step call service

2023-08-01 21:46:21.743 INFO (MainThread) [homeassistant.components.automation.app_bp_flash_lavatrice] APP - BP - Flash Lavatrice: Choose at step 2: choice 2: Repeat at step 1: Executing step delay 0:00:01.500000

2023-08-01 21:46:23.247 INFO (MainThread) [homeassistant.components.automation.app_bp_flash_lavatrice] APP - BP - Flash Lavatrice: Choose at step 2: choice 2: Repeating sequence: Iteration 1671

2023-08-01 21:46:23.248 INFO (MainThread) [homeassistant.components.automation.app_bp_flash_lavatrice] APP - BP - Flash Lavatrice: Choose at step 2: choice 2: Repeat at step 1: Running automation actions

2023-08-01 21:46:23.249 INFO (MainThread) [homeassistant.components.automation.app_bp_flash_lavatrice] APP - BP - Flash Lavatrice: Choose at step 2: choice 2: Repeat at step 1: Executing step call service

2023-08-01 21:46:23.250 WARNING (MainThread) [homeassistant.helpers.service] Unable to find referenced entities scene.lavatrice or it is/they are currently not available

2023-08-01 21:46:23.255 INFO (MainThread) [homeassistant.components.automation.app_bp_flash_lavatrice] APP - BP - Flash Lavatrice: Choose at step 2: choice 2: Repeat at step 1: Executing step delay 0:00:01.500000