Quantcast
Channel: Configuration - Home Assistant Community
Viewing all articles
Browse latest Browse all 106028

Script: saving entity state and restore it at the end of the script

$
0
0

So I’m new to HA scripting, and I’m finding the documentation to be pretty lacking.

What I’m trying to do seems simple enough: at the start of the script, save the state of an entity (light) and, after all the other actions, restore that light to its previous state.

This is where I’m at:

example_script:
    sequence:
      - alias: "Set variables"
        variables:
          state_one:
            value: light.one.state

And, at the end:

       - alias: "Restore one"
         service: light.turn_on
         target:
           entity_id: >
             {% if state_one == 'on' %}
             light.one
             {% endif %}

I’m not even sure if I’m on the right track or not. Can anyone help, please?

Thank you.

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 106028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>