Should a mqtt cover only send close command when cover is open and vice versa?

I’ve been trying to reconfigure my mqtt/shelly-1 garage door following these guides:

However, I’ve encountered an issue where HA will send the ‘close’ command, even if the door is closed – this causes the door to open which is unexpected

This post suggests using a script to mitigate the issue which I’ve implemented, but it requires a lot of extra scripts and a second cover. It seems like an excessive workaround.

My question is: In the case where the cover is closed and the ‘close_cover’ service is called - shouldn’t the cover itself do nothing? If that’s the case, am I missing something from my config?

cover:
  - platform: mqtt
    name: garage_door
    device_class: garage
    retain: false
    command_topic: "shellies/shelly1-garage-door-2/relay/0/command"
    payload_open: "on"
    payload_close: "on"
    payload_stop: "on"
    state_topic: "shellies/shelly1-garage-door-2/input/0"
    state_open: "0"
    state_closed: "1"
    availability_topic: "shellies/shelly1-garage-door-2/online"
    payload_available: "true"
    payload_not_available: "false"    

It was suggested here by @petro (Need help with if/else) that the cover should be doing this, but maybe the value_template was incorrect.

In my case, I don’t think it’s that issue though. Using Node-RED to inspect the contents of my state_topic, I can see that the values are either “0” or “1” indicating open/closed:

Node-RED_-_Home_Assistant

How are you triggering the close cover, are you using a script or some sort of automation to call it? I see you mentioned the close_cover service, have you tried “cover. close_cover” instead?

I’ve been calling it in node-red, because ultimately I generally use this with HomeKit which calls close_cover or open_cover depending on the state

Ok, that makes sense as I too had the same type of problem when I tried to trigger any sort of automation through HomeKit. My fix was to create a scripts.yaml with the following:

garage_door_2_close_cover:
  alias: garage_door_2_close_cover
  sequence:
    - condition: state
      entity_id: binary_sensor.shelly_shsw_1_b8f683_switch
      state: 'on'
    - service:  switch.turn_on
      data:
        entity_id: switch.shelly_shsw_1_b8f683

Then in the actual cover I added the below line so it links to that script whenever close_cover is called:

close_cover:
          service: script.garage_door_2_close_cover

I’m using the Template platform with my cover and I’m also not very well versed MQTT so I don’t know how to adapt this solution to your setup.

Yes yes - I understand that’s a “fix” but as stated in OP it seems like a big workaround for something that seems like it shouldn’t need to exist.

How did you end up resolving this @jaaasshh ? I have the same issue and thoughts as you

Edit: actually I have been able to solve in my instance by instead using the template cover and following the example in the current documentation (Template Cover - Home Assistant) which includes a condition to check the state. Maybe this isn’t an option for mqtt cover?
Will see how reliable the shelly is used like this.

close_cover:
          - condition: state
            entity_id: sensor.garage_door
            state: "on"
          - service: switch.turn_off
            target:
              entity_id: switch.garage_door