#Using scripts to save, apply and delete temporary scenes

1 messages Β· Page 1 of 1 (latest)

rapid valley
#

I am trying to have one script that can be reused to temporarily save scenes and another script to apply and then delete the scenes.

I use input fields in order to have variable scene names.

In my scripts I want to check if the scene with that name exists before saving it or applying it, in order to avoid overwriting scenes or applying scenes that don't exist.

The problem seems to be writing a condition that checks if a scene exists. It doesn't seem to work for me when the scene is "freshly created". Then all my attempts at conditions return "false - the scene doesn't exist" but I can see the scene under the scenes tab in the web GUI.

Why does this happen? Can I flush the new scene to the system so my conditions work immediately, or is there some other magic I have to understand in order to get this to work?

Thanks for any help πŸ™

barren copper
#

Maybe add a little time delay?

tall cloud
rapid valley
# barren copper Maybe add a little time delay?

The script saving the scene and the one applying it are different scripts triggered from different automations. A delay isn't applicable here.

Also; the time it takes to pick up that there really is a scene there seems more to do with whether or not I touch the saved scene in the GUI or not.

But thank you for helping πŸ™‚ πŸ™

rapid valley
tall cloud
#

But maybe if you start telling the problem you want to solve, not the solution you want to implement, it's easier to help you πŸ˜‰

barren copper
#

Looks like a good time to start sharing the yaml πŸ™‚

rapid valley
#

The problem I want to solve is the following:

  1. Something triggers an automation
  2. Call script "save scene" with args:
  • scene_name - the name of the scene to save
  • entities - the entities to snapshot
  1. Modify the entities - maybe increase brightness of a light or whatever
  2. Wait some time
  3. Call script "recall scene" with arg:
  • scene_name - the name of the scene to recall and then delete

This way automations can, in a simple way, reuse scripts in step 2 and 5 to make temporary changes to the state of my home, and then revert to the original state later.

barren copper
#

Yeah, if it's simply single scene I see no real use for a script (as it's already a single action). But if you want to make sure you save all attributes even when the light is off you need two scenes, that could be usefull with scripts.

But then, where are you stuck? What did you make? What does it do and what did you expect?

halcyon anchor
# rapid valley I am trying to have one script that can be reused to temporarily save scenes and...
rapid valley
#

Creating unique names is not the problem

#

Home assistant not picking up new scenes in its state is the problem

barren copper
#

Okay, so please share some yaml of what you have πŸ™‚