Returning lights to previous state with scene not working

Hi,

I’m rather new to HA. I followed this youtube to create an automation, and then go to the previous state on some lightening.
This resulted in the following code …

if:
  - condition: trigger
    id:
      - Keuken Beweging
then:
  - service: scene.create
    data:
      scene_id: memory
      snapshot_entities:
        - light.hue_lightstrip_plus_2_links
        - light.hue_lightstrip_plus_rechts
        - light.hue_go_1_keuken
        - light.hue_color_lamp_keuken
        - light.hue_smart_plug_1
  - service: light.turn_on
    metadata: {}
    data:
      transition: 10
      kelvin: 4835
      brightness_pct: 100
    target:
      entity_id:
        - light.hue_lightstrip_plus_2_links
        - light.hue_lightstrip_plus_rechts
  - service: light.turn_on
    metadata: {}
    data: {}
    target:
      entity_id: light.hue_smart_plug_1
  - service: light.turn_on
    metadata: {}
    data:
      transition: 10
      rgb_color:
        - 207
        - 139
        - 23
      brightness_pct: 100
    target:
      entity_id: light.hue_go_1_keuken
  - service: light.turn_on
    metadata: {}
    data:
      transition: 10
      rgb_color:
        - 207
        - 139
        - 23
      brightness_pct: 100
    target:
      entity_id:
        - light.hue_color_lamp_keuken
else:
  - service: scene.turn_on
    data:
      transition: 10
    target:
      entity_id: scene.memory

Now the on/off and brighteness values are stored correctly in the ‘memory’ scene.
However, the colors stored are the ones assigned in the script.
How is this possible, the script is run top to bottom, right?

Regards,
Gunther.

Hi Gunther,

I don’t know the exact answer, but I’ve heard this question before. So I did this Search in my search engine and saw many other posts about the subject.
I believe your answer is in there somewhere.

site:home-assistant.io scene not saving colors

How long are saved scenes kept for?

I can’t tell any more as the documentation has been desecrated replaced with a monetised video I refuse to watch.

I don’t think this will work:

if:
  - condition: trigger
    id:
      - Keuken Beweging
then:
  - service: <save a scene>
  - service: <other stuff>
else:
  - service: <restore the scene>

As soon as your if-then and automation finishes is the scene is destroyed.

The way you need to use it is like this:

if:
  - condition: trigger
    id:
      - Keuken Beweging
then:
  - service: <save a scene>
  - service: <other stuff>
  - service: <restore the scene>

i.e. save and restore all in the one sub-block of actions.

2 Likes

I think the scenes stay there indefinately …

The weird thing is, when i only run the scene.create part the colors are stored correct, when i run the total automation, they are not …

What does the automation trace show?

All normal i think …
Except … ??

I would love a way to manually delete those automation created scenes.

Delete is covered here: https://www.home-assistant.io/integrations/scene/#deleting-dynamically-created-scenes