Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/PiotrMachowski/Home-Assistant-custom-components-Saver
This custom component allows you to save current state of any entity and use its data later to restore it.
https://github.com/PiotrMachowski/Home-Assistant-custom-components-Saver
automation helper home-assistant save script variable
Last synced: 5 days ago
JSON representation
This custom component allows you to save current state of any entity and use its data later to restore it.
- Host: GitHub
- URL: https://github.com/PiotrMachowski/Home-Assistant-custom-components-Saver
- Owner: PiotrMachowski
- License: mit
- Created: 2020-06-10T22:26:28.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2023-09-30T21:12:14.000Z (about 1 year ago)
- Last Synced: 2024-08-02T16:01:32.999Z (3 months ago)
- Topics: automation, helper, home-assistant, save, script, variable
- Language: Python
- Homepage:
- Size: 37.1 KB
- Stars: 61
- Watchers: 8
- Forks: 2
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
[![HACS Default][hacs_shield]][hacs]
[![GitHub Latest Release][releases_shield]][latest_release]
[![GitHub All Releases][downloads_total_shield]][releases]
[![Community Forum][community_forum_shield]][community_forum]
[![Ko-Fi][ko_fi_shield]][ko_fi]
[![buycoffee.to][buycoffee_to_shield]][buycoffee_to]
[![PayPal.Me][paypal_me_shield]][paypal_me]
[![Revolut.Me][revolut_me_shield]][revolut_me][hacs_shield]: https://img.shields.io/static/v1.svg?label=HACS&message=Default&style=popout&color=green&labelColor=41bdf5&logo=HomeAssistantCommunityStore&logoColor=white
[hacs]: https://hacs.xyz/docs/default_repositories[latest_release]: https://github.com/PiotrMachowski/Home-Assistant-custom-components-Saver/releases/latest
[releases_shield]: https://img.shields.io/github/release/PiotrMachowski/Home-Assistant-custom-components-Saver.svg?style=popout[releases]: https://github.com/PiotrMachowski/Home-Assistant-custom-components-Saver/releases
[downloads_total_shield]: https://img.shields.io/github/downloads/PiotrMachowski/Home-Assistant-custom-components-Saver/total[community_forum_shield]: https://img.shields.io/static/v1.svg?label=%20&message=Forum&style=popout&color=41bdf5&logo=HomeAssistant&logoColor=white
[community_forum]: https://community.home-assistant.io/t/custom-component-saver/204249# 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](https://hacs.xyz/) (recommended)
[![Open your Home Assistant instance and open a repository inside the Home Assistant Community Store.](https://my.home-assistant.io/badges/hacs_repository.svg)](https://my.home-assistant.io/redirect/hacs_repository/?owner=PiotrMachowski&repository=Home-Assistant-custom-components-Saver&category=Integration)
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*](https://github.com/PiotrMachowski/Home-Assistant-custom-components-Saver/releases/latest/download/saver.zip) and extract its contents to `config/custom_components/saver` directory:
```bash
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
### Using UI
[![Open your Home Assistant instance and start setting up a new integration.](https://my.home-assistant.io/badges/config_flow_start.svg)](https://my.home-assistant.io/redirect/config_flow_start/?domain=saver)
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
Add following code in configuration.yaml:
```yaml
saver:
```## Available services
### Save state
Saves the state and parameters of the entity.
```yaml
service: saver.save_state
data:
entity_id: cover.living_room
```### Delete saved state
Deletes a saved state for an entity.
```yaml
service: saver.delete
data:
entity_id: cover.living_room
```### Set variable
Sets the value to the variable.
```yaml
service: saver.set_variable
data:
name: counter
value: 3
```### Delete variable
Deletes a saved variable.
```yaml
service: saver.delete_variable
data:
name: counter
```### Clear
Deletes all saved data.
```yaml
service: saver.clear
```### Deprecated services
Show
#### 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`.
```yaml
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 }}' }}"
```#### 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`.
```yaml
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 }}' }}"
```## Using saved values in templates
It is possible to use saved data in templates using `saver_entity` and `saver_variable` functions:
```yaml
{{ 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"
```## Events
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](https://www.home-assistant.io/docs/automation/trigger/#event-trigger).
## Support
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
[ko_fi_shield]: https://img.shields.io/static/v1.svg?label=%20&message=Ko-Fi&color=F16061&logo=ko-fi&logoColor=white
[ko_fi]: https://ko-fi.com/piotrmachowski
[buycoffee_to_shield]: https://shields.io/badge/buycoffee.to-white?style=flat&labelColor=white&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAABhmlDQ1BJQ0MgcHJvZmlsZQAAKJF9kT1Iw1AUhU9TpaIVh1YQcchQnayIijhKFYtgobQVWnUweemP0KQhSXFxFFwLDv4sVh1cnHV1cBUEwR8QVxcnRRcp8b6k0CLGC4/3cd49h/fuA4R6malmxzigapaRisfEbG5FDLzChxB6MIZ+iZl6Ir2QgWd93VM31V2UZ3n3/Vm9St5kgE8knmW6YRGvE09vWjrnfeIwK0kK8TnxqEEXJH7kuuzyG+eiwwLPDBuZ1BxxmFgstrHcxqxkqMRTxBFF1ShfyLqscN7irJarrHlP/sJgXltOc53WEOJYRAJJiJBRxQbKsBClXSPFRIrOYx7+QcefJJdMrg0wcsyjAhWS4wf/g9+zNQuTE25SMAZ0vtj2xzAQ2AUaNdv+PrbtxgngfwautJa/UgdmPkmvtbTIEdC3DVxctzR5D7jcAQaedMmQHMlPSygUgPcz+qYcELoFulfduTXPcfoAZGhWSzfAwSEwUqTsNY93d7XP7d+e5vx+AIahcq//o+yoAAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH5wETCy4vFNqLzwAAAVpJREFUOMvd0rFLVXEYxvHPOedKJnKJhrDLuUFREULE7YDCMYj+AydpsCWiaKu29hZxiP4Al4aWwC1EdFI4Q3hqEmkIBI8ZChWXKNLLvS0/Qcza84V3enm/7/s878t/HxGkeTaIGziP+EB918nawu7Dq1d0e1+2J2bepnk2jFEUVVF+qKV51o9neBCaugfge70keoxxUbSWjrQ+4SUyzKZ5NlnDZdzGG7w4DIh+dtZEFntDA98l8S0MYwctNGrYz9WqKJePFLq80g5Sr+EHlnATp+NA+4qLaZ7FfzMrzbMBjGEdq8GrJMZnvAvFC/8wfAwjWMQ8XmMzaW9sdevNRgd3MFhvNpbaG1u/Dk2/hOc4gadVUa7Um425qii/7Z+xH9O4jwW8Cqv24Tru4hyeVEU588cfBMgpPMI9nMFe0BkFzVOYrYqycyQgQJLwTC2cDZCPeF8V5Y7jGb8BUpRicy7OU5MAAAAASUVORK5CYII=
[buycoffee_to]: https://buycoffee.to/piotrmachowski
[buy_me_a_coffee_shield]: https://img.shields.io/static/v1.svg?label=%20&message=Buy%20me%20a%20coffee&color=6f4e37&logo=buy%20me%20a%20coffee&logoColor=white
[buy_me_a_coffee]: https://www.buymeacoffee.com/PiotrMachowski
[paypal_me_shield]: https://img.shields.io/static/v1.svg?label=%20&message=PayPal.Me&logo=paypal
[paypal_me]: https://paypal.me/PiMachowski
[revolut_me_shield]: https://img.shields.io/static/v1.svg?label=%20&message=Revolut&logo=revolut
[revolut_me]: https://revolut.me/314ma