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. If you think that this should be the default behaviour in HomeAssistant then vote here

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

3 Likes

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.

1 Like

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.

Did you managed to implement user defined triggers so that you don’t need another auromation? Would be very nice if this helpful blueprint would be extended with more features.

No, I didn’t as I don’t think user defined triggers are a feature yet - I think there is a feature request open somewhere.

But you can use the new “take control” feature of blueprints to edit it as you see fit.

1 Like