MQTT fan speeds

I have multiple MQTT operated fans and it worked (still works but will be deprecated soon) well.
The newer version of MQTT fan in 2021.4.x does not work with the old style I used earlier.

The message after updating HA is:

Logger: homeassistant.components.mqtt.fan
Source: helpers/config_validation.py:738
Integration: MQTT (documentation, issues)
First occurred: 8:27:58 PM (12 occurrences)
Last logged: 8:27:58 PM

The ‘payload_low_speed’ option near /config/configuration.yaml:170 is deprecated, please remove it from your configuration
The ‘payload_medium_speed’ option near /config/configuration.yaml:170 is deprecated, please remove it from your configuration
The ‘speeds’ option near /config/configuration.yaml:170 is deprecated, please remove it from your configuration
The ‘speed_command_topic’ option near /config/configuration.yaml:170 is deprecated, please remove it from your configuration
The ‘speed_state_topic’ option near /config/configuration.yaml:170 is deprecated, please remove it from your configuration

My configuration looks like:

  - platform: mqtt
    name: "Fan"
    availability_topic: "fancontrols/fancontrol-32942c/available"
    state_topic: "fancontrols/fancontrol-32942c/state"
    command_topic: "fancontrols/fancontrol-32942c/set"
    speed_state_topic: "fancontrols/fancontrol-32942c/speed/state"
    speed_command_topic: "fancontrols/fancontrol-32942c/speed/set"
    qos: 0
    payload_on: "on"
    payload_off: "off"
    payload_low_speed: "low"
    payload_medium_speed: "medium"
    payload_high_speed: "high"
    speeds:
      - "off"
      - low
      - medium
      - high

I can not figure out how to translate the ‘speeds’ to percentages like 0, 33, 66, 100 to select the speeds in MQTT.
How do I translate the percentages from HA to the payloads on the MQTT bus?

Thanks for helping!

see if this thread could help you out at all.

it’s specifically for the Sonoff iFan03 but it should be easily modified to work with any MQTT fan that has 3 speeds.

The config I have made from the suggestion above is:

  - platform: mqtt
    name: "Fan"
    command_topic: "fancontrols/fancontrol-32942c/set"
    state_topic: "fancontrols/fancontrol-32942c/state"
    state_value_template: >
      {% if value_json.FanSpeed is defined %}
        {% if value_json.FanSpeed == 0 -%}off{%- elif value_json.FanSpeed > 0 -%}on{%- endif %}
      {% else %}
        {% if states.fan.fan.state == 'off' -%}off{%- elif states.fan.fan.state == 'on' -%}on{%- endif %}
      {% endif %}
    availability_topic: "fancontrols/fancontrol-32942c/available"
    payload_off: "off"
    payload_on: "on"
    preset_modes:
      - 'low'
      - 'medium'
      - 'high'
    preset_mode_command_topic: "fancontrols/fancontrol-32942c/speed/set"
    preset_mode_command_template: >
      {% if value == 'low' %}
        low
      {% elif value == 'medium' %}
        medium
      {% elif value == 'high' %}
        high
      {% else %}
        off 
      {% endif %}
    preset_mode_state_topic: "fancontrols/fancontrol-32942c/speed/state"
    preset_mode_value_template: >
      {% if value_json.FanSpeed == low %}
        low
      {% elif value_json.FanSpeed == medium %}
        medium
      {% elif value_json.FanSpeed == high %}
        high
      {% else %}
        off
      {% endif %}

The logs do not show an error on this one, so it is fixed!

1 Like

I was close but not close enough :face_with_raised_eyebrow:

The config I am using now is:

  - platform: mqtt
    name: "Fan"
    command_topic: "fancontrols/fancontrol-32942c/set"
    state_topic: "fancontrols/fancontrol-32942c/state"

    availability_topic: "fancontrols/fancontrol-32942c/available"
    payload_off: "off"
    payload_on: "on"
    preset_modes:
      - 'low'
      - 'medium'
      - 'high'
    preset_mode_command_topic: "fancontrols/fancontrol-32942c/speed/set"

    preset_mode_state_topic: "fancontrols/fancontrol-32942c/speed/state"

I want to use the GitHub - finity69x2/fan-control-entity-row: Provides a means to show a compact graphical control row for 2 or 3 speed fans in Home Assistant with this setup but it does not work as expected.

I tried to do some translations and used a dummy mqtt subscription to port the values but had no luck.

How do I translate the fan preset modes to the custom fan control buttons?

You will need to use the fan-mode-button-row plugin.

I have overlooked that one… :roll_eyes: (looks similar to the fan control entity row)

Thanks for pointing in the right direction. Now it works well!

1 Like

it’s very new. Just released in HACS a few days ago.

1 Like

Looks like it works well!
Thanks for your time and plug-in.

1 Like

Hey Guys, Since you seem to know what youre talking about in this topic, maybe you could help me?

I have an ITHO Fan box wich i control with MQTT, and the logs tell me the way it works now wel be ending soon.

On the end is the code wich i have, and i have not a single clue how to change it to the new method.

Do you have any suggestions?
Thanks!

sensor:

 - platform: mqtt

   name: Tijd

   state_topic: "ITHO/Fan/Timer"

   value_template: "{{value}}"

   unit_of_measurement: 's'

 - platform: mqtt

   name : Snelheid

   state_topic: "ITHO/Fan/State"

   value_template: >

     {% if value|float==0 %}Standby{% endif %}

     {% if value|float==1 %}Laag{% endif %}

     {% if value|float==2 %}medium{% endif %}

     {% if value|float==3 %}Hoog{% endif %}

     {% if value|float==4 %}Full{% endif %}

     {% if value|float>=11 %}Hoog(T){% endif %}

 

fan:

 - platform: mqtt

   command_topic: "ITHO/Fan/cmd"

   state_topic : "ITHO/Fan/State"

   speed_command_topic: "ITHO/Fan/cmd"

   speed_state_topic: "ITHO/Fan/State"

   state_value_template: "{% if value|float==0 %}State 0{% endif %}{% if value|float >0 %}State 1{% endif %}"

   speed_value_template: "{% if value|float==0 %}State 0{% endif %}{% if value|float >0 and value|float <=4 %}State {{value}}{% endif %}{% if value|float >=11 %}State 3{% endif %}"

   payload_on: "State 1"

   payload_off: "State 0"

   payload_low_speed: "State 1"

   payload_medium_speed: "State 2"

   payload_high_speed: "State 3"

   optimistic: "true"

   name: Afzuiging Badkamer

   speeds:

     - low

     - medium

     - high


group:

 Ventilator:

   entities:

     - fan.afzuiging_badkamer

     - sensor.Snelheid

     - sensor.Tijd
1 Like

@Nightraider did you find a way to rewrite this?
I have updated HA to the latest version and now it’s not a warning but an error. :frowning:

Ik got it working with this

1 Like