Restore position of cover not working as expected with restore_from_flash

Hi,

I’m having an issue with the restoring the state of a cover (sun blind).

On the time_based cover component page it is still stated:
The state of the cover can be restored from flash after a node reboot, with esp8266_restore_from_flash: true option set. See [esp8266_restore_from_flash]

I then found that this option is no longer valid and it should be this:

esp8266:
  board: nodemcuv2
  restore_from_flash: True

The restored position of the cover is still always 50% open with this option active.

I’ve searched the forums and found this post about the same problem:

The thread is closed with this final comment:
FINAL EDIT : enabling esp8266_restore_from_flash all the automations that i added to manage globals (and even globals too) are unnecessary: cover position is natively saved through reboots.

It seems that the transition from esp8266_restore_from_flash to restore_from_flash has broken the expected behaviour in my use-case.

One thing that I’m not sure of is if there is a restore_mode option involved but as far as I can tell this is for GPIO pin states and not for remembering the position of a cover. The board does not have to do anything upon booting, it just has to know the value of the cover postion and adapt the opening and closing time in seconds to that value. This seems to be all included in the cover code but it is just not working for me.

Any advice or tips are greatly appreciated. Thank you!

Mkt

1 Like

This is my first question here and I’m surprised that there are no responses while the forum seems very active (tons of later questions have been answered).

Is this because my question is not as it should be or because no-one knows the answer?

Thank you.

I think it’s probably because people don’t know.

For more unique issues it can take time.

If you don’t get bites here after a few days you can also try the ESPHome Discord (see ESPHome webpage).

Posting your full config won’t hurt.

1 Like

You could try converting it to a Feedback cover and see if the issue remains?

I’ve found the issue.

assumed_state: False
This option was the culprit. After removing that the state of the cover is restored upon booting the board.

The penny dropped when I read that assumed_state is always true in a time-based cover so I guess this option is not meant to be used and causes problems like this.

2 Likes

Good on you for sharing back the solution!

Hello everyone, I am having a problem that I think is the same, but I am using an ESP32.

If I choose the closing position, for example, 50%, and reboot, the value is saved, and when the ESP reconnects online, the value is the same as before the reboot. However, if I execute the command to close and restart in the middle of the process, the value is lost and it reconnects as 100% open…

esphome:
  on_boot:
    - priority: 600 #https://esphome.io/components/esphome.html
      then:
        - delay: 10s
        - if:
            condition:
              lambda: |-
                auto now = id(current_time).now();
                auto timeopen = id(time_open).state_as_esptime();
                auto timeclose = id(time_close).state_as_esptime();
                
                if (now.hour > timeopen.hour && now.hour < timeclose.hour) {
                  return true;
                } else if (now.hour == timeopen.hour && now.minute >= timeopen.minute) {
                  return true;
                } else if (now.hour == timeclose.hour && now.minute <= timeclose.minute) {
                  return true;
                } else {
                  return false;
                }
            then:
              - cover.open: door_1
            else:
              - cover.close: door_1

datetime:
  - platform: template
    id: time_open
    type: time
    name: "Time Open"
    icon: mdi:sort-clock-descending
    optimistic: yes
    initial_value: "08:30:00"
    restore_value: true
    on_time:
      then:
        - cover.open: door_1
  - platform: template
    id: time_close
    type: time
    name: "Time Close"
    icon: mdi:sort-clock-ascending
    optimistic: yes
    initial_value: "21:30:00"
    restore_value: true
    on_time:
      then:
        - cover.close: door_1

switch:
  - platform: gpio
    id: door_1_open
    pin: GPIO12
    inverted: false
    interlock: [door_1_close]
    restore_mode: RESTORE_DEFAULT_OFF
  - platform: gpio
    id: door_1_close
    pin: GPIO23
    inverted: false
    interlock: [door_1_open]
    restore_mode: RESTORE_DEFAULT_OFF
    
cover:
  - platform: time_based
    name: "Door 1"
    id: door_1
    device_class: garage
    has_built_in_endstop: true
    open_duration: 20s
    close_duration: 20s
    open_action:
      - switch.turn_on: door_1_open
    close_action:
      - switch.turn_on: door_1_close
    stop_action:
      - switch.turn_off: door_1_open
      - switch.turn_off: door_1_close