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

Hi, I am having trouble getting the ifan02 to respond correctly. It is on Tasmota 9.1.0. Setup as an iFan02 per the Tasmota wiki:

I’ve copied the code from post #1 above for the fan, here is my configuration.yaml for both the light and fan:

light:
  - platform: mqtt
    name: "Living Room Fan Light"
    state_topic: "stat/sonoff_ifan02_1/POWER1"
    state_value_template: "{{ value_json['values']['POWER1'] }}"
    command_topic: "cmnd/sonoff_ifan02_1/POWER1"
    availability_topic: "tele/sonoff_ifan02_1/LWT"
    qos: 1
    payload_on: "ON"
    payload_off: "OFF"
    payload_available: "Online"
    payload_not_available: "Offline"
    retain: false

fan:
  - platform: mqtt
    name: "Living Room Fan"
    command_topic: "cmnd/sonoff_ifan02_1/FanSpeed"
    state_topic: "stat/sonoff_ifan02_1/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/sonoff_ifan02_1/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/sonoff_ifan02_1/FanSpeed"
    percentage_state_topic: "stat/sonoff_ifan02_1/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 %}
    qos: 1

I have a Lovelace card using the fan-percent-button-row.js from your GitHub dated 5-June, with the fan and light:

type: entities
entities:
  - entity: fan.living_room_fan
    type: custom:fan-percent-button-row
    secondary_info: last-changed
  - entity: light.living_room_fan_light
    icon: hass:ceiling-light
    secondary_info: last-changed

That gives me a card that looks like this:

card

So here is the PROBLEM:

Fan: If I click the “HIGH” button on the Lovelace card the fan turns on high but I get no response on the card, the “OFF” button remains highlighted blue. The “MED” and “LOW” buttons also change the speed, but again, they don’t highlight, the “OFF” button stay blue. Pressing the “OFF” button does nothing. It doesn’t respond at all. I have to click on the words ‘Living Room Fan’, the slider is at ‘0’ even through the fan is on high, med, or low. I have to drag it right a little and then back to 0 to get it to turn off.

Light: similar problem. If click the toggle next to the ‘Living Room Fan Light’ it momentarily slides right and blue, the light turns on, but then the toggle goes back to off even though the light is on. Subsequent actuations of the toggle do nothing since the light is already on. No way to turn it off.

I think the problem is my iFan02 Tasmota does not recognize the commands “RESULT” nor “LWT” for the ‘state_topic’, ‘percentage_state_topic’, and ‘availability_topic’ MQTT commands. I get ‘{“Command”:“Unknown”}’ for both in the Tasmota console when I try “stat/sonoff_ifan02_1/RESULT” or “tele/sonoff_ifan02_1/LWT” in the console. However, changing the word to ‘FanSpeed’ gives a result. See below:

Any insights onto why “RESULT” and “LWT” are not recognized or why I can send commands but not receive feedback from the device is greatly appreciated, thanks!

2 Likes

Anyone know why my MQTT commands are not changing the state of the entity?

are you having issues with the fan entity itself in HA because of the fan template or are the MQTT commands not working to change the state of the device even if you send the MQTT commands externally to HA?

IOW, if you send the MQTT commands directly to the device thru an external program (MQTTFx, etc) do they work there?

The commands are being sent and received by the ifan via MQTT (tried several devices, they all work). The issue is the ifan doesn’t to recognize the “stat/sonoff_ifan02_1/RESULT” or “tele/sonoff_ifan02_1/LWT” commands. I get “unknown” in the Tasmota console. Because of this despite the MQTT command turning the fan or fan light on, the actual entity in HA does not think its on and change the state, even though it did change.

More detailed info in post #41 above.

Hey all, I’m having an issue with this that I’m hoping someone here can help me with.

Setting the fan speed works well, however, if turning the light on or off then the fan speed preset goes to off. The fan itself is still running at the correct preset speed but HA thinks the fan is now off. This happens when switching the light on or off.

I’m hoping I just missed something obvious but it looks like others are having the same issue with the preset going back to off but I’m not sure anyone found out why. Removing the ‘off’ preset helped as suggested above but that leads to other unwanted behavior with automations.

Hi Finity & Gang,

I had (again with help from Finity) everything working fine prior to deprecated day …

I’m trying to enter the new world using the new YAML and Preset modes.

Issue is that when I use the suggested YAML in the first post here for Preset mode … I get an error in my configuration.yaml saying
"Misssing Property “Speeds”

