MQTT Covers with HomeKit stuck in Opening/Closing state

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?

Hi There,
Thanks for posting all this info. Did you find a way to fix it?
This is my mqtt cover shelly config

 - platform: mqtt
   name: "Patio Cover"
   state_topic: "shellies/shellyswitch25-xxx/roller/0"
   command_topic: "shellies/shellyswitch25-xxx/roller/0/command"
   position_topic: "shellies/shellyswitch25-xxx/roller/0/pos"
   set_position_topic: "shellies/shellyswitch25-xxx/roller/0/command/pos"
   payload_available: "true"
   payload_not_available: "false"
   qos: 1
   retain: false
   payload_open: "open"
   payload_close: "close"
   payload_stop: "stop"
   position_open: 100
   position_closed: 0
   optimistic: false

And this is what I get in HomeKit
image

Unfortunately no, I gave up.

I created a Template Sensor for each cover, with the state “closed” or “open” based on the current position. For example if the position is under 11, the sensor state is “closed”.

- platform: template
  sensors:
    state_serranda_cameretta:
      value_template: '{% if (state_attr("cover.serranda_cameretta", "current_position") | int) <= 11 %}Closed{% else %}Open{% endif %}'
      friendly_name: 'Apertura Serranda Cameretta'

Obviously this not work with Homekit, but I use scenes or automation that I can activate with Homekit for close one or a group of covers.

Hope this help.