MQTT Cover Position Problem

Hi all - i need help with a problem.

I have implemented the following config for my cover. The cover buttons are active and working (blind works as expected) - and the blind takes commands from the position slider.

However, the one thing I cannot figure out is why the position slider does not retain the position of the blind even though I can see the MQTT updates coming back into the broker on the ‘position’ topic - what am i missing?

- platform: mqtt
  name: "MQTT Cover Office"
  device_class: shade
  command_topic: "rblind/1/set"
  position_topic: "rblind/1/position"
  availability_topic: "rblind/1/availability"
  set_position_topic: "rblind/1/set_position"
  qos: 0
  retain: false
  payload_open: "OPEN"
  payload_close: "CLOSE"
  payload_stop: "STOP"
  position_open: 100
  position_closed: 0
  payload_available: "online"
  payload_not_available: "offline"
  optimistic: false

When does it lose the position?

When I close the pop up - it resets back to zero when I open it, its like the slider is ignoring the actaul position - the screen shot below is a great example of it being at zero.

I set the blind to 60% closed 2hrs ago, closed the pop up and its back at zero.
Screenshot 2021-01-22 at 13.35.50

Do you have control over the retained flag for the position messages sent from the cover?

If so, set it to true.

OK i have tried this heres the line from my arduino code - true (retain) flag set at the end

client.publish(TOPIC_OUT1, outstr, true);

Still doesnt work - behaviour is as before.

One thing I cant identify is an MQTT state in HASS - is there a method that I can utilise to check that the state is actaully making it into HASS?

bump - anyone?

ok - so I have been digging into this somewhat and trouble shooting the retain flag.

  1. forcing the retain flag on the client end has no effect unless you have retain set in the cover config on HASS
  2. with retain set on HASS and optionally set on the client then
    a) the position slider does not remember the position, and
    b) unwanted behaviour occurs

My gut feel on this one is there is a problem with the payload by the fact that the payload is a string and it needs to be a INT for the position_topic to recognise it.

Looking at the MQTT Cover documentation there are options to add templates for all topics but the position_topic - i am at a bit of a loss here.

Is it possible to add a template to the positions_topic? Has anyone done this?

guessing this is not possible then?

To answer my own question…

It appears that if the blind does not provide an immediate update on the position topic the position slider defaults to 0 when you close the more info box. Moreover it also appears that if an update is not recieved by home assistant in a finite amount of time it also ignores the position or can exhibit erratic behaviour… c’est la vie!

The solution which is not ideal is to set

optimistic: true

its not ideal as it will remeber the last position set rather than the actual position of the blind - this may help some one else

UPDATE:

I kept digging on this and ultimately raised an issue on GIT. The root cause was with the formatting of the payload on the position_topic.

My original payload had preceding spaces [..payload] - which would have required a template to extract a value so that HASS could then strip the spaces - which is clearly incorrect.

Refactoring the controller code to remove the preceding spaces [payload] AND updating the position_topic with position every couple of seconds the position slider works correctly and not only retains position but you can see it moving with the actual blind position - really nerdy :slight_smile:

This has allowed me to create an auto configuring MQTT blind integration so I can remove the YAML entry completely.