I’m trying to create a scene on the fly using scene.create in a script so I can save the state my lights are in, flash a color, and then have them return to their previous state. I’m using templates in scene creation to save the current value.
I suspect the scene is getting created with the template text (e.g. '{{ state_attr("light.lr_floor_lamp", "brightness") }}'') instead of with the concrete values the template resolves to when I create the scene (e.g. 254). If that’s the case the template will resolve when I try to apply the scene which will apply the state the lights are currently in which isn’t very helpful.
I’ve been trying to verify this but it seems temp scenes are only saved in memory and not in scenes.yaml. I can see the created scenes in the scenes GUI but the edit button is grayed out since it’s a temp scene.
Any ideas on how to achieve this or check how temp scenes are getting saved?
I searched around quite a lot and somehow didn’t come across that post. Thanks for the link though, hopefully creating scenes based on current states will be an option at some point in the future.
@ joelspiers15
If your color lamps happen to be LIFX, here is a simple script that does the trick. Not sure if it will cross over to other RBG bulbs, but maybe it will help you.
They’re hue so that won’t work. There is a flash option for Hue which is supposed to do that but it doesn’t actually return the lights to their previous state
I think I read a comment in GitHub about a proposed ability to capture the current state of entities. So you can take a snapshot of the current states, apply a scene, then revert back to the snapshot (effectively “undo-ing” the scene).
FWIW, the home automation software I’ve used for years has scenes with two possible behaviors: set set-restore
The set behavior is like how Home Assistant’s scenes work. Turn on the scene and done; there’s no way to revert to the previous states.
The set-restore behavior lets you turn on a scene and then, if you wish, turn off the scene so that all entities are automatically restored to their previous state. Under the hood, this kind of scene automatically takes a snapshot of all entity states so it knows how to put them back afterwards. This allows you to layer one scene atop another and easily be able to peel them off, one by one.
The classic example of this is you have the Movie scene running and then someone rings the doorbell. This activates the Doorbell scene that pauses your movie and displays the entry camera on the TV, brightens the room lights, and turns on the hallway light. After you paid for the pizza, hit play and that turns off the Doorbell scene and automagically restores the room to its previous state (no door camera on screen, lights dim, etc).