MQTT template cover not updated

Hello,
this is my first discussion here even if I’m using Home Assistant since some years.

I’ve faced an issue today with my shelly 2.5 used for a cover, seems that home assistant entity is not updated correctly even if MQTT message contains the updated value.

This misalignment always happens when shelly reboots, the reboot sometimes happens when moving cover with manual switches so the “real cover position” is different than what home assistant shows.
I thought that the issue was related to what shelly publishes to MQTT, but today I’ve investigated deeply and I can state that shelly works correct, the issue is in HA, here are my checks.

This is my mqtt cover (I know I’ll move away from yaml, I’ll do next months):

cover:
  - platform: mqtt
    unique_id: "camera_matr.finestra"
    name: "Finestra Camera matr."
    command_topic: "shellies/tapp/camera_matr/fin/roller/0/command"
    position_topic: "shellies/tapp/camera_matr/fin/info"
    #position_topic: "shellies/tapp/camera_matr/fin/info"
    #position_template: "{{ value_json.rollers[0].current_pos }}"
    position_topic: "shellies/tapp/camera_matr/fin/roller/0/pos"
    position_template: "{{ value }}"
    set_position_topic: "shellies/tapp/camera_matr/fin/roller/0/command/pos"
    availability_topic: "shellies/tapp/camera_matr/fin/online"
    payload_available: "true"
    payload_not_available: "false"
    retain: false
    payload_open: "open"
    payload_close: "close"
    payload_stop: "stop"
    position_open: 100
    position_closed: 15
    optimistic: false
    qos: 0

The main point is “position_topic” and “position_template”, I’ve tested two way to get the current position but no one works.

Using the MQTT dump service for both position_topic I get:

  1. “info” topic
shellies/tapp/camera_matr/fin/info,{"wifi_sta":{"connected":true,"ssid":"my_ssid","ip":"my_ip","rssi":-72},"cloud":{"enabled":false,"connected":false},"mqtt":{"connected":true},"time":"08:18","unixtime":1656055080,"serial":4,"has_update":false,"mac":"mac_addr","cfg_changed_cnt":0,"actions_stats":{"skipped":0},"rollers":[{"state":"stop","source":"input","power":0.00,"is_valid":true,"safety_switch":false,"overtemperature":false,"stop_reason":"normal","last_direction":"close","current_pos":22,"calibrating":false,"positioning":true}],"meters":[{"power":0.00,"overpower":0.00,"is_valid":true,"timestamp":1656058680,"counters":[0.000, 0.000, 0.000],"total":0},{"power":0.00,"overpower":0.00,"is_valid":true,"timestamp":1656058680,"counters":[0.000, 0.000, 0.000],"total":0}],"inputs":[{"input":0,"event":"","event_cnt":0},{"input":0,"event":"","event_cnt":0}],"temperature":49.50,"overtemperature":false,"tmp":{"tC":49.50,"tF":121.11, "is_valid":true},"temperature_status":"Normal","update":{"status":"idle","has_update":false,"new_version":"20220209-093016/v1.11.8-g8c7bb8d","old_version":"20220209-093016/v1.11.8-g8c7bb8d"},"ram_total":49920,"ram_free":36808,"fs_size":233681,"fs_free":144325,"voltage":237.87,"uptime":38362}

to extract the current_pos I’ve used the following template, tested on developer’s template tab

{{ value_json.rollers[0].current_pos }}

using this template on developer’s tab with the same son gives me the correct value “22”, but using into yaml it gives a different value ( 8 )

  1. “roller/0/pos” topic
    the dump is :
shellies/tapp/camera_matr/fin/roller/0/pos,22

when testing in developer mode the template position_template: "{{ value }}" I get 22, using it into yaml configuration I get again a different value ( 8 again).

After every yaml changes I’ve reloaded MQTT and template configuration from settings, but it never worked.

Even restarting HA does not solve.

EDIT: the only way to “solve” this issue is to completely open the cover, so the value 100% in HA is aligned to the real cover position.

Is it a configuration issue ?
What’s wrong ?

I’m using Home Assistant docker image 2022.6.6 .

Thank you all and sorry for this long first topic :slight_smile:

You can only have one position_topic and one position_template. You have two topics:

Replace all that with this:

    position_topic: "shellies/tapp/camera_matr/fin/info"
    position_template: "{{ value_json.rollers[0].current_pos }}"

Hi Tom,
sorry I did mistake when pasting here to include both version.

sorry again, the one here is completely wrong.

