This custom component allows you to save current state of any entity and use its data later to restore it.
Additionally, you can create simple variables and use their values in scripts.
Using HACS (recommended)
This integration can be installed using HACS.
To do it search for Saver
in Integrations section.
To install this integration manually you have to download saver.zip and extract its contents to config/custom_components/saver
directory:
mkdir -p custom_components/saver
cd custom_components/saver
wget https://github.com/PiotrMachowski/Home-Assistant-custom-components-Saver/releases/latest/download/saver.zip
unzip saver.zip
rm saver.zip
From the Home Assistant front page go to Configuration and then select Integrations from the list.
Use the "plus" button in the bottom right to add a new integration called Saver.
The success dialog will appear or an error will be displayed in the popup.
Add following code in configuration.yaml:
saver:
Saves the state and parameters of the entity.
service: saver.save_state
data:
entity_id: cover.living_room
Deletes a saved state for an entity.
service: saver.delete
data:
entity_id: cover.living_room
Sets the value to the variable.
service: saver.set_variable
data:
name: counter
value: 3
Deletes a saved variable.
service: saver.delete_variable
data:
name: counter
Deletes all saved data.
service: saver.clear
Show
Executes the script using saved state of the entity.
To use state of an entity you have to use a following value in a template: state
.
To use state attribute (in this case current_position
) of an entity you have to use a following value in a template: attr_current_position
.
service: saver.restore_state
data:
entity_id: cover.living_room
restore_script:
- service: cover.set_cover_position
data_template:
entity_id: cover.living_room
position: "{{ '{{ attr_current_position | int }}' }}"
- service: input_text.set_value
data_template:
entity_id: input_text.cover_description
value: "Cover is now {{ '{{ state }}' }}"
Executes a script using all saved entities and variables.
To use state of an entity (in this case cover.living_room
) you have to use a following value in a template: cover_living_room_state
.
To use state attribute (in this case current_position
) of an entity you have to use a following value in a template: cover_living_room_attr_current_position
.
service: saver.execute
data:
script:
- service: cover.set_cover_position
data_template:
entity_id: cover.living_room
position: "{{ '{{ cover_living_room_attr_current_position | int }}' }}"
- service: input_text.set_value
data_template:
entity_id: input_text.cover_description
value: "Cover is now {{ '{{ cover_living_room_state }}' }}"
- service: input_text.set_value
data_template:
entity_id: input_text.counter_description
value: "Counter has value {{ '{{ counter }}' }}"
It is possible to use saved data in templates using saver_entity
and saver_variable
functions:
{{ saver_entity("sun.sun") }} # returns saved state of "sun.sun" entity
{{ saver_entity("sun.sun", "azimuth") }} # returns "azimuth" attribute of saved "sun.sun" entity
{{ saver_variable("counter") }} # returns saved variable "counter"
After the completion of the services mentioned before, the following events are fired:
Service Function | Event ID | Provided Arguments |
---|---|---|
execute | event_saver_executed | script |
save_state | event_saver_saved_entity | entity_id |
restore_state | event_saver_restored | entity_id |
delete | event_saver_deleted_entity | entity_id |
clear | event_saver_cleared | |
set_variable | event_saver_saved_variable | variable, value |
delete_variable | event_saver_deleted_variable | variable |
The events can be used to trigger further automations that depend on the completion of the services. The documentation is provided here.
If you want to support my work with a donation you can use one of the following platforms:
Platform | Payment methods | Link | Comment |
---|---|---|---|
Ko-fi |
|
|
|
buycoffee.to |
|
|
|
PayPal |
|
|
|
Revolut |
|
|
|