Help with the new MQTT fan control

I have a fan controller that HA controls via MQTT. It offers 3 speeds: low, medium, high. Prior to 2021.4, I had my fan entities defined as follows:

- platform: mqtt
  name: "livingroom fanlinc fan"
  command_topic: 'insteon/aa.bb.cc/fan/set'
  state_topic: 'insteon/aa.bb.cc/fan/state'
  speed_command_topic: 'insteon/aa.bb.cc/fan/speed/set'
  speed_state_topic: 'insteon/aa.bb.cc/fan/speed/state'

With the change of the fan entity model in 2021.04 and the depreciation of speed_command_topic and speed_state_topic, I’m trying to redefine my entities with templates. Below is my attempt but it is not working. Can anyone share a similar config?

- platform: mqtt
  name: "office fanlinc fan"
  command_topic: 'insteon/aa.bb.cc/fan/set'
  state_topic: 'insteon/aa.bb.cc/fan/state'
  percentage_command_topic: 'insteon/aa.bb.cc/fan/speed/set'
  percentage_command_template: >
    {% if value < 10 %}
       off
    {% elif value < 40 %}
       low
    {%  elif  value < 80 %}
       medium
    {% else %}
       high
    {% endif %}  
  percentage_state_topic: 'insteon/aa.bb.cc/fan/speed/state'
  percentage_value_template: >
    {% if value == low %}
       33
    {% elif value == medium %}
       66
    {% elif value == high %}
       100
    {% else %}
       0
    {% endif %}  

Look at the code I came up with for my mqtt fan in this post:

It’s for an iFan03 but it has a similar structure to what you need.

My fan expects 0, 1, 2, 3 for your off low medium high but if you substitute your values in for mine it should work for you.

The only other thing you will need is to figure out how the insteon light reports it’s state.

Mine uses a json coded value called “FanSpeed” so you will need to change that to whatever your integration reports.

If you can’t get it working let me know and I’ll help you dig into it deeper.

1 Like

Thank you for pointing the way. I got this to work with the following:

- platform: mqtt
  name: "office fanlinc fan"
  command_topic: 'insteon/aa.bb.cc/fan/set'
  state_topic: 'insteon/aa.bb.cc/fan/state'
  percentage_command_topic: 'insteon/aa.bb.cc/fan/speed/set'
  percentage_command_template: >
      {% if value < 10 %}
         off
      {% elif value < 40 %}
         low
      {% elif value < 75 %}
        medium
      {% else %}
         high 
      {% endif %}
  percentage_state_topic: 'insteon/aa.bb.cc/fan/speed/state'
  percentage_value_template: >
      {% if value == 'low' %}
        33
      {% elif value == 'medium' %}
        67
      {% elif value == 'high' %}
        100
      {% else %}
        0
      {% endif %}

If you want to keep the old speed lists then I’ve requested that the old speed list options should be kept and I’ve had a suggestion from a dev that if a FR gets enough votes they would implement it.

Here is the FR. Please go there and vote it up.