How to add variables to hass.io? How to store a light state into variables to restore later?

I would like to use variables to store the state of lights (on or off) at the beginning of an automation to be able to restore the state at the end.
Because I want to send some effects to my lamps and I think this is only possible with light.turn_on, and this will always turn on and depending on the current state sometimes I need to turn off. And I want to avoid to define to different automations depending on the current state but this be one automation.

I found this: https://github.com/rogro82/hass-variables and it looks like this is what I could use.
So I added this address under Menu > Hass.io ADD-ON STORE > Repositories: https://github.com/rogro82/hass-variables
it’s name is shown as “unknown” and I am not sure if this is the right way to add this component.
Anyway I can’t use it, if I add a section “variable” to my configuration.yaml and check the configuration I get:
“Component not found: variable”

Is my way to use this component wrong? Maybe it is not possible to use it in hass.io, but only in the hass without the “io”?

Are there other easy ways to store the state of a light at the beginning of a group of actions to be able to use it at the end of these actions?

That’s not an add-on repository

Did you read the ‘INSTALL’ instructions? It plainly tells you exactly what you need to do.

Copy variable.py to your home-assistant custom_components folder

You literally make a directory in your config directory, called custom_components, and copy the .py file into it. restart HASS.

You could try publishing the state in a a mqtt topic to retrieve later.

2 Likes

Thank you, this was not clear for me. I did not understand from the instructions that I should / could add this folder in my config folder because I have no such folder.

yes, I like this idea to store it in an mqtt topic!
Thank you for this suggestion.

This is my preferred method for passing variables/data around.

https://developers.home-assistant.io/docs/en/creating_component_loading.html

Sometimes you have to dig around to find the answer. It’s not always right out in the open.

2 Likes

FWIW, I created a python_script to save/restore lights & switches. It’s described in this topic, and can be obtained from here. If you think this might help you, and you have questions, just let me know.

2 Likes