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.zipFrom 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. Supports saving multiple entities.
service: saver.save_state
data:
entity_id: cover.living_roomRestores saved states (only for entities that support it). Supports restoring multiple entities.
service: saver.restore_state
data:
entity_id: cover.living_roomOptional attributes:
delete_after_run: allows to disable removing saved states after restoring them (default:true).transition: Number that represents the time (in seconds) the light should take to transition to the new state.
service: saver.restore_state
data:
entity_id:
- cover.living_room
- light.living_room
delete_after_run: false
transition: 3Deletes a saved state for an entity.
service: saver.delete
data:
entity_id: cover.living_roomDeletes saved states for entities that match provided regex.
service: saver.delete_regex
data:
entity_id_regex: light.living_room.*Sets the value to the variable.
service: saver.set_variable
data:
name: counter
value: 3Deletes a saved variable.
service: saver.delete_variable
data:
name: counterDeletes saved variables that match provided regex.
service: saver.delete_variable_regex
data:
regex: "counter_\\d+"Deletes all saved data.
service: saver.clearIt 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 |
|---|---|---|
| save_state | event_saver_saved_entity | entity_id |
| restore_state | event_saver_restored | entity_id |
| delete | event_saver_deleted_entity | entity_id |
| delete_regex | event_saver_deleted_entity_by_regex | entity_id_regex, entities |
| clear | event_saver_cleared | |
| set_variable | event_saver_saved_variable | variable, value |
| delete_variable | event_saver_deleted_variable | variable |
| delete_variable_regex | event_saver_deleted_variable_by_regex | variables, regex |
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 |
|
|
|
