Custom component: Saver

Hey,

I cant get this to work.

I have DOODS that scans for detected objects at my front door and returns a value. Normally I a value of 2 (2 cars in drive). I want to use this to save and restore a value of doods after a restart. My code is below and i would appreciate some help.

# Hass.io has restarted
  - id: 'hassio_restarted'
    alias: 'Hass.io Startup Notification'
    trigger:
      - platform: homeassistant
        event: start
    action:
    - service: script.restore_states
    - service: notify.mobile_app_stephen_s20
      data:
        title: "Home Assitant has restarted."
        message: ''
    - service: notify.alexa_media
      data:
        target: 
          - media_player.office_echo
        data:
          type: announce
        message: "Home Assitsant has restarted."

# Hass.io has shutdown
  - id: 'hassio_shutdown'
    alias: 'Hass.io Shutdown Notification'
    trigger:
      - platform: homeassistant
        event: shutdown
    action:
    - service: script.save_states
    - service: notify.mobile_app_stephen_s20
      data:
        title: "Home Assitant has shutdown."
        message: ''
    - service: notify.alexa_media
      data:
        target: 
          - media_player.office_echo
        data:
          type: announce
        message: "Home Assistant has shutdown"
save_states:
  alias: Save States
  sequence:
    - service: saver.save_state
      data:
        entity_id: image_processing.doods_front_door

restore_states:
  alias: Restore States
  sequence:
    - service: saver.restore_state
      data:
        entity_id: image_processing.doods_front_door
        restore_script:
          - service: image_processing.scan
            data_template:
              entity_id: image_processing.doods_front_door
              value: "{{ state}}"

Does image_processing have a possibility to set state using a service?

The only service i think it has is image_processing.scan - i take it that it cant be done then?

Unfortunately :frowning:

1 Like

please tell me the script, there is a wled tape. I want to save its effect state, change the effect, and then return the effect back

alias: test
sequence:

  • service: saver.save_state
    data:
    entity_id: light.wled
  • delay: ‘00:00:05’
  • service: wled.effect
    data:
    entity_id: light.wled
    effect: police
  • delay: ‘00:00:05’
  • service: saver.restore_state
    data:
    entity_id: light.wled
    entity_id: saver.saver
    mode: single

I have replied in an issue you have created :slight_smile:

it turns out that your addition will not help me. Sorry, maybe I don’t write correctly, I’m from Russia

Is there a way to use this to save and restore multiple entities in one go. So, for example, saving with:

        - service: saver.save_state
          data:
            entity_id:
              - input_select.accent_lights_alert_color
              - input_select.accent_lights_default_color
              - input_select.accent_lights_movie_color
              - input_select.accent_lights_test

and then restoring with a

        - service: saver.restore_state
          data:
            entity_id:
              - input_select.accent_lights_alert_color
              - input_select.accent_lights_default_color
              - input_select.accent_lights_movie_color
              - input_select.accent_lights_test
            restore_script:
              - service: input_select.select_option
                data:
                  entity_id: SOMETHING GOES HERE
                  option: '{{ "{{ state }}" }}'

rather than having to save and restore them one at a time?

It is possible using built-in scenes mechanism:

  - service: scene.create
    data:
      scene_id: before
      snapshot_entities:
      - climate.ecobee
      - light.ceiling_lights
 -  service: scene.turn_on
    target:
      entity_id: scene.before

Documentation

I’ve given that a try, but it seems to be restoring too much for what I need.

(I’m trying to update the list of options for some input_selects, and then restore only the selected option to what it was before. Doing this with the scene method apparently restores the list of options as well.)

In this case unfortunately you have to do it one by one :frowning: Alternatively you can try to play around with loops

Hrm. Before I start working on it as such, would you be interested in a pull request to add this?

Definitely not anytime soon, I have a looooot of work with other integrations

Release v1.2.0

  • Added saver_entity and saver_variable Jinja functions (to use instead of saver.restore_state and saver.execute services)
  • Added possibility to save/delete multiple entities at once

image

Can you please provide an example of how to save and restore multiple entities? I would like to use this to preserve the state of some binary_sensors and restore them after a restart.

It is not possible to set a state of a binary sensor

scene.create has typical problem of losing it once restarted.
There is no other way that script can update the saved scene.

What I am trying to archive?
On ‘Scene1’ button press, save/update the selected entities’ states so it can be recalled next time.
User wants to keep 2 scenes.

Updating scenes via ‘Automation& Scenes’ is very difficult for non-technical users.
Also, non-admin users will have issues seeing all the scenes and being able to change everything.

Easy method to update the scene is: User has its mushroom-based user-friendly dashboard, he/she changes lights/fan/climate as wanted and then long presses the scene button on same dashboard which calls script and update/save the scene.

With Saver I can save only 1 state for each entity. In that case, I can’t give second scene option to the user.

HA really needs to redesign its core scene methodology.

Hi !
I have big trouble with SAVER.
I can save entities but can only restore 1 … the first that was saved the first time.
I’ve noticed that SAVER have 2 entities :

And each new save i done under saver.save_2 and cannot be recovered.
I’ve deleted SAVER , restart HA …
The 2 entities are still here.
A clear leave the 2 entities.

I can’t delete saver.save_2 : no unique ID …

So, what can i do ?

What

Haven’t you configured it in yaml and via UI at the same time?

you mean i don’t need to have a line with saver: in yaml config ?