How-to: Using the iFan03/iFan02 running Tasmota on MQTT with the newest updates to the fan control models after HA V2021.3.x

For anyone that is trying to configure their iFan03/02 MQTT fans using the newest fan controls here are the ways I have configured mine.

I’ve tested both of the code configs below on the iFan03 but they should also work on the iFan02 as long as the topics are the same.

There are two ways to set these fans up now - using “percentages” or using “presets” for the speed controls.

With both of these configurations you will need to adjust your topics to the correct ones for your fans.

Here is the config used to control by percentages:

fan:
  - platform: mqtt
    name: "Master Bedroom Fan Percents"
    command_topic: "cmnd/iFan03-2/FanSpeed"
    state_topic: "stat/iFan03-2/RESULT"
    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.master_bedroom_fan.state == 'off' -%}off{%- elif states.fan.master_bedroom_fan.state == 'on' -%}on{%- endif %}
      {% endif %}
    availability_topic: tele/iFan03-2/LWT
    payload_off: "off"
    payload_on: "on"
    payload_available: Online
    payload_not_available: Offline
    percentage_command_template: >
      {% if value == 33 %}
        1
      {% elif value == 66 %}
        2
      {% elif value == 100 %}
        3
      {% else %}
        0 
      {% endif %}
    percentage_command_topic: "cmnd/iFan03-2/FanSpeed"
    percentage_state_topic: "stat/iFan03-2/RESULT"
    percentage_value_template: >
      {% if value_json.FanSpeed == 1 %}
        33
      {% elif value_json.FanSpeed == 2 %}
        66
      {% elif value_json.FanSpeed == 3 %}
        100
      {% else %}
        0 
      {% endif %}

Here is the one that uses the preset modes (I think this is my preferred method as it works as closely to the old way as possible):

fan:
  - platform: mqtt
    name: "Master Bedroom Fan Presets"
    command_topic: "cmnd/iFan03-2/FanSpeed"
    state_topic: "stat/iFan03-2/RESULT"
    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.master_bedroom_fan.state == 'off' -%}off{%- elif states.fan.master_bedroom_fan.state == 'on' -%}on{%- endif %}
      {% endif %}
    availability_topic: tele/iFan03-2/LWT
    payload_off: "off"
    payload_on: "on"
    payload_available: Online
    payload_not_available: Offline
    preset_modes:
      - 'off'
      - 'low'
      - 'medium'
      - 'high'
    preset_mode_command_topic: "cmnd/iFan03-2/FanSpeed"
    preset_mode_command_template: >
      {% if value == 'low' %}
        1
      {% elif value == 'medium' %}
        2
      {% elif value == 'high' %}
        3
      {% else %}
        0 
      {% endif %}
    preset_mode_state_topic: "stat/iFan03-2/RESULT"
    preset_mode_value_template: >
      {% if value_json.FanSpeed == 1 %}
        low
      {% elif value_json.FanSpeed == 2 %}
        medium
      {% elif value_json.FanSpeed == 3 %}
        high
      {% else %}
        off
      {% endif %}

Now that I’ve finally been able to work these out I will finish up working on my new fan control rows for Lovelace.

there may be some changes to this if the github discussion on the topic inspires any changes.

8 Likes

Also I haven’t been able to test version 2 with presets to see if the voice assistants (I use Echo’s) will recognize the speeds. And I probably won’t get to it it for a few days.

So if anyone wants to try this out and report back that would be helpful.

Using Version 2 with presets with fan-percent-button-row. It doesn’t work with fan-control-entity-row. Works well except:

When i press the Off switch from the details window, then preset dropbox in details window goes to ‘off’ directly, as expected.

But when i press Off button in fan percent row entity, in details window, Preset dropbox stays at the last preset even tough the fan is off.

I am not using any assistant so i couldn’t test it.

Thanks a lot for the .yaml and the components…

EDIT: I think the Off button in fan percent row entity sets the percent to 0 but it does not really switch off the Fan… Becuse the on/off button statys switched on even tough the percent is 0.

