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

I’m using the preset mode one as it was basically like for like from my old cards/flows.

1 Like

Yeah, that was the plan for that one.

Hopefully they won’t change anything else to prevent us from using speeds as preset modes.

One of the devs said that we weren’t supposed to use speeds as presets but I could never get any clarification (or even any response at all) as to why.

1 Like

Just as an FYI I realized that the new fan config codes using presets and percentages don’t work using voice commands via Alexa even tho they work fine in HA.

see the issue discussion here:

For anyone who wants the old speed list functionality reinstated…

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.

If that gets done we won’t need the new configs above.

1 Like

Thank @finity, up voted!

I have an IFAN02 with Tasmota on it for my main office ceiling fan. I also have a Nextion-based “Office Controller” mounted on the wall to be able to turn on the lights and fan, as well as set fan speeds. I’d have to go through some machinations to make that work under this system… so I’m not super thrilled with this new percentage- or preset-based setup and would love to have the option to keep the old style.

1 Like

For Tasmota it’s a lot easier than all this. Using Tasmota 9.3+ and the Tasmota Ha integration it just works without YAML…

You still want to use @finity 's fan speed control and the new Percentage one, but it all just works…

For other firmware, you will need to work a little harder.
Thanks @emontnemery !!

@finity

Thank you as always for leading the pack. I’m stuck. Recently upgraded to latest 2021.5 and cannot get HA to recognize that fan is on. I’ve pared pack your very helpful yaml to below, but HA obstinately refuses to read the state topic as anything other than off. I have even put in a simple switch in lovelace and it sends the correct payload of “3” but then turns right off without acknowledging the state

I hope someone can give me a sanity check. I’ve been looking at it for so long I’m sure I must be overlooking an error.

  - platform: mqtt
    name: "ifan1"
    command_topic: "cmnd/iFan1/FanSpeed"
    state_topic: "stat/iFan1/RESULT"
    state_value_template: >
        {% if value_json.FanSpeed > 0 -%}on{%- elif value_json.FanSpeed == 0 -%}off{%- endif %}
    availability_topic: tele/iFan1/LWT
    payload_off: "0"
    payload_on: "3"
    payload_available: Online
    payload_not_available: Offline

and watching the full MQTT feed I see that the commands are going through and state being reported just fine.

May 12 19:41:15 cmnd/iFan1/FanSpeed 3
May 12 19:41:15 stat/iFan1/RESULT {"FanSpeed":3}

I’ve hit that point where the frustration is making it difficult to remember all permutations I’ve tried.

Which version are you using - preset or percentage?

Also you should probably just post all the code for what you are trying right now. that way I can see where you might be off if it’s somewhere else in the code.

you should just be able to literally copy my code from above and replace your entities and topics and it should work.

EDIT:

And thank you for the kind words. :slightly_smiling_face:

@finity
Your mere reply solved it. I was using
image: homeassistant/raspberrypi3-homeassistant:latest
It was one of the 3 2021.5.x versions (I tried a few). I went back to 2021.4.3 and your yaml works perfectly.

Just needed a finite intervention

edit: It also could have been the payload_on tweak I tried. I’d like it to turn on to 3 whenever it goes from off to on (for some existing automations) but maybe that isn’t possible.

edit2: It was in fact the payload_on change. It took tracing it back to the MQTT binary sensor documentation

Cool! It’s like magic! :laughing:

But yes the speed selected by going to on is always “low” speed and I think that is hard-coded into the integration.

I have a template test fan that I set up to make it go back to the last speed it was on before turning off but I had to do that via scripts. I doubt it’s worth it to create another fan entity along with all of the other stuff that needs done to make it work just to get the fan to jump to speed 3 immediately.

1 Like

after 2 hours of playing with the code I found that this works best for me specially I’m using Homekit
the reason that I had to play with it is that when using “preset modes” it shows as a group of 4 switches and when using Siri will not understand something like " Set the kitchen fan to 50%" or " Set the fan to medium " it will just gonna replay with " this function is not available " or can’t do that.

The percentage mode is work best with HomeKit and Siri but you have to specifically ask for 0%, 33%, 66% or 100% even when manually change it from the HomeKit app you will have to fit it exactly to same percentage otherwise it will not work at all.

so my work around it is any thing between 1-33% will be low or level 1 any value 34-66% will be medium or level 2 and from 67-100% that is Max, High or level 3.

and it works perfect with Siri on my HomePod

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

You can streamline that template quite a bit:

percentage_command_template: >
    {% if 1 <= value <= 33 %}
      1
    {% elif 34 <= value <= 66 %}
      2
    {% elif 67 <= value <= 100 %}
      3
    {% else %}
      0
    {% endif %}

I realise this is outside of the card itself, but I suspect we have the best collection of relative experience and expertise here.
I’m seeing this oddity on my ‘new’ fans (since the changes to presets). The card is showing off instead of low, medium, high when the fan is going and I’ve tracked it down to this. The state is on, but the preset moves back to ‘off’. How can the preset be changing on it’s own?

How have you configured the fan? is it an iFan02/03 or some other model?

iFan03, like this - I think it may be the preset of off that’s the issue?

  - platform: mqtt
    name: "Girls Fan"
    command_topic: "cmnd/girls-fan/FanSpeed"
    state_topic: "stat/girls-fan/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.girls-fan.state == 'off' -%}off{%- elif states.fan.girls-fan.state == 'on' -%}on{%- endif %}
      {% endif %}
    availability_topic: tele/girls-fan/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/girls-fan/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/girls-fan/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 %}

I’m not sure why it would go back to off.

I’m using that same config and mine doesn’t do that.

you can try removing the off preset mode and try it tho.

I removed the ‘off’ preset and this has now resolved the issue. The last preset shows in the device state attributes, the but the state is off, then it moves to on and whichever preset has been selected.

Not sure if that’s a bug in the new HA code or the way it’s designed to work?

This is the way mine works using the preset mode code I posted in post #1 above:

Is that not the way yours works?

1 Like

Yes that’s right it does/was working just the same, but after some time, it was showing with the slider as on and preset as off. I’ve set one of my two fans back to have a preset of off and left the other without the preset of off so I can hopefully show more.

Sorry it took a while, but I built a test view in HA to show the issue. The fan shown here has this config in preset;

preset_modes:
  - 'off'
  - 'low'
  - 'medium'
  - 'high'

Here’s what can happen with that config - this is your awesome fan-mode-button-row card and a simple entity card for the same fan. The fan at the time was on medium, but after a short period shows as preset = off but still ‘on’. Another fan with the preset ‘off’ removed in the config doesn’t show any issues now, so that’s a simple fix, but thought I’d let you know the details.

1 Like