Cover group state incorrect at startup

I recently updated HA (to 2021.11.5) and am noticing that on startup my garage doors cover group does not seem to be consistent with the individual covers, but I’m not 100% sure it wasn’t doing this before. I’m wondering if I’m doing something wrong here or am missing a configuration option to avoid this issue.

Problem

On startup, the cover group shows an open state, but both individual covers have a closed state. It seems to correct itself after some interaction, but ultimately it seems like the cover group is not behaving correctly. See screenshot below:

Configuration

The garage doors device is a d1 mini lite, with hardwired reed switches and a 2 channel relay that hooks into the garage door controllers on the wall. Here is the important portion, but the ESPHome device and individual covers defined in HA work fine.

ESPHome

esphome:
  name: garagedoors
  platform: ESP8266
  board: d1_mini_lite

# ...removed all the unrelated config here

binary_sensor:
  - platform: gpio
    id: garage1_sensor
    pin:
      number: GPIO12 #D8
      mode: INPUT_PULLUP
      inverted: True
    name: "Garage Door 1 Sensor"
    device_class: garage_door
    filters:
      - delayed_on: 20ms
  - platform: gpio
    id: garage2_sensor
    pin:
      number: GPIO13 #D7
      mode: INPUT_PULLUP
      inverted: True
    name: "Garage Door 2 Sensor"
    device_class: garage_door
    filters:
      - delayed_on: 20ms

switch:
  - platform: gpio
    id: relay
    pin:
      number: GPIO5 #D1
      inverted: True
    restore_mode: ALWAYS_OFF
  - platform: template
    name: "Garage Door 1 Switch"
    icon: "mdi:garage"
    turn_on_action:
      - switch.turn_on: relay
      - delay: 0.5s
      - switch.turn_off: relay
  - platform: gpio
    id: relay2
    pin:
      number: GPIO4 #D2
      inverted: True
    restore_mode: ALWAYS_OFF
  - platform: template
    name: "Garage Door 2 Switch"
    icon: "mdi:garage"
    turn_on_action:
      - switch.turn_on: relay2
      - delay: 0.5s
      - switch.turn_off: relay2
  - platform: restart
    name: 'Garage Door REBOOT'

Home Assistant

The home assistant configuration. I can’t recall why I defined the covers in home assistant, rather than esphome, but here is the home assistant portion:

cover:
  - platform: template
    covers:
      left_garage_door:
        friendly_name: "Garage Door (Left)"
        value_template: "{{ is_state('binary_sensor.garage_door_1_sensor', 'on') }}"
        open_cover:
          - service: switch.turn_on
            data:
              entity_id: switch.garage_door_1_switch
        close_cover:
          - service: switch.turn_on
            data:
              entity_id: switch.garage_door_1_switch
        icon_template: >-
          {% if is_state('binary_sensor.garage_door_1_sensor', 'on') %}
             mdi:garage-open
           {% else %}
             mdi:garage
           {% endif %}
      right_garage_door:
        friendly_name: "Garage Door (Right)"
        value_template: "{{ is_state('binary_sensor.garage_door_2_sensor', 'on') }}"
        open_cover:
          - service: switch.turn_on
            data:
              entity_id: switch.garage_door_2_switch
        close_cover:
          - service: switch.turn_on
            data:
              entity_id: switch.garage_door_2_switch
        icon_template: >-
          {% if is_state('binary_sensor.garage_door_2_sensor', 'on') %}
            mdi:garage-open
          {% else %}
            mdi:garage
          {% endif %}
  - platform: group
    name: Garage Doors
    entities:
      - cover.left_garage_door
      - cover.right_garage_door

I was able to connect to the running container and debug …/components/group/cover.py using this guide.

However, with debugging enabled, it caused the container to startup much slower than before and the group cover was in the correct state this time. Stepping through, it did everything that I’d expect.

Next, I tried using this debugpy config so I could startup like normal, then debug.

debugpy:
  start: false
  wait: false

This approach resulted in the incorrect state again. When I enabled debugging, the breakpoints were never reached that I had stepped through before. So, it seems like the covers in the cover group aren’t available immediately, which then results in the group having the incorrect state, but then for some reason the state of the cover group is never updated.

I assumed there should be an event which would update the cover group when the covers go from being unavailable to having a valid state, but there must be something missing there still. Does anyone have insight into how a group should behave in this case?

I have a simple automation that turns off all lights (in my case) that are turned on every time my system restarts. Because the groups of cover sensors and motions sensors always report ‘on’ after a restart. After one sensor reports it’s current state the group returns in it’s correct state again.

Thanks, yeah I was starting to think about something like that, but it feels a bit dirty to me. Ultimately, I was trying to understand if this cover group was working as expected or not. It seems like there must be a missing hook or something for the group to be updated on any state changes for the children.

I can’t recall why I didn’t do the full implementation in esphome, but I think there was some issue with how it was exposed in home assistant or google home iirc. It seems like the ideal approach would be to push all the functionality of the garage doors into esphome if at all possible, so I’m trying that again for now to see what blockers I run into. Otherwise, the whole implementation is split across multiple places, which makes it hard to figure out what is going on when you have to remember what you did a year ago, like I’m doing now.