Ifan03 with tasmota to ha

here is my config for an iFan03 using Tasmota:

  platform: mqtt  
    name: "Sunroom Fan"
    command_topic: "cmnd/iFan03-1/FanSpeed"
    speed_command_topic: "cmnd/iFan03-1/FanSpeed"    
    state_topic: "stat/iFan03-1/RESULT"
    speed_state_topic: "stat/iFan03-1/RESULT"
    state_value_template: >
      {% if value_json.FanSpeed is defined %}
        {% if value_json.FanSpeed == 0 -%}0{%- elif value_json.FanSpeed > 0 -%}4{%- endif %}
      {% else %}
        {% if states.fan.sunroom_fan.state == 'off' -%}0{%- elif states.fan.sunroom_fan.state == 'on' -%}4{%- endif %}
      {% endif %}
    speed_value_template: "{{ value_json.FanSpeed }}"
    availability_topic: tele/iFan03-1/LWT
    payload_off: "0"
    payload_on: "4"
    payload_low_speed: "1"
    payload_medium_speed: "2"
    payload_high_speed: "3"
    payload_available: Online
    payload_not_available: Offline
    speeds:
      - "off"
      - low
      - medium
      - high

use that and change to your topics/entity_ids as needed but don’t change anything having to do with the templates.

Do you remember which repo you got the above configuration from?

Only difference between ours (besides topics/entity_ids) was that I had quotations around all four speed listed at the end. I removed quotations from low, medium, high, leaving them around off. Restarted HA and no difference. Off on the fan control entity row card still does not work, but clicking the entity and using the “Speed” dropdown turns off fan.

I think I started with this but ended up reading in the community forums here mostly.

Wish I could get the off button to work.

I also need to swap out the capacitors. Haven’t hooked it up to a fan yet but I have a feeling since I am in US I will have speed issues as has been reported frequently with iFan_0x users.

that wasn’t the only difference.

here is your state value template:

state_value_template: >
  {% if value_json.FanSpeed is defined %}
    {% if value_json.FanSpeed == 0 -%}0{%- elif value_json.FanSpeed > 0 -%}2{%- endif %}
  {% else %}
    {% if states.fan.bedroom_fan.state == ‘off’ -%}0{%- elif states.fan.bedroom_fan.state == ‘on’ -%}2{%- endif %}
  {% endif %}

and here is my state value template:

state_value_template: >
  {% if value_json.FanSpeed is defined %}
    {% if value_json.FanSpeed == 0 -%}0{%- elif value_json.FanSpeed > 0 -%}4{%- endif %}
  {% else %}
    {% if states.fan.sunroom_fan.state == 'off' -%}0{%- elif states.fan.sunroom_fan.state == 'on' -%}4{%- endif %}
  {% endif %}

I think I remember needing to change the template to get the tasmota an to work. And I think that was what was needed to be changed.

try it and see if it works.

But TBH, what I would do is just copy/paste my whole config into yours and change the topics/entities to your own because I know for a fact my code works with the fan control row since I wrote it and I am using it right now with that code in a tasmotized iFan03. :wink:

If it doesn’t work then I guess it’s possible that something else has changed in the later tasmota versions. But we can’t know that until we are sure you have tried my exact working config to make sure it’s not an error on your end.

EDIT to add:

