#Automation "memory" of pre-start state?

1 messages Β· Page 1 of 1 (latest)

neat surge
#

If I build a sequence of ifs and thens etc in an automation, where the initial trigger is an entity going from any state to a specific state, how can I make it so at the end of the automation the device goes back to what it was doing when the automation started?

Basically the "to be automated" device has 4 interlocked relays and one of the four is on at any given time. I want the automation to start based on a different device (the vacuum robot) showing a specific combination of entity states, which makes the target device do a specific thing by triggering a specific relay (which turns off whichever relay was on before due to interlock). But after a set of conditions that determine that the automation is no longer needed, I want the last step to be the automation turning on the relay that was on when the automation started, whatever that might have been.
What can I do to achieve this sort of memory effect? And please don't tell me the only way is to create four automation-paths per device to account for four possible start-states 😭
I have 8 of these devices around the house and also a full-time job πŸ˜‚

fallow seal
#

You can create a snapshot of the states by using scene.create as the first step of the automation.
As the last step you apply that scene to restore the initial states.

#

If you want to avoid that temporary scene you could also use "define variables" to save the state and then use a template to apply it in the end. However that's more complicated

icy goblet
#

What about using helpers? If it's few information it may be a simpler solution? πŸ€”

fallow seal
#

it's 4x8=32 input booleans that you would need
scene.create is super convinient to use

neat surge
#

is this created scene then stored in the scene menu in HA? Or is it only kept temporarily?

#

As in, would having 8 devices go through this automation several times a week lead to a ton of pointless auto-created scenes being saved in my HA scene menu?

fallow seal
#

it's kept until you restart home assistant or overwrite it
you would create one temporary scene per device

#

you can see it in the scenes menu but it looks a bit different:

#

you basically tell the automation "store the states of those 4 entities in a scene with the following name"
then you can apply that scene as often as you want, or overwrite it with the same name in case you run the automation again

neat surge
#

ah cool, ok thanks I'll look into it

fallow seal
#

it's just important to note that those scenes don't survive a reboot

#

but if I understood your usecase correctly you always want to create the scene first and then restore it later

neat surge
#

yep, ganz genau

#

vielen Dank Herr Spiegelmann πŸ˜‚

fallow seal
#

I'm using the temporary scene to turn my lights yellow/red to indicate a warning/alarm and after the issue is resolved I want to return back to the initial state

fallow seal
neat surge
#

(I thought it was just a random username, didn't click in my head that it would be an actual german, but "licht_arbeitszimmer", that's why I made a little jokey nod to it)

#

no worries

fallow seal
#

it actually is a random username - it's the title of a song by moonspell, but I happen to be German as well πŸ˜‰

neat surge
#

perfect combination of coincidences, much like moonspell I'm from PT

#

I do get the impression that there's a lot of germans in the HA community for some reason? Could just be confirmation bias.
Grüße aus BaWu

fallow seal
neat surge
#

any idea why?

fallow seal
#

πŸ€·β€β™‚οΈ

icy goblet
neat surge
#

closed captions to the rescue?

fallow seal
#

Yes, there are really quite a few German home assistant youtubers and I'm subscribed to all of them πŸ˜‰

icy goblet
#

Totally πŸ™‚. It would be a good idea to have a list of resources like that

fallow seal
#

@neat surge btw. here's the snippet from my screenshot:

          scene_id: licht_arbeitszimmer
          snapshot_entities:
            - light.ceiling_light_rgbcw_a447f1
            - light.arbeitszimmer_licht
        action: scene.create
      - data:
          brightness_pct: 40
          color_name: yellow
        target:
          entity_id: light.ceiling_light_rgbcw_a447f1
        action: light.turn_on
      - delay:
          hours: 0
          minutes: 0
          seconds: 3
          milliseconds: 0
      - data: {}
        target:
          entity_id: scene.licht_arbeitszimmer
        action: scene.turn_on
#

creates the scene, turns the light yellow, waits 3s, reapplies the initial state

neat surge
#

I can create a scene but I can't figure out how to activate that scene later. The UI tool doesn't allow me to select a scene that doesn't exist yet, and doing it directly in YAML isn't working

marsh tangle
#

Just manually type the entity id like scene.slug. Or just make the snapshot manually a single time. After which it will just show in the entity list of scene.turn_on.

neat surge
#

I was getting errors until I wrote it like this in yaml:

#
sequence:
                        - action: scene.turn_on
                          metadata: {}
                          data: {}
                          target:
                            entity_id: scene.namestringhere
                        - action: scene.delete
                          metadata: {}
                          data: {}
                          target:
                            entity_id: scene.namestringhere
#

(the automation creates scenes to save previous state, then activates them at the end then deletes them, no reason to have extra scenes clogging up the UI)

#

Now it seems to be working

marsh tangle
#

Between "save previous state" and the activation is most part of the day, correct?

But delete is only so it does not show in the UI. But if you always use the same name and it's already there most of the day, I donΒ΄t see it as clogging at all.

nova cosmos
#

Scrolling through this channel can be super interesting. I had no idea this was possible, and just went ahead and modified some of my sequences to use this haha

nova cosmos
#

Actually I don't want to take over this thread, but one question, I have the same issue as Deimos. It won't let me save it when the scene doesn't exist yet. I get a UI error, stating the entity_id is not valid

      - sequence:
          - action: scene.create
            metadata: {}
            data:
              snapshot_entities:
                - light.yeelight_color_0x12a68b4c
              scene_id: my-scene-id
          - action: scene.turn_on
            metadata: {}
            data: {}
            target:
              entity_id: scene.my-scene-id
          - action: scene.delete
            metadata: {}
            data: {}
            target:
              entity_id: scene.my-scene-id

I've removed the steps that aren't relevant