Dynamic scenes - ability to peek inside and delete scene

Dynamic scenes (i.e. created with scene.create) are awesome! Particularly those which use snapshot_entitites, as they provide me with a way to temporarily override a “stable” state with a context-aware one, while still giving me the option to “undo” the automation and go back to the stable state by activating the dynamic scene.

However, in order not to use several helpers, I would like to have 2 extra features for these dynamic scenes:

  • the ability to delete them explicitly, without reloading the scene integration
  • the ability to “extract” a scene and “look” inside at the saved states of entities, specifically those saved with snapshot_entities, for which I don’t know what the state was at the time of creating the scene

Here’s a use case I’m having trouble with: I have individual climate control and window sensors in all rooms, as well as an outside temperature sensor. I would like to:

  • be able to alter the set temperature when the window is open for a while (to debounce short openings) and notify family members about it
    • they can choose to “undo” the automation if, for example, the window is left open on purpose, with the desire to heat the room knowing about the energy waste
  • go back to the initial state either when
    • the window is closed (also with a debounce time)
    • a family member has expressed their desire to “undo” the automation
  • if, during the temporary override, someone sets a new temperature on the thermostat, don’t revert to the initial state upon closing the window and don’t adjust the temperature down upon external temperature variation, just consider that this is the new “stable” state
  • a while after the automation was undone either by expressing the desire to undo or by manually altering the set temperature (e.g. several hours, let’s call it “override cooldown”), the automation should re-start to turn down the thermostat, as maybe whoever has set the temperature forgot they did and energy is being wasted for more time than they had planned

If I could delete dynamic scenes and check the states inside them, my automation would be relatively simple (considering my climate control is in heating mode):

  • variables:
    • “stable” set temperature: the thermostat temperature if a scene doesn’t exist, else the temperature of the thermostat snapshot in the scene
  • triggers:
    • window open or closed
    • outside temperature changes
    • set temperature changes
  • actions
    • if the window opens and the set temperature is above the outside temperature and the snapshot scene doesn’t exist or it exists and has never been activated (state=="unknown")
      • take a snapshot of the thermostat
      • save it in a scene or overwrite the existing scene
      • turn down the thermostat
      • notify about the change, with the ability to “undo”, in which case activate and delete the dynamic scene
    • if the window closes, the scene exists, has never been activated and the stable set temperature (i.e. in the scene) is above the outside temperature
      • activate the scene
      • delete the scene
    • if the scene exists and the set temperature is altered
      • recreate the scene with the new thermostat temperature (manual override)
      • activate the scene (no effect except for scene state)
    • if the scene exists and has been activated for longer than the override cooldown
      • delete the scene
      • re-run the automation

Notice all the “scene exists” conditions. The automation may look long, but it’s actually pretty straightforward considering the desired scenario complexity. This would be an automation blueprint that can be instantiated for each room with its own thermostat and window sensor.

I know that all this can be achieved with helpers, but I would have to create a couple of helpers for each room, which adds up to a lot. Plus the automation(s) would be much, much longer.

Having the ability to delete dynamic scenes would also help with creating blueprints that others can use for a similar task without having to instruct them how to create helpers.

I agree, It seems like we’re missing some obvious controls for scenes. I am have to use a helper for to manage scene creation for my lights automation which is frustrating.

I also have a few situations where I want to capture the existing scene before changing things up to be able to “return to normal” after some event. If I check for the existing scene and it does not exist, then creating it does what I want. I do not want to overwrite this scene as I have no other record of what that snapshot looks like, but I wish to return to it at the end. I have an instance where there are a handful of different triggers that can cause the scene to be created (if not already). So it is crucial that the scene does not exist if I need to capture the current state. Being able to delete the scene after loading it will allow me to easily check if I need to re-capture the current scene or not.

I’ve opened a pull request for the scene.delete functionality, but it will probably take a while before it will be merged. Add scene.delete service for dynamically created scenes (with scene.create) by tetele · Pull Request #89090 · home-assistant/core · GitHub

1 Like

I should probably explain a bit better what this feature is supposed to be for, but please leave comments if anyone else has a different use case.

The way I see it, creating scenes is a means of saving states in case of temporary overrides.

For example, I have a thermostat set the way I want it in a room. But if that room’s window is open, I want to put the thermostat in an eco mode and save the initial state to something I can revert back to later on, upon closing the window. This works well.

But what if I want to check if an override is in place due to an open window or some other reason? I can check if a dynamic scene exists, but that only tells me if an override was ever in place since the last HA restart. Of course, I could add an input_boolean helper which would signal an override, but that means one new entity per each climate-binary_sensor combo, which sucks if you want to create a blueprint.

If I could delete a dynamic scene, the existance of such a scene would be a good indicator if an override is in place or not.

Have the same situation but for a Light triggered by a camera movement. the Reload work for the moment , because i have only one case. but will whant to add more base on zone in frigate.

The PR has been merged. Here’s the documentation for the scene.delete service

Hey, i tried to remove a scene that is created with create.scene:

but if i call the service i get an error:

Any idea here?