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