Home-Assistant-custom-components-Saver
Home-Assistant-custom-components-Saver copied to clipboard
This custom component allows you to save current state of any entity and use its data later to restore it.
Saver
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.
Installation
Using HACS (recommended)
This integration can be installed using HACS.
To do it search for Saver
in Integrations section.
Manual
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
Configuration
GUI
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.
YAML
In configuration.yaml:
saver:
Available services
Save state
Saves the state and parameters of the entity.
service: saver.save_state
data:
entity_id: cover.living_room
Restore state
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 }}"
Delete saved state
Deletes a saved state for an entity.
service: saver.delete
data:
entity_id: cover.living_room
Set variable
Sets the value to the variable.
service: saver.set_variable
data:
name: counter
value: 3
Delete variable
Deletes a saved variable.
service: saver.delete_variable
data:
name: counter
Execute script
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 }}"
Clear
Deletes all saved data.
service: saver.clear
Using in templates
It is possible to use saved data in templates via saver.saver
entity:
script:
- service: cover.set_cover_position
data_template:
entity_id: cover.living_room
position: "{{ state_attr('saver.saver', 'entities')['cover.living_room'].attributes.current_position | int }}"
- service: input_text.set_value
data_template:
entity_id: input_text.cover_description
value: "Cover is now {{ state_attr('saver.saver', 'entities')['cover.living_room'].state }}"
- service: input_text.set_value
data_template:
entity_id: input_text.counter_description
value: "Counter has value {{ state_attr('saver.saver', 'variables')["counter"] }}"