Home Assistant Custom Components Saver Save

This custom component allows you to save current state of any entity and use its data later to restore it.

Project README

HACS Default GitHub Latest Release GitHub All Releases Community Forum Ko-Fi buycoffee.to PayPal.Me Revolut.Me

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

Open your Home Assistant instance and open a repository inside the Home Assistant Community Store.

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

Using UI

Open your Home Assistant instance and start setting up a new integration.

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:

saver:

Available services

Save state

Saves the state and parameters of the entity.

service: saver.save_state
data:
  entity_id: cover.living_room

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

Clear

Deletes all saved data.

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.

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.

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:

{{ 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.

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
  • PayPal
  • Credit card
  • Buy Me a Coffee at ko-fi.com
  • No fees
  • Single or monthly payment
  • buycoffee.to
  • BLIK
  • Bank transfer
  • Postaw mi kawę na buycoffee.to
    PayPal
  • PayPal
  • PayPal Logo
  • No fees
  • Revolut
  • Revolut
  • Credit Card
  • Revolut
  • No fees
  • Open Source Agenda is not affiliated with "Home Assistant Custom Components Saver" Project. README Source: PiotrMachowski/Home-Assistant-custom-components-Saver
    Stars
    60
    Open Issues
    2
    Last Commit
    7 months ago
    License
    MIT

    Open Source Agenda Badge

    Open Source Agenda Rating