MQTT Covers with HomeKit stuck in Opening/Closing state

Tags: #<Tag:0x00007f7397428558>

Hi all!

I have several roller shutters configured in Home Assistant as covers that I control over the HomeKit component with many Apple devices.
Everything works fine until I change the closed_position in the template definition from 0 to a number greater than 0. This is required to record in Home Assistant that a cover is closed also if is not in position 0. In fact I like to leave the holes between each row of the rolling shutter opened. Normally this number is between 8% to 12% and depends on the roller shutter.

When I change to cover template from this:

- platform: mqtt
  name: "Serranda Cameretta"
  state_topic: "shellies/shellyswitch25-xxx/roller/0"
  state_open: "open"
  position_topic: "shellies/shellyswitch25-xxx/roller/0/pos"
  position_open: 100
  # Chiude a 8
  position_closed: 0
  set_position_topic: "shellies/shellyswitch25-xxx/roller/0/command/pos"
  command_topic: "shellies/shellyswitch25-xxx/roller/0/command"
  payload_open: "open"
  payload_close: "close"
  payload_stop: "stop"
  retain: false
  optimistic: false
  qos: 1

to this (note the position_closed is the only difference):

- platform: mqtt
  name: "Serranda Cameretta"
  state_topic: "shellies/shellyswitch25-xxx/roller/0"
  state_open: "open"
  position_topic: "shellies/shellyswitch25-xxx/roller/0/pos"
  position_open: 100
  # Chiude a 8
  position_closed: 8
  set_position_topic: "shellies/shellyswitch25-xxx/roller/0/command/pos"
  command_topic: "shellies/shellyswitch25-xxx/roller/0/command"
  payload_open: "open"
  payload_close: "close"
  payload_stop: "stop"
  retain: false
  optimistic: false
  qos: 1

the commands sent from an HomeKit device are well executed, but the state on HomeKit is not consistent with the real state of the roller shutter, mainly stuck in Opening or Closing state but sometimes also the opening % is different from the current_position reported from the device.

On Home Assistant all seems to be good, and the state is Closed from the 8/12% to 0%, so I can log the closed state correctly.
Without the changes to the template definition, I’m not able to log the closed state of the roller shutters, but I like to control them via HomeKit without the need to select each of them and see the state.

Have you any hint on a possible way to fix this behaviour?

Thanks in advance!

Maybe I find where is the issue.
I used a MQTT Cover configuration to manage the shutters as you can see on the previous message. To track the position I configured a specific sensor:

# Sensori singole serrande
- platform: mqtt
  name: "Apertura Serranda Studio"
  state_topic: "shellies/shellyswitch25-xxx/roller/0/pos"
  unit_of_measurement: '%'

Looking at the entity States page, when the position of the cover is 8 or less, I found that the cover state is closed because of the “position_closed: 8” on the MQTT Cover configuration, but its “current_position” attribute is 0 instead of 8.
Looking at the sensor state, is correctly reported 8 as current position. This is expected because the sensor is taking the payload value from an MQTT message of the shelly module.

So it seams that the current_position attribute is automatically overrided to 0 as value when the state closed is forced by the position_closed configured on the MQTT Cover configuration.

Where I’m doing wrong? Is this an expected behaviour, or a limitation of the MQTT Cover?