Toggle between a scene and the pre-scene state

What this does

It allows you to toggle a scene on and off with a single input. Without this blueprint, there is no easy way to ‘undo’ a scene activation in home assistant.

How it works

When triggered it saves the current state as a new scene scene.my_scene_store_previous_state before then activating the scene e.g scene.my_scene. When triggered again it simply activates scene.my_scene_store_previous_state. It alternates between the 2 by seeing which of scene.my_scene_store_previous_state & scene.my_scene was the last to be triggered.

Once the timeout has passed since scene.my_scene was activated it assumes a new session has started and will start by saving the state and activating scene.my_scene. Even if it was due to activate scene.my_scene_store_previous_state next.

After a restart the first activation will always be to implement scene.my_scene as the pre-scene state is lost at restart.

Of course if the state before you activate the scene is identical or similar to the scene then it will toggle between 2 identical states and you won’t notice any difference.

Requirements

  1. At least one scene
  2. A second automation to trigger this one.

How to uses

  1. Click the link below to import the blueprint and create it with the desired settings.
  2. Run it by calling the service Automation: Trigger from automations, UI buttons or the developer tools.
  3. More advanced users can fire an event. The automation listens for a custom event
event: scene_toggle
event_data:
  entity_id: scene.my_scene

Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.

Change log

2022-11-24 Version 1.0

Help wanted - I do not know how to do these things

1 Like

You may consider mentioning that this blueprint relies on the scene.create service and the resulting ‘snapshot scene’ it produces doesn’t survive a restart.

I did not know this - thanks for pointing it out. I don’t think it is a major issue as the pre-scene state doesn’t really need to persist for long. It just acts as an ‘undo’ function. But if there was a restart whilst the scene was activate then the pre-scene state and the scene state would be identical.