Value_template: How to get old state after restart?

Hi guys,

i have a templated cover, which is using the value_template to get the state. It is working good, but every time, when I restart HA, the state falls back to open. How do I code it, to use the old state? Here is the template:

- platform: template
  covers:
    garagentor:
      friendly_name: "Garage"
      device_class: garage
      value_template: "{{ is_state('binary_sensor.garagentor', 'on') }}"
      open_cover:
        service: switch.turn_on
        data:
          entity_id: switch.shelly
      close_cover:
        service: switch.turn_on
        data:
          entity_id: switch.shelly
      stop_cover:
        service: switch.turn_on
        data:
          entity_id: switch.shelly
      icon_template: >-
        {% if states('binary_sensor.garagentor') == "on" %}
          mdi:garage-open
        {% else %}
          mdi:garage
        {% endif %}

Not sure if this will help, but I use button card to control my cover/gate within lovelace. I figure it might give you some ideas, if anything.

entity: cover.front_gate
icon: 'hass:gate'
show_icon: true
show_name: true
state:
  - color: 'rgb(68,115,159)'
    icon: 'hass:gate-open'
    value: open
  - color: 'rgb(68,115,159)'
    value: closed
styles:
  icon:
    - height: 60px
tap_action:
  action: toggle
type: 'custom:button-card'

I also noticed in your code, you have

      open_cover:
        service: switch.turn_on
        data:
          entity_id: switch.shelly
      close_cover:
        service: switch.turn_on
        data:
          entity_id: switch.shelly
      stop_cover:
        service: switch.turn_on

Do you mean switch.turn_off for close_cover?

If this gives the correct state after a HA restart, your cover should have the correct state. Unfortunately, You did not specify that binary sensor.