Skip to content

PiotrMachowski/Home-Assistant-custom-components-Saver

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

54 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

HACS Default GitHub Latest Release GitHub All Releases Installations 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

Using HACS (recommended)

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 (Deprecated)

Add following code in configuration.yaml:

saver:

Available services

Save state

Saves the state and parameters of the entity. Supports saving multiple entities.

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

Restore state

Restores saved states (only for entities that support it). Supports restoring multiple entities.

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

Optional 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: 3

Delete saved state

Deletes a saved state for an entity.

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

Delete saved states by regex

Deletes saved states for entities that match provided regex.

service: saver.delete_regex
data:
  entity_id_regex: light.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

Delete variables by regex

Deletes saved variables that match provided regex.

service: saver.delete_variable_regex
data:
  regex: "counter_\\d+"

Clear

Deletes all saved data.

service: saver.clear

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

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
  • Powered by

    PyCharm logo.

    About

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

    Topics

    Resources

    License

    Stars

    Watchers

    Forks

    Packages

     
     
     

    Contributors

    Languages