Right, that plugin will “kind of” work for now until they fully deprecate the speed list. But you will get warnings in the log because it uses the fan.set_speed service which is going to be deprecated along with the speed list.

It shouldn’t work at all really using the percentages because it doesn’t use the correct service (as noted above).

It might still work somewhat since, for now, the fans still contain a speed list.

That’s why I need to get the other two plugins going.

Have you tried the fan-percent-button-row yet?

It might have some bugs that I need to work out but it worked well in my setup using template fans I created to test it.

For sonoff ifan03, i actually use your yaml with preset modes above, together with fan-percent-button-row component. The bug for fan-percent-button-row is as i stated in my previous message…

Oh, sorry for the confusion.

If you are using preset modes the fan-percent-button row won’t work either since it uses the set_percentage service.

If you are using presets then the service needs to be set_preset_mode.

I’m working on a new plugin to use preset modes but I haven’t had any time to finish it yet since I just figured out how the new stuff was supposed to work.

I have to say they definitely took something that worked fairly easy and straight forward and turned it into a convoluted mess with the new updates for fans.

1 Like

Thank god for your post and plugin, confirm the percentage mode works. I was able to get my ifan running along with the Fan Percent Button Row.

1 Like

@febalci

I saw your post at the github repo.

I made a change I think will fix it so please try the updated code there.

Make sure after you copy the new file to your system that you clear the cache after restarting HA so the changes get picked up.

@finity,

Works perfectly now, thank you very much…

Awesome!

Thanks for testing it out!

Now on to getting the “preset mode” plugin working.

I also saw your post in the issue on the github repo.

Is that still active or has this thread resolved it?

I’d like to close that issue if it has.

1 Like

All good, working as expected now. thanks to you​:relieved: :pray:

1 Like

finity

Once again, thank you for all your work on these fans. Would not be able to use them as well without you.

Version 1, along with fan-percent-button-row all working for me.

Thanks.

Happy to test preset mode plugin if you need anyone.

1 Like

Hi
I’m using the first version percentages but I’ve found if the fan is on and I reboot Home Assistant the fan percent row shows the fan as off when HA comes back online. Is there anyway to fix that?
Thanks
Dan

I had troubles with that in the past but I use the following automation to check for the current state of the fan on HA restart:

- alias: 'Check MBR Ceiling Fan State on HA Start'
    initial_state: 'on'
    trigger:
      platform: homeassistant
      event: start
    action:
      - service: mqtt.publish
        data:
          topic: "cmnd/iFan03-2/FanSpeed"
          payload: ""

an empty payload will just cause the fan to report it’s current state and not change anything.

1 Like

That fixed it. Thanks! :slight_smile:

1 Like

I have to say they definitely took something that worked fairly easy and straight forward and turned it into a convoluted mess with the new updates for fans.

Well it wouldnt be HomeAssistant without that. :wink: Isnt one of the unspoken requirements of core pr’s that the code need not be more complicated and adding unnecessary workarounds, etc?

Yet, I feel on every few updates, the client side coding needs to be unnecessarly add-ed to.

oh well.

1 Like

I finally got the new plugin ready for use with fans using preset modes.

try it out here:

It’s not in HACS yet and TBH, there seems to be a pretty bad backlog of repos that need to be added to the HACS default list so I’m not sure when this will get added to HACS. So you will likely need to install this manually if you want to try it out.

It will look the same as my other plugins and will be just as theme-able.

And I have it set up for fans to use either two or three preset modes.

Give it a try and let me know (as usual) if you have any issues.

Brilliant as always, got the new plugin and copied the examples at the top and now have working fans for the future - I was dreading this breaking change but it was nice and easy, thanks Finity!

For anyone using Node-Red on their Fans (I use it to cycle speeds/off from RF switches) there’s also one breaking change in that the fan no longer reports a speed, but a preset as the current ‘state’. So you’ll need to use data.attributes.preset_mode to detect where in the speed range the fan is.

1 Like

Glad I could be of help.

Which one are you using the mode or percent plugin?