Time based Cover with additional manual control - set state based on time elapsed?

Hi,
I’m absolutely new to ESPhome (and HA). Have been using FHEM and custom python scripts/MQTT messages for my DIY sensors and actuators. But ESPhome seems a much better choice, so I am going to go with that :wink:

For one of my DIY actuators based on I2C IC MCP23017, I managed to get the “time based cover” up and running. So this part is already fine.
In addition to the I2C controlled outputs, I do have manual switches to control the covers. The switches are independent of the I2C control. In other words: a relay gets turned on either by I2C or by the manual switch (if both are on, output gets turned off electronically). However, the state of the manual switch is recorded by MCP23017, therefore, I do now when the manual switch is turned on.

Is there a way to count the time when the switch is on and calculate the position of the cover in the same way the “time based cover” does? Basically, what I want to achieve is that the state of the cover is known, even when operated by the manual switch.
I already started looking into the “duty time” sensor component, but I do not know how to get the state (0% – 100%) back to the cover’s state…

substitutions:
  open_time: 0.5min
  close_time: 0.5min
  interlock_time: 500ms

esphome:
  name: kellerwohnzimmer

esp8266:
  board: esp12e

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: !secret api_key

ota:
  password: !secret ota_password

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

captive_portal:

i2c:
  - id: bus_a
    sda: GPIO4
    scl: GPIO5
    scan: true

mcp23017:
  - id: 'mcp23017_hub'
    i2c_id: bus_a
    address: 0x20

# Individual outputs
switch:
  - platform: gpio
    name: "Cover 1 Up"
    id: "up1"
    internal: true
    interlock: &interlock_group1 [up1, down1]
    interlock_wait_time: ${interlock_time}
    pin:
      mcp23xxx: mcp23017_hub
      # Use pin A0
      number: 0
      mode:
        output: true
      inverted: false

  - platform: gpio
    name: "Cover 1 Down"
    id: "down1"
    internal: true
    interlock: *interlock_group1
    interlock_wait_time: ${interlock_time}
    pin:
      mcp23xxx: mcp23017_hub
      # Use pin A1
      number: 1
      mode:
        output: true
      inverted: false

# Individual inputs
binary_sensor:
  - platform: gpio
    name: "Switch Cover 1 Up"
    id: "mup1"
    pin:
      mcp23xxx: mcp23017_hub
      # Use pin B0
      number: 8
      mode:
        input: true
        pullup: false
      inverted: false

  - platform: gpio
    name: "Switch Cover 1 Down"
    id: "mdown1"
    pin:
      mcp23xxx: mcp23017_hub
      # Use pin B1
      number: 9
      mode:
        input: true
        pullup: false
      inverted: false

cover:
  - platform: time_based
    device_class: shutter
    name: "Rolladen1"
    manual_control: true

    open_action:
      - switch.turn_on: up1
    open_duration: ${open_time}

    close_action:
      - switch.turn_on: down1
    close_duration: ${close_time}

    stop_action:
      - switch.turn_off: up1
      - switch.turn_off: down1

sensor:
  - platform: duty_time
    id: mup1_time
    name: Manual up1 Time
    sensor: mup1
  - platform: duty_time
    id: mup2_time
    name: Manual up2 Time
    sensor: mup2