Return to previous lighting scene

Hi all, I need a “function” for my hue lights and not sure how to achieve it and if it is even possible. What I need is to program one of the buttons of the Philips hue switch so when I press it, the room will return to the previous lighting scene.

Do you think something like this is possible?

If you assign the applicable scenes to the area (room) that it’s applicable, then it would technically be possible to write a template that returned the last activated (an attribute of scene entities) scene for that area. Then use that template as the target for a scene.turn_on service call. Assign that to a button - voila. (No I am not writing the template - there’s tons of docs)

So it’s very do-able if you make sure your scenes are associated wiht areas and areas actually represent rooms in your setup.

You could also snapshot the current state dynamically into a scene (check out the scene docs - you can do this) to return to it in case you don’t like the result.

I was thinking something like that but then I realized that the template shouldn’t return the last activated scene but the scene that was activated before the last activated scene, I hope I am making sense here.
Here’s an example: I have three scenes in my room Red, Green and Blue I activate the Red scene and after 30min I activate the Blue scene, now the Blue scene is the last activated but I want the template to return back the Red scene, which is not the last activated scene. I am not very familiar with snapshots and storing that etc. I would prefer to go with a template but I’m not sure how to do it.

No need to write code, I am fairly new to HA so in order to learn I prefer to begin writing any code my self and ask for help if I get stuck on the way. :wink:

You’re making perfect sense - I follow.

That gets - COMPLICATED. In that case you’d have to intercept the scene application and store last somehow. In which case snapshotting is probably the easiest way

Here’s the docs for creating a transient scene on the fly.
Scenes - Home Assistant (

But there’s a rub. You’d have to figure out how to run it. You’d probably have to give up using standard scene.turn_on calls and instead use a script that calls the snapshot THEN the scene turn on for the new scene. Anytime you call scene turn_on withoput your prep script you’d miss the ability to revert.