Use the new "Percentage" MQTT Fan integration

Hi all:)

I have a Danish branded Nilan HVAC / Vent system in our house, which uses a custom Modbus(esp8266) interface. It communicates with HA through MQTT.

For now I have the following setup - regarding the fan.

fan:
  - platform: mqtt
    name: "Nilan"
    state_topic: "ventilation/control/RunSet"
    command_topic: "ventilation/runset"
    speed_state_topic: "ventilation/control/VentSet"
    speed_command_topic: "ventilation/ventset"
    qos: 2
    retain: true
    payload_on: "1"
    payload_off: "0"
    payload_low_speed: "2"
    payload_medium_speed: "3"
    payload_high_speed: "4"
    speeds:
      - "off"
      - low
      - medium
      - high

With this setup I can change the fan speed . It actually has 4 speeds (1, 2 ,3 and 4) But the old integration did not allow all 4 speeds.

How should I set it up using the new percentage thing like this example??

# Example using percentage based speeds with preset modes configuration.yaml
fan:
  - platform: mqtt
    name: "Bedroom Fan"
    state_topic: "bedroom_fan/on/state"
    command_topic: "bedroom_fan/on/set"
    oscillation_state_topic: "bedroom_fan/oscillation/state"
    oscillation_command_topic: "bedroom_fan/oscillation/set"
    percentage_state_topic: "bedroom_fan/speed/percentage_state"
    percentage_command_topic: "bedroom_fan/speed/percentage"
    preset_mode_state_topic: "bedroom_fan/speed/preset_mode_state"
    preset_mode_command_topic: "bedroom_fan/speed/preset_mode"
    preset_modes:
       -  "auto"
       -  "smart"
       -  "whoosh"
       -  "eco"
       -  "breeze"
    qos: 0
    payload_on: "true"
    payload_off: "false"
    payload_oscillation_on: "true"
    payload_oscillation_off: "false"
    speed_range_min: 1
    speed_range_max: 100

I have a more primitive setup, but it should be translatable. If you have the 4 levels you could use it as 4 percentiles, and use the templating language to extract and place the information, right?
Something along the lines of this should work

  - platform: mqtt
    name: "Nilan"
    state_topic: "ventilation/control/RunSet"
    command_topic: "ventilation/runset"
    percentage_state_topic: "ventilation/control/VentSet"
    percentage_value_template: >
   {% if value == 1 %}
       25
   {% elif value == 2 %}
       50
   {% elif value == 3 %}
       75
   {% elif value == 4 %}
       100
   {% else %}
       0
   {% endif %}
    percentage_command_topic: "ventilation/ventset"
    qos: 2
    retain: true
    payload_on: "1"
    payload_off: "0"
    percentage_command_template: >
   {% if value < 10 %}
       0
   {% elif value < 38 %}
       1
   {%  elif  value < 63 %}
       2
   {%  elif value < 78 %}
       3
   {% else %}
       4
   {% endif %}

Disclaimer, there might be prettier solutions and the intermediate thresholds of 10,38,63,78 are just an example.

1 Like

Here’s my initial attempt at converting… speed control not working though—open to suggestions (note the commented out parts are the old version—this is a 6-speed fan that was cobbled in HA as 3 speeds):

fan:
#Arlec wall fan (boy's bedroom)
  - platform: mqtt
    name: "Wall fan"
    state_topic: "stat/arlec_fan/POWER1"
    command_topic: "cmnd/arlec_fan/POWER1"
    oscillation_state_topic: "stat/arlec_fan/POWER2"
    oscillation_command_topic: "cmnd/arlec_fan/POWER2"
#    speed_state_topic: "stat/arlec_fan/speed"
#    speed_command_topic: "cmnd/arlec_fan/TuyaSend4"
    percentage_state_topic: "stat/arlec_fan/speed"
    percentage_command_topic: "cmnd/arlec_fan/TuyaSend4"
    percentage_value_template: >-
      {% if value == '3,0' %}
        16
      {% elif value == '3,1' %}
        33
      {% elif value == '3,2' %}
        50
      {% elif value == '3,3' %}
        67
      {% elif value == '3,4' %}
        83
      {% elif value == '3,5' %}
        100
      {% endif %}
    percentage_command_template: >-
      {% if value < 17 %}
        '3,0'
      {% elif value < 34 %}
        '3,1'
      {% elif  value < 51 %}
        '3,2'
      {% elif value < 68 %}
        '3,3'
      {% elif value < 84 %}
        '3,4'
      {% else %}
        '3,5'
      {% endif %}
    qos: 0
    payload_on: 'ON'
    payload_off: 'OFF'
    payload_oscillation_on: 'ON'
    payload_oscillation_off: 'OFF'
 #   payload_low_speed: '3,0'
 #   payload_medium_speed: '3,1'
 #   payload_high_speed: '3,5'
    availability_topic: tele/arlec_fan/LWT
    payload_available: Online
    payload_not_available: Offline