The config I have is the following (and it’s not working):

cover:
  - platform: mqtt
    unique_id: "bagno1.finestra"
    name: "Finestra Bagno gr."
    command_topic: "shellies/tapp/bagno_gr/fin/roller/0/command"
    #position_topic: "shellies/tapp/camera_matr/fin/info"
    #position_template: "{{ value_json.rollers[0].current_pos }}"
    position_topic: "shellies/tapp/camera_matr/fin/roller/0/pos"
    position_template: "{{ value }}"
    set_position_topic: "shellies/tapp/bagno_gr/fin/roller/0/command/pos"
    availability_topic: "shellies/tapp/bagno_gr/fin/online"
    payload_available: "true"
    payload_not_available: "false"
    retain: false
    payload_open: "open"
    payload_close: "close"
    payload_stop: "stop"
    position_open: 100
    position_closed: 17
    optimistic: false
    qos: 0

Try this:

cover:
  - platform: mqtt
    unique_id: "bagno1.finestra"
    name: "Finestra Bagno gr."
    command_topic: "shellies/tapp/bagno_gr/fin/roller/0/command"
    position_topic: "shellies/tapp/camera_matr/fin/info"
    position_template: "{{ value_json.rollers[0].current_pos }}"
    set_position_topic: "shellies/tapp/bagno_gr/fin/roller/0/command/pos"
    availability_topic: "shellies/tapp/bagno_gr/fin/online"
    payload_available: "true"
    payload_not_available: "false"
    retain: false
    payload_open: "open"
    payload_close: "close"
    payload_stop: "stop"
    position_open: 100
    position_closed: 17
    optimistic: false
    qos: 0

Sorry Tom but I did a mistake again, this is not my day :frowning:
It’s not a mix of “camera_matr” and “bagno_gr” covers (I’ve seven of them so making mistake it’s very easy).

The config is this one:

cover:
  - platform: mqtt
    unique_id: "camera_matr.finestra"
    name: "Finestra Camera matr."
    command_topic: "shellies/tapp/camera_matr/fin/roller/0/command"
    position_topic: "shellies/tapp/camera_matr/fin/info"
    position_template: "{{ value_json.rollers[0].current_pos }}"
    #position_topic: "shellies/tapp/camera_matr/fin/roller/0/pos"
    #position_template: "{{ value }}"
    set_position_topic: "shellies/tapp/camera_matr/fin/roller/0/command/pos"
    availability_topic: "shellies/tapp/camera_matr/fin/online"
    payload_available: "true"
    payload_not_available: "false"
    retain: false
    payload_open: "open"
    payload_close: "close"
    payload_stop: "stop"
    position_open: 100
    position_closed: 15
    optimistic: false
    qos: 0

now looking to your answer, seems like mine, am I right or I’m so tired to not seeing any differences ?

consider also that topic “shellies/tapp/camera_matr/fin/info” is refreshed every two minutes from another automation, meanwhile topic “shellies/tapp/camera_matr/fin/roller/0/pos” is refreshed by device at its change and is retained by broker.

if those templates are expected to work, but in reality its value isn’t refreshed, should I open a defect on GitHub ?

Thanks,

An update.

The issue happened again (shelly 2.5 reboots and the cover’s position is misaligned), even if I’ve updated to 2022.6.7 version and using the following configuration:

cover:
  - platform: mqtt
    unique_id: "camera_matr.finestra"
    name: "Finestra Camera matr."
    command_topic: "shellies/tapp/camera_matr/fin/roller/0/command"
    position_topic: "shellies/tapp/camera_matr/fin/roller/0/pos"
    position_template: "{{ value }}"
    set_position_topic: "shellies/tapp/camera_matr/fin/roller/0/command/pos"
    availability_topic: "shellies/tapp/camera_matr/fin/online"
    payload_available: "true"
    payload_not_available: "false"
    retain: false
    payload_open: "open"
    payload_close: "close"
    payload_stop: "stop"
    position_open: 100
    position_closed: 15
    optimistic: false
    qos: 0

MQTT dump service wrote this file:

shellies/tapp/camera_matr/fin/roller/0/pos,19

This is the position from HA:

Thanks.

Due to upload limitation, I’ve to split the screenshot in many replies, sorry.

This is template tab:

This is from Shelly webpage
shelly_pos

And this is from MQTTfix tool

Hi,
after some deep investigation, I’ve understood which is the error.
It’s the position_closed: 15 that misaligns MQTT value with HA value.