it’s also difficult to know if your code is completely correct because you didn’t format it correctly to display it properly. it would be helpful if you could edit your post to fix that. just put three back ticks (```) on a line above and a line below the code.

Never got back to you but I got this fixed last night by only changing the code above!

Thank you!!! You the man :slight_smile:

I also will start formatting shared code correctly from now on, thanks!

1 Like

Has anyone managed to load an ESP bin for the ifan03? I can’t seem to find anything related to ESP or the GPIOs of the 03 so I can even create my own yaml.

As far as I know there is no pre-canned ESPHome sketch you can load for the iFan03 yet.

And I asked a long time ago in the iFan03 thread in the Tasmota forum for the GPIO pinout (especially as it relates to the remote control) and I never got any responses.

Digging thru the Tasmota code I found the GPIO to control the relays for the different functions but it still leaves trying to figure out the remote functions.

Here is what I have so far:

sonoff_template.h - 

{ "Sonoff iFan02",   // Sonoff iFan02 (ESP8285)
     GPIO_KEY1,        // GPIO00 WIFI_KEY0 Virtual button 1 as feedback from RC
     GPIO_USER,        // GPIO01 ESP_TXD Serial RXD and Optional sensor
     0,                // GPIO02 ESP_LOG
     GPIO_USER,        // GPIO03 ESP_RXD Serial TXD and Optional sensor
     GPIO_REL3,        // GPIO04 WIFI_O2 Relay 3 (0 = Off, 1 = On) controlling the fan
     GPIO_REL2,        // GPIO05 WIFI_O1 Relay 2 (0 = Off, 1 = On) controlling the fan
     0, 0, 0,          // Flash connection
     GPIO_KEY2,        // GPIO09 WIFI_KEY1 Virtual button 2 as feedback from RC
     GPIO_KEY3,        // GPIO10 WIFI_KEY2 Virtual button 3 as feedback from RC
     0,                // Flash connection
     GPIO_REL1,        // GPIO12 WIFI_O0 Relay 1 (0 = Off, 1 = On) controlling the light
     GPIO_LED1_INV,    // GPIO13 WIFI_CHK Blue Led on PCA (0 = On, 1 = Off)
     GPIO_KEY4,        // GPIO14 WIFI_KEY3 Virtual button 4 as feedback from RC
     GPIO_REL4,        // GPIO15 WIFI_O3 Relay 4 (0 = Off, 1 = On) controlling the fan
     0, 0
  },

starts at line 2035  
{ "Sonoff iFan03",   // Sonoff iFan03 (ESP8285)
     GPIO_KEY1,        // GPIO00 WIFI_KEY0 Button 1
     GPIO_TXD,         // GPIO01 ESP_TXD Serial RXD connection to P0.5 of RF microcontroller
     0,                // GPIO02 ESP_LOG
     GPIO_RXD,         // GPIO03 ESP_RXD Serial TXD connection to P0.4 of RF microcontroller
     0,                // GPIO04 DEBUG_RX
     0,                // GPIO05 DEBUG_TX
                       // GPIO06 (SD_CLK   Flash)
                       // GPIO07 (SD_DATA0 Flash QIO/DIO/DOUT)
                       // GPIO08 (SD_DATA1 Flash QIO/DIO/DOUT)
     GPIO_REL1_INV,    // GPIO09 WIFI_O0 Relay 1 (0 = Off, 1 = On) controlling the light
     GPIO_BUZZER_INV,  // GPIO10 WIFI_O4 Buzzer (0 = Off, 1 = On)
                       // GPIO11 (SD_CMD   Flash)
     GPIO_REL3,        // GPIO12 WIFI_O2 Relay 3 (0 = Off, 1 = On) controlling the fan
     GPIO_LED1_INV,    // GPIO13 WIFI_CHK Blue Led on PCA (0 = On, 1 = Off) - Link and Power status
     GPIO_REL2,        // GPIO14 WIFI_O1 Relay 2 (0 = Off, 1 = On) controlling the fan
     GPIO_REL4,        // GPIO15 WIFI_O3 Relay 4 (0 = Off, 1 = On) controlling the fan
     0, 0
  }
  
   /* Fanspeed is controlled by relay 2, 3 and 4 as in Sonoff 4CH.
      000x = 0
      001x = 1
      011x = 2
      101x = 3 (ifan02) or 100x = 3 (ifan03)
   */

Hey guys. I have been researching and reading about this for the past 2 days and have made some progress but still having issues with the OFF “speed” or state.

I disabled MQTT HA auto config, and inserted the manual YAML into my config. I now have a working light. The fan speeds work except when I select off it doesn’t turn off. Also when I click the fan on/off slider it slides on for 2 seconds, then slides back off, but no change happens to actual ifan device. Here’s my config:

fan:
  - platform: mqtt  
    name: "Family Room Fan"
    command_topic: "cmnd/familyroomfan/FanSpeed"
    speed_command_topic: "cmnd/familyroomfan/FanSpeed"    
    state_topic: "stat/familyroomfan/RESULT"
    speed_state_topic: "stat/familyroomfan/RESULT"
    state_value_template: >
      {% if value_json.FanSpeed is defined %}
        {% if value_json.FanSpeed == 0 -%}0{%- elif value_json.FanSpeed > 0 -%}4{%- endif %}
      {% else %}
        {% if states.fan.family_room_fan.state == 'off' -%}0{%- elif states.fan.family_room_fan.state == 'on' -%}4{%- endif %}
      {% endif %}
    speed_value_template: "{{ value_json.FanSpeed }}"
    availability_topic: tele/familyroomfan/LWT
    payload_off: "0"
    payload_on: "4"
    payload_low_speed: "1"
    payload_medium_speed: "2"
    payload_high_speed: "3"
    payload_available: Online
    payload_not_available: Offline
    speeds:
      - 'off'
      - low
      - medium
      - high
  - platform: mqtt   
    name: "Fan Light"
    command_topic: "cmnd/familyroomfan/power1"
    state_topic: "stat/familyroomfan/POWER1"
    qos: 1
    payload_on: "ON"
    payload_off: "OFF"
    retain: true

I’m not sure if it’s copy/paste error but the code you posted has both the fan and the light under the “fan:” section.

Is that the way it is in your actual code?

Afternoon All,
I recently setup my ifan03, but oddly when i switch it off after a few minutes it comes back on at the medium speed…

my fan.yaml looks like this:

- platform: mqtt  
  name: "LivingroomFan"
  command_topic: "cmnd/ifan1/FanSpeed"
  speed_command_topic: "cmnd/ifan1/FanSpeed"    
  state_topic: "stat/ifan1/RESULT"
  speed_state_topic: "stat/ifan1/RESULT"
  state_value_template: >
    {% if value_json.FanSpeed is defined %}
      {% if value_json.FanSpeed == 0 -%}0{%- elif value_json.FanSpeed > 0 -%}4{%- endif %}
    {% else %}
      {% if states.fan.ifan1.state == 'off' -%}0{%- elif states.fan.ifan1.state == 'on' -%}4{%- endif %}
    {% endif %}
  speed_value_template: "{{ value_json.FanSpeed }}"
  availability_topic: tele/ifan1/LWT
  payload_off: "0"
  payload_on: "4"
  payload_low_speed: "1"
  payload_medium_speed: "2"
  payload_high_speed: "3"
  payload_available: Online
  payload_not_available: Offline
  speeds:
    - off
    - low
    - medium
    - high

inside home assistant the fan looks like this:
image

the console of the ifan shows:

18:20:49 MQT: tele/ifan1/LWT = Online (retained)
18:20:49 MQT: cmnd/ifan1/POWER = 
18:23:29 MQT: stat/ifan1/RESULT = {"FanSpeed":2}
18:23:35 MQT: stat/ifan1/RESULT = {"FanSpeed":0}
18:23:50 MQT: stat/ifan1/RESULT = {"FanSpeed":2}
18:25:04 MQT: tele/ifan1/STATE = {"Time":"2020-05-21T18:25:04","Uptime":"0T21:37:15","UptimeSec":77835,"Heap":27,"SleepMode":"Dynamic","Sleep":100,"LoadAvg":9,"MqttCount":211,"POWER1":"OFF","FanSpeed":2,"Wifi":{"AP":1,"SSId":"Wan17","BSSId":"FC:EC:DA:A7:F6:45","Channel":11,"RSSI":96,"Signal":-52,"LinkCount":234,"Downtime":"0T00:05:48"}}
1 Like

I’ve subscribed to my mqtt via node red and i can see this:


however if i look at the console on the ifan i can see that it has picked up a speed of 2 from an mqtt message, this doesn’t seem to be appearing in my mqtt though…
image

EDIT: SORTED! I got to the bottom of the issue, one of my Motion Sensors was turning on the fan with the RF code! Just changed one of the jumpers on the sensor and it’s sorted!

Wow that’s pretty obscure.

Nice troubleshooting there!

Hello everyone

I think I have the same problem that other people here, but I don’t know if I didn’t find the answer or if so, it didn’t worked for me.
when I switch on the fan with the card, it’s only show in blue for a few seconds, it remains working but I souldn’t see that status in the card.
Here is my code

fan:
  - platform: mqtt
    name: "tasmota_ifan03"
    command_topic: "cmnd/tasmota_ifan03/FanSpeed"
    speed_command_topic: "cmnd/tasmota_ifan03/FanSpeed"    
    state_topic: "stat/tasmota_ifan03/RESULT"
    speed_state_topic: "stat/tasmota_ifan03/RESULT"
    state_value_template: >
        {% if value_json.FanSpeed is defined %}
        {% if value_json.FanSpeed == 0 -%}0{%- elif value_json.FanSpeed > 0 -%}4{%- endif %}
        {% else %}
        {% if states.fan.sunroom_fan.state == 'off' -%}0{%- elif states.fan.sunroom_fan.state == 'on' -%}4{%- endif %}
        {% endif %}
    speed_value_template: "{{ value_json.FanSpeed }}"
    availability_topic: tele/tasmota_ifan03/LWT
    payload_off: "0"
    payload_on: "4"
    payload_low_speed: "1"
    payload_medium_speed: "2"
    payload_high_speed: "3"
    payload_available: Online
    payload_not_available: Offline
    speeds:
     - "off"
     - low
     - medium
     - high
 

And this is my card

image

thnks in advance

the first obvious problem is that you jut copied my code for my fan and didn’t change the 'else" portion to your entity. You need to change the “sunroom_fan” to “tasmota_ifan03”

state_value_template: >
  {% if value_json.FanSpeed is defined %}
  {% if value_json.FanSpeed == 0 -%}0{%- elif value_json.FanSpeed > 0 -%}4{%- endif %}
  {% else %}
  {% if states.fan.tasmota_ifan03.state == 'off' -%}0{%- elif states.fan.tasmota_ifan03.state == 'on' -%}4{%- endif %}
  {% endif %}

but if that doesn’t fix it then you will need to figure out if your mqtt topics and payloads are correct.

Can I ask how you are presenting your iFan03 to Alexa? I have it running via MQTT and your custom row for the UI now but I really want to have the voice commands working.

Thanks,
Jay

I use nabu casa for alexa voice commands.

ah I see you are using the home assistant cloud, thanks for the reply.

Jay

Does Alexa recognize ‘medium’ for you?

I don’t remember specifically ever doing it but I’m pretty sure that I’ve used all of the speeds via alexa and I don’t remember ever noticing any problems.

Medium is flaky at best.

You can use “Alexa “Set Fan Name” to Speed 1” through Speed 3.

Works much better than low, medium or high.

With the last few updates from HA (im running core-2021.3.2) the changes to the fan break the HAC fan row addon. Anyone able to fix or find a work around? I am not knowledgeable enough to code it.

I tried to put the iFan03 into auto discovery (tasmota setoption19) but it doesnt work well. HA would see the fan and give me three four buttons (1 for light and 3 for fan relays). The relay control button just off after a second of being turn on and there is no way to turn the fan off.

Hope someone can figure this out.

EDIT: fix can be found here 2021.03 and tasmotized Sonoff IFan03 - lots of errors in log and fan unavailable - Configuration - Home Assistant Community (home-assistant.io)