Returning to previous state after automation

Hey,

I want my living room lights to flash red at midnight, and go back to their original state after the automation.

I followed the instructions given on the top comment at Return light to previous state after automation, where I create a scene first, then flash the lights and finally go back to the state I created at the beginning. However my automation flashes the lights red, but fails to return to the previous state.

I am adding my snippet below, can someone point out to my mistake please?
Thanks!

Edit: I should also mention that the scene I create here is accessible from the Scenes menu and when I execute it it exactly does what I intend it to do, so no issue with scene creation part I think.

- id: '2'
  alias: Flash red lights at midnight
  trigger:
  - platform: time
    at: '23:59'
  condition: []
  action:
  - service: scene.create
    data:
      scene_id: lights_previous_state
      snapshot_entities: 'light.salon_2_light,light.salon_1_light'
  - service: light.turn_on
    data:
      entity_id: light.salon_1_light
      brightness: 130
      flash: long
      rgb_color:
      - 255
      - 0
      - 0
  - service: light.turn_on
    data:
      entity_id: light.salon_2_light
      brightness: 130
      flash: long
      rgb_color:
      - 255
      - 0
      - 0
  - service: scene.turn_on
    data:
      entity_id: scene.lights_previous_state

To answer my own question, using the “state” object directly after a delay, instead of using the scene.turn_on did the trick:

  • delay: ‘00:00:05’
  • scene: scene.lights_previous_state

Thanks!

3 Likes

Hi. Looking to do something similar. Does this create a new scene every night, though? Do you slowly accumulate lots of scenes? Would it be possible to delete the scene in the same script, do you think?

Hello,
I have try the following code:

alias: Licht blinken (blau) wenn es regnet
trigger:
  - platform: numeric_state
    entity_id: automation.regen_aktuell
    above: '0'
action:
  - service: scene.create
    data:
      scene_id: lights_previous_state
      snapshot_entities: light.mondo_wand
  - service: light.turn_on
    data:
      brightness: 130
      flash: long
      rgb_color:
        - 0
        - 17
        - 255
    target:
      entity_id: light.mondo_wand
  - service: light.turn_on
    data:
      brightness: 130
      flash: long
      rgb_color:
        - 0
        - 17
        - 255
    target:
      entity_id: light.mondo_wand
    enabled: false
  - service: scene.turn_on
    data:
      entity_id: scene.lights_previous_state

But the color change don´t work. But the light flashes with the last used color.

What make I wrong?

No one an idea?