Mqtt fan control for cbus fan controller

Hi,

I’m trying to fix my fan controller which is connected via MQTT to my CBUS network. I am using this in combination with a custom lovelace integration called fan-percentage-button-row to control the fan speed (buttons send percentage speeds) as well as a standard entity card.

Whilst I have the fan working for the most part, the percentage output doesn’t seem to be updating IN the entity itself which the Lovelace integration is expecting (i presume). The percentage field under developer tools always shows 0. Also, I cannot turn the fan off except when I move the slider when clicking on entity card to anywhere between 1-9 (less than 10 based on config but not 0)

Here is my current config that I am hoping to get help with…

Notes,

  • topic …/state returns on/off whereas …/level returns value of speed
  • speed for cbus ranges from 0-255 (255 = 100%)
  • cbus fan controller operates with 3 speeds (33% - 86, 67% - 170, 100% - 255)

  - platform: mqtt
    name: Living Room Ceiling Fan (CBUS)
    state_topic: "cbus/read/254/56/23/state"
    command_topic: "cbus/write/254/56/23/ramp"
    percentage_command_topic:  "cbus/write/254/56/23/ramp"
    percentage_command_template: >
      {% if value == off %}
        0
      {% elif value < 10 %}
        0
      {% elif value < 34 %}
        86
      {% elif value < 68 %}
        170
      {% else %}
        255
      {% endif %}  
    percentage_state_topic: "cbus/read/254/56/23/level"
    percentage_value_template: >
      {% if value == 86 %}
         33
      {% elif value == 170 %}
         66
      {% elif value == 255 %}
         100
      {% else %}
         0
      {% endif %}