I am using my own names for the topics, but I still get the error what ever topic name I use.

Any idea’s?

Kind Regards

Jason

By far, the easiest way to fix this currently is to use the HA Tasmota Integration, All this yaml is gone, and it just works…
Tasmota needs to be 9.2+(9.5 is current) and HA should be one of the current versions as well.

Totally agree … went down this path.

Now the issue is calling the fan speeds from the UI … or the cards that finity has generated.

It seems that all the speeds are the same … does anyone else have that ?

my finity icons work great.
You can look at my implementation on my config, I have the lovelace showing there.
GitHub - SirGoodenough/Home-Assistant-Config: My HA Configuration... This is what I run for production in my house..
I use the percentage in 3 places and some of the others.

@Sir_Goodenough - I use Tasmota and the new Tasmota integration for HA.
Also, I set up the fan in HA using the instructions here.

I am reading this entire forum topic page and I am also looking at your Github repo. But I am not able to understand what you guys are trying to achieve, as compared to the link I have posted above. Could you please explain?

Before the Tasmota Integration, there was a lot of yaml to make the fan work at all. I was suggesting they use the Tas-integ like you are and eliminate that YAML hassle converting 0-1-2-3 into percentages for happy HA…

Then, in your lovelace you have a bunch of manual yaml to give you buttons.
I use a HACS enabled integration to do that from finity.

{
                                    "entity": "fan.office_fan",
                                    "IsOffColor": "#F88416",
                                    "IsOnLowColor": "#E78E85",
                                    "IsOnMedColor": "#E54234",
                                    "IsOnHiColor": "red",
                                    "customTheme": true,
                                    "customSetpoints": true,
                                    "hiPercentage": 100,
                                    "name": "Office Fan",
                                    "type": "custom:fan-percent-button-row"
                                },

Is all that’s in my lovelace.
Screenshot_2021-08-09_20-50-39

@Sir_Goodenough - Thanks for that. Your comment was really helpful in confirming to me that I am on the correct path.

@finity - thanks for your HACS plugins. I am using the “fan-percent-button-row” like mentioned above. The only point which tripped me up was: after installing the plugin, when I tried to use it in Lovelace, it said that the type was not found. This was reported here. Like you suggested there, it was solved by force-reloading the browser using Ctrl-Shift-R or Cmd-Shift-R.

I am so happy that the plugin shows the currently selected speed of the fan.

Now, is there a way to enable the speed selection via Alexa?

EDIT: I just realised that, having exposed the fan to Alexa via emulated_hue, I am able to control the speed of the fan in Alexa just like controlling the brightness of lights. That is, by saying things like “Alexa, Set the Living Fan to 66%” or “Alexa, Set the Living Fan to High” (Saying “Medium” does not work, though). This is good enough for now, I guess.

2 Likes

Thanks James C … I’ll scan thru … really appreciate your reply !

1 Like

Relating to the wiring, I have it working, but I need to turn the fan on before I am able to turn the light on? This can’t be right, right?

Fan and light should be acting independently.

Hey @Wilky13, did you ever figure out what the issue was? I’ve been wracking my brain the last few days trying to figure out this issue that you described in post 41 above. I’m having the exact same problem.

So my issue came down to copy/pasting only certain things from the code at the top of the page. Basically, I left the payload_on/off from my previous setup and pasted in the state_value_template from the code above. That template was changing the payload values to something other than the payload_on/off were expecting causing my issues.

Maybe my boneheaded mistake will help or prevent someone else from doing it too!

Hi, need some help with getting the fan-percent-button-row card working fully. I’m running ifan03 with tasmota 9.5.0, trying to implement as @Sir_Goodenough suggested (tasmota integration and the percent-button-row card). It all works, however status doesn’t update on lovelace until I do a broswer refresh. This means that if it is off, and I set it to high, the fan turns on to high, but the ‘off’ button stays highlighted, and can no longer be pressed. any assistance greatly appreciated!

Tim

No, I never got it to work properly with the ifan02.

However, I replaced it with an ifan04 (I live in the U.S.) and followed @DigiBlur’s blog

Here

And everything is working as it should.

1 Like

I don’t see this problem.
It may take a couple of seconds, but that’s it.
Perhaps you are using the sometimes somewhat defective HA MQTT Broker add-on that can take a minute or 2 to pass messages thru? I have went to another machine to run the broker on because of this very slow (broken) behavior.

1 Like