#    speeds:
#      - 'off'
#      - low
#      - medium
#      - high

For additional context (and where I sourced my original setup), see here: https://templates.blakadder.com/arlec_AWDC001HA.html

@AussieByrd Did you figure out the speed control? I have the following:

  - platform: mqtt
    name: "Office Fan Switch"
    state_topic: "stat/tasmota_office-ds03/POWER1"
    command_topic: "cmnd/tasmota_office-ds03/POWER1"
    preset_mode_state_topic: "stat/tasmota_office-ds03/speed"
    preset_mode_value_template: >
      {% if value == '3,0' %}
        low
      {% elif value == '3,1' %}
        low
      {% elif value == '3,2' %}
        medium
      {% elif value == '3,3' %}
        high
      {% else %}
        off
      {% endif %}    
    preset_mode_command_topic: "cmnd/tasmota_office-ds03/tuyasend4"
    preset_mode_command_template: >
      {% if value == 'low' %}
        "3,1"
      {% elif value == 'medium' %}
        "3,2"
      {% elif value == 'high' %}
        "3,3"
      {% else %}
        0 
      {% endif %}
    availability_topic: "tele/tasmota_office-ds03/LWT"
    payload_available: "Online"
    payload_not_available: "Offline"    
    payload_on: "ON"
    payload_off: "OFF"
    preset_modes:
      - 'off'
      - 'low'
      - 'medium'
      - 'high' 

And it appears the preset_mode_command_template is not working.

No luck so far - I’ve gone back to my old setup for now.

Thanks for the heads up. My setup works correctly from the physical switch (i.e. if I change the fan speed it changes in home assistant correctly). It just does not change if I go the other way (i.e. home assistant to the physical switch). That is what leads me to believe that the preset_mode_command_template is wrong.

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.

For anyone who wants the old speed list functionality reinstated.

With help of our local Wizz Simon Frølich the solution is:

fan:
  - platform: mqtt
    name: "Nilan"
    state_topic: "ventilation/control/RunSet"
    command_topic: "ventilation/runset"
    percentage_command_topic: "ventilation/ventset"
    percentage_state_topic: "ventilation/control/VentSet"
    speed_range_min: 1
    speed_range_max: 4
    qos: 2
    retain: true
    payload_on: "1"
    payload_off: "0"
    unique_id: nilan_fan

Scripts will now be looking like this:

alias: Nilan fan speed HIGH
sequence:
  - service: fan.set_percentage
    data:
      percentage: 75
    target:
      entity_id: fan.nilan
mode: single
icon: hass:fan

The “percentage: 75” should be replaced with
0: Off
25: Low
50: Medium
75: High
100: “Vaccume” :slight_smile:

Great - thanks :smiley:

I have an MQTT fan which is running out of time before needing a code change due to the deprecated fan speeds. I’m guessing the FR to not remove the old speed system isn’t going to happen so could someone please help me convert this? (it was pretty much copy / pasted from a tutorial)

fan:
  - platform: mqtt  
    name: "Bedroom Fan"
    unique_id: bedroom_fan  
    command_topic: "tasmota/fans/master_bedroom/cmnd/POWER1"
    state_topic: "tasmota/fans/master_bedroom/tele/STATE"
    state_value_template: "{{ value_json.POWER1 }}"
    speed_command_topic: "tasmota/fans/master_bedroom/cmnd/Backlog"
    speed_state_topic: "tasmota/fans/master_bedroom/tele/RESULT"
    speed_value_template: >
      {% if value_json.TuyaReceived.Data == "55AA03070005030400010016" %}
        Power1 1; TuyaSend4 3,0
      {% elif value_json.TuyaReceived.Data == "55AA03070005030400010117" %}
        Power1 1; TuyaSend4 3,1
      {% elif value_json.TuyaReceived.Data == "55AA03070005030400010218" %}
        Power1 1; TuyaSend4 3,2
      {% endif %}
    availability_topic: tasmota/fans/master_bedroom/tele/LWT
    payload_available: Online
    payload_not_available: Offline
    payload_low_speed: "Power1 1; TuyaSend4 3,0"
    payload_medium_speed: "Power1 1; TuyaSend4 3,1"
    payload_high_speed: "Power1 1; TuyaSend4 3,2"
    payload_off: "OFF"
    payload_on: "ON"
    qos: 1
    retain: false
    speeds:
      - low
      - medium
      - high

Will I also need to change the setup in the fan itself? It’s running Tasmota.

Thanks

Bump… Is there anyone who can please help me convert this to the new format?

Thankfully the tutorial I followed for my fan controller has been updated with the required changes.

Hey Dave, did you need to change your tasmota rules in the end?

Cheers,

Linton

I actually don’t yet have it working properly. I updated things as per the blog post linked above but the functionality isn’t quite right on my device / HA

Evil. Well atleast I’m not the only one. I wished so hard for more than 3 speeds but wow this has been a pain for everyone

If you have the exact fan controller as per that blog post then you can only get max 3 speeds as that is how the hardware is built. No software can change that.

Ha, oh no, I have a 5 speed fan that ive been limited to 3 speeds out of HA

Any update on this, I have the same issue. Had it all working for ages and then it all got depreciated :frowning:

I used the details in this blog post Brilliant Smart Ceiling Fan Remote in Home Assistant and just need to convert it to the new style. I think the key is just having those RF codes added to the HA code.

I also tried to get it working using Taking the old ceiling fan for a smart spin – neon.ninja but doesn’t seem to work properly for me.

fan:
  - platform: mqtt
    name: "esp_fan_bedroom"
    unique_id: "esp_fan_bedroom"
    command_topic: "cmnd/esp_fan_bedroom/POWER1"
    state_topic: "tele/esp_fan_bedroom/STATE"
    state_value_template: "{{ value_json.POWER1 }}"
    speed_command_topic: "cmnd/esp_fan_bedroom/Backlog"
    speed_state_topic: "tele/esp_fan_bedroom/RESULT"
    speed_value_template: >
      {% if value_json.TuyaReceived.Data == "55AA03070005030400010016" %}
        Power1 1; TuyaSend4 3,0
      {% elif value_json.TuyaReceived.Data == "55AA03070005030400010117" %}
        Power1 1; TuyaSend4 3,1
      {% elif value_json.TuyaReceived.Data == "55AA03070005030400010218" %}
        Power1 1; TuyaSend4 3,2
      {% endif %}
    availability_topic: tele/esp_fan_bedroom/LWT
    payload_available: Online
    payload_not_available: Offline
    payload_low_speed: "Power1 1; TuyaSend4 3,0"
    payload_medium_speed: "Power1 1; TuyaSend4 3,1"
    payload_high_speed: "Power1 1; TuyaSend4 3,2"
    payload_off: "OFF"
    payload_on: "ON"
    qos: 1
    retain: false
    speeds:
      - "off"
      - low
      - medium
      - high

vs

  - platform: mqtt
    name: "esp_fan_bedroom"
    command_topic: "cmnd/esp_fan_bedroom/POWER1"
    state_topic: "stat/esp_fan_bedroom/POWER1"
    payload_on: "ON"
    payload_off: "OFF"
    availability_topic: "tele/esp_fan_bedroom/LWT"
    payload_available: "Online"
    payload_not_available: "Offline"
    preset_mode_state_topic: "stat/esp_fan_bedroom/RESULT"
    preset_mode_value_template: >
      {%- if value == '3,0' %}Low
      {%- elif value == '3,1' %}Medium
      {%- elif value == '3,2' %}High
      {%- endif -%}
    preset_mode_command_topic: "cmnd/esp_fan_bedroom/TuyaSend4"
    preset_mode_command_template: >
      {%- if value == "Low" %}3,0
      {%- elif value == "Medium" %}3,1
      {%- elif value == "High" %}3,2
      {%- endif -%}
    qos: 0
    preset_modes:
      - "Low"
      - "Medium"
      - "High"

I’ve replied to you in the Aus thread.