Mqtt Cover with position doesn't show open or closed

Hi there,

can anybody help me? I’m really confused right now…
I have some older remote controlled covers, which are controlled via fhem and some magic :stuck_out_tongue:
Because I want to controll them via homeassistant, I connected them via mqtt and defined the cover in homeassistant like this:

  - platform: mqtt
    name: Fhem_Rollo_01
    unique_id: "fhemRollo01"
    command_topic: "fhem/Rollo_Nr_01/set"
    position_topic: "fhem/Rollo_Nr_01/homekit_pos"
    position_template: "{{ position }}"
    set_position_topic: "fhem/Rollo_Nr_01/set"
    set_position_template: "{{'position_homekit '}}{{ position }}"
    #availability_topic: "fhem/connection/status"
    payload_available: "true"
    payload_not_available: "false"
    payload_open: "open"
    payload_close: "closed"
    payload_stop: "stop"
    state_opening: "drive-up"
    state_closing: "drive-down"
    position_open: 100
    position_closed: 0
    optimistic: false
    qos: 1

At first sight, this works rather well. I can open and close them via the buttons and I can the position via the slider.
But there are some problems:

  • It doesn’t show me the state of the cover. My covers are closed at 0% and open at 100%. This is not reflected in homeassistant. Is it possible to calculate the state from the position? I thought, position_open: 100 position_closed: 0 would be sufficent.
  • Because my cover integration in fhem only accepts multiples of 10% as values for the covers, it is very hard to control the position via the slider in the dashboard. What is the best way to control and send only multiples of 10 as the position?
  • Bonus question: Let’s say I didn’t want to put 20+ covers with nearly identical mqtt topics in my configuration. Are anchors the way to do this?

If you are still reading this, thank you.
At last but not least, I’d like to apologise for butchering the english grammar but english is not my native tongue. :wink:

I haven’t used “position” before (I use tilt_position for my tilt blinds), but I agree that position_open/closed, should determine the state. A suggestion would be to use a state_topic: anyway. I would suggest you make it the same as the position_topic. This way you can use a template to set the state based on position (example position=0 is closed, otherwise open). I’ve not used state_opening/closing, but I recommend you use state_open/closed. So something like:

state_topic: "fhem/Rollo_Nr_01/homekit_pos"
state_open: "on"
state_closed: "off"
value_template: '{% if value == 0 -%}off{%- else -%}on{%- endif %}'

Using set_position_template…I did the following in the developer’s tool, so maybe it would work for you.

{% set position = 67 %}
{% if (position%10) > 5 %}
    round up {{ position - position%10 +10 }}
{% else %}
   round down {{position - position%10 }}
{% endif %}