iFan03 on ESPHome, working ! well...sort of

Hi everyone, I had been searching this forum on how to integrate an iFan03 with ESPHome to smarten up a legacy RF remote controlled fan. Found a few resources on using Tasmota, but none on ESP Home. Since I like to keep it simple and have a bunch of devices on ESPHome already, I tried a few things, and with help from several folks in this community I got it to work (for me).

What works : iFan03 is flashed with ESPHome and integrated in HA. The 3 relays are controlled by pins 14, 12 and 15 (low/medium/high) and the light by pin 9. The 3 relays and the light switch can be activated as separate entities in HA.

What does not work : I could not configure it as a fan entity. I have tried this approach proposed by @finity here. I was able to figure out which changes to make the the ifan02h file and the config file, but in the end could not get the right behavior from the buttons consistently (for instance, switching from medium to low setting worked every other press : first press no behavior, second press worked).

How I circumvented that : Node Red flows…

In hope this might help somebody, here is

  1. config in ESP Home
esphome:
  name: ifan03
  platform: ESP8266
  board: esp8285

wifi:
  ssid: "xxxxxxx"
  password: "xxxxxxx"

# Enable logging
logger:

# Enable Home Assistant API
api:

ota:

output:
  - platform: gpio
    pin: GPIO9
    id: light_output
    inverted: true

light:
  - platform: binary
    name: "iFan03 Light"
    output: light_output
    id: ifan03_light

switch:
  - platform: gpio
    pin: GPIO14
    name: "relay_1"
    id: fan_relay1
    
  - platform: gpio
    pin: GPIO12
    name: "relay_2"
    id: fan_relay2
    
  - platform: gpio
    pin: GPIO15
    name: "relay_3"
    id: fan_relay3

    
text_sensor:
  - platform: version
    name: Master Fan ESPHome Version
    
sensor:
  - platform: wifi_signal
    name: Master Fan WiFi Signal Strength
    update_interval: 60s
  1. NodeRed Flows

  1. Lovelace (using button card)

(yes, the fans are spinning when on :slight_smile: )

Thanks to @RomRider for his help on the code for the speed attribute and @HakaToph for his help with the hardware setup

Hope this helps someone in this wonderful community !

Did you try turning off the other two relay when turning on the first e.g.

  • platform: gpio
    pin: GPIO14
    id: fan_relay1
    on_turn_on:
    • switch.turn_off: fan_relay3
    • switch.turn_off: fan_relay2

Hello. Did UI buttons status changes when you control with RF?
Also have you applied on_turn_on action: as described by @accelle

I’ve flashed this on esphome and the on_turn_on works. However, I wasn’t able to make the RF work, I think I’m missing something in the config so I opted to use tasmota for now.

Exactly, my RF is not working either but it was never my intent to have dual control since we have a tablet with HA access mounted in the bedroom. Also, the speed is automated based on room temperature and presence detection and we rarely use the manual switch.

mviamin i followed your code for esp-home. i can see it it esp home and it online but the integration does not show up when i restart hassio. Any advice?? I have converted most of my device from tasmota to esp-home but this one does not want to show up.

Hi @Geoff_Green, have you added it through the Integrations menu ?
Configuration --> Integrations --> hit the “+” at the bottom right, select ESPHome, and use the device IP as the host. You can find the device IP from your router (recommend you use IP address reservation if you have not already), or you can find the IP in ESPHome by clicking on show logs.

Hope this helps ?

That’s got it. @mviamin Was waiting for it to automatic appear like my other Esp-home stuff. I have got fan working with the remote as well using the Sonnoff bridge. just got to get the button card into Lovelace to complete it. Is the Button card one from Hacs or complete custom one?

Great ! Funny because I never got the remote to work…my assumption has always been that flashing ESPHome code was over-writing any of the remote functionality built in the factory firmware…anyway, good that you had it working.

In order to operate the fan, I used the Button Card from HACS and combined several into a horizontal stack.

Looks like this :

The reason for the lock button is because the operation of the fan is automated based on temperature (i.e. certain thresholds launch the fan at different speeds or turn it off). The lock button disables that functionality and lets users (meaning my wife :)) operate the fan manually…

Will impliment buttons when i get home. Thanks for the info. For the remote i use the Sonoff bridge with esphom. I intercepted the signal from the remote and created sensor for each button in the bridge and used node red to controll the ifan03

1 Like

There is a relatively easy solution to get the remote working without anything other than esphome:

remote_receiver:
  pin: GPIO3
  dump: raw

This will give you the raw codes of your remote, which you can use as binary_sensors like this:

  
binary_sensor:
  - platform: remote_receiver
    name: "Ventilator BĂĽro Fernbedienung Stufe 0"
    id: remote_0
    raw:
      code: [-207, 104, -103, 104, -104, 103, -104, 207, -104, 103, -104, 104, -103, 104, -104, 103, -104, 105, -102, 104, -725, 104, -311, 103, -518, 104, -933, 103, -104, 104, -725, 104, -932, 104, -207, 207, -519]
    on_release:
      then:
        - switch.turn_off: fan_relay1
        - switch.turn_off: fan_relay2
        - switch.turn_off: fan_relay3
  - platform: remote_receiver
    name: "Ventilator BĂĽro Fernbedienung Stufe 1"
    id: remote_1
    raw:
      code: [-207, 104, -104, 103, -104, 104, -103, 207, -104, 104, -103, 104, -104, 103, -104, 104, -103, 104, -104, 103, -726, 103, -312, 103, -518, 104, -933, 103, -104, 104, -725, 104, -103, 104, -726, 103, -104, 311, -518]
    on_release:
      then:
        - switch.turn_on: fan_relay1
  - platform: remote_receiver
    name: "Ventilator BĂĽro Fernbedienung Stufe 2"
    id: remote_2
    raw:
      code: [-208, 103, -104, 104, -103, 104, -103, 208, -103, 104, -104, 103, -104, 104, -103, 104, -104, 103, -104, 103, -726, 104, -310, 104, -518, 104, -933, 103, -104, 104, -725, 104, -207, 104, -622, 103, -416, 102, -415]
    on_release:
      then:
        - switch.turn_on: fan_relay2
  - platform: remote_receiver
    name: "Ventilator BĂĽro Fernbedienung Stufe 3"
    id: remote_3
    raw:
      code: [-207, 104, -104, 103, -104, 104, -103, 208, -103, 104, -104, 103, -104, 104, -103, 104, -104, 103, -104, 103, -726, 104, -311, 104, -518, 103, -934, 103, -103, 104, -726, 103, -104, 207, -622, 104, -103, 104, -207, 104, -415]
    on_release:
      then:
        - switch.turn_on: fan_relay3
  - platform: remote_receiver
    name: "Ventilator BĂĽro Fernbedienung Licht"
    id: remote_light
    raw:
      code: [-207, 104, -103, 104, -104, 103, -104, 207, -104, 103, -104, 104, -103, 104, -103, 104, -104, 103, -104, 104, -725, 104, -311, 103, -518, 104, -933, 103, -104, 103, -726, 103, -311, 104, -518, 104, -207, 104, -103, 104, -414]
    on_release:
      then:
        - light.toggle: ifan03_light

1 Like

I have got the iFan03 working correctly with the RF remote and HA. It requires only ESPHome, no other automations or nodeRed. I have gather all my information from a number of posts relating to the iFan02 and iFan03 from the forums and used them all to complete the code, thank you to everyone who shared their code.

In order to make this work you will need to create a “ifan03.h” file in your ESPHome folder within the HA config folder. Then you will need to copy the following code into this file:

#include "esphome.h"
using namespace esphome;

class IFan03Output : public Component, public FloatOutput {
  public:
    void write_state(float state) override {
      if (state < 0.3) {
        // OFF
        digitalWrite(14, LOW);
        digitalWrite(12, LOW);
        digitalWrite(15, LOW);
      } else if (state < 0.6) {
        // low speed
        digitalWrite(14, HIGH);
        digitalWrite(12, LOW);
        digitalWrite(15, LOW);
      } else if (state < 0.9) {
        // medium speed
        digitalWrite(14, HIGH);
        digitalWrite(12, HIGH);
        digitalWrite(15, LOW);
      } else {
        // high speed
        digitalWrite(14, HIGH);
        digitalWrite(12, LOW);
        digitalWrite(15, HIGH);
      }
    }
};

Now you can start building your yaml file using the code below:

esphome:
  name: bedroom_ifan03
  platform: ESP8266
  board: esp01_1m
  includes:
    - ifan03.h
  on_boot:
    priority: 225
    # turn off the light as early as possible
    then:
      - light.turn_off: ifan03_light

wifi:
  ssid: "SSID"
  password: "PASSWORD"
  manual_ip:
    static_ip: 192.168.1.106
    gateway: 192.168.1.1
    subnet: 255.255.255.0 

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Bedroom Ifan03 Fallback Hotspot"
    password: "PASSWORD"

captive_portal:

web_server:
  port: 80
# Enable logging
logger:

# Enable Home Assistant API
api:

ota:

output:
  - platform: custom
    type: float
    outputs:
      id: fanoutput
    lambda: |-
      auto ifan03_fan = new IFan03Output();
      App.register_component(ifan03_fan);
      return {ifan03_fan};

  - platform: gpio
    pin: GPIO9
    id: light_output

light:
  - platform: binary
    name: "iFan03 Light"
    output: light_output
    id: ifan03_light

switch:
  - platform: template
    id: update_fan_speed
    optimistic: True
    turn_on_action:
      then:
        - delay: 200ms
        - if:
            condition:
              and:
                - switch.is_off: fan_relay1
                - switch.is_off: fan_relay2
                - switch.is_off: fan_relay3
            then:
              - fan.turn_off: ifan03_fan
        - if:
            condition:
              and:
                - switch.is_on: fan_relay1
                - switch.is_off: fan_relay2
                - switch.is_off: fan_relay3
            then:
              - fan.turn_on:
                  id: ifan03_fan
                  speed: LOW
        - if:
            condition:
              and:
                - switch.is_on: fan_relay1
                - switch.is_on: fan_relay2
                - switch.is_off: fan_relay3
            then:
              - fan.turn_on:
                  id: ifan03_fan
                  speed: MEDIUM
        - if:
            condition:
              and:
                - switch.is_on: fan_relay1
                - switch.is_off: fan_relay2
                - switch.is_on: fan_relay3
            then:
              - fan.turn_on:
                  id: ifan03_fan
                  speed: HIGH
        - switch.turn_off: update_fan_speed

  - platform: gpio
    pin: GPIO14
    id: fan_relay1

  - platform: gpio
    pin: GPIO12
    id: fan_relay2

  - platform: gpio
    pin: GPIO15
    id: fan_relay3

fan:
  - platform: speed
    output: fanoutput
    id: ifan03_fan
    name: "Bedroom Fan"
    
#Remote Control

remote_receiver:
  pin: GPIO3
  dump: raw

binary_sensor:
  - platform: remote_receiver
    name: "Bedroom Fan Off"
    id: remote_0
    raw:
      code: [-207, 104, -103, 104, -104, 103, -104, 207, -104, 103, -104, 104, -103, 104, -104, 103, -104, 105, -102, 104, -725, 104, -311, 103, -518, 104, -933, 103, -104, 104, -725, 104, -932, 104, -207, 207, -519]
    on_release:
      then:
        - fan.turn_off: ifan03_fan
  - platform: remote_receiver
    name: "Bedroom Fan Low"
    id: remote_1
    raw:
      code: [-207, 104, -104, 103, -104, 104, -103, 207, -104, 104, -103, 104, -104, 103, -104, 104, -103, 104, -104, 103, -726, 103, -312, 103, -518, 104, -933, 103, -104, 104, -725, 104, -103, 104, -726, 103, -104, 311, -518]
    on_release:
      then:
        - fan.turn_on:
            id: ifan03_fan
            speed: LOW
  - platform: remote_receiver
    name: "Bedroom Fan Medium"
    id: remote_2
    raw:
      code: [-208, 103, -104, 104, -103, 104, -103, 208, -103, 104, -104, 103, -104, 104, -103, 104, -104, 103, -104, 103, -726, 104, -310, 104, -518, 104, -933, 103, -104, 104, -725, 104, -207, 104, -622, 103, -416, 102, -415]
    on_release:
      then:
        - fan.turn_on:
            id: ifan03_fan
            speed: MEDIUM
  - platform: remote_receiver
    name: "Bedroom Fan High"
    id: remote_3
    raw:
      code: [-207, 104, -104, 103, -104, 104, -103, 208, -103, 104, -104, 103, -104, 104, -103, 104, -104, 103, -104, 103, -726, 104, -311, 104, -518, 103, -934, 103, -103, 104, -726, 103, -104, 207, -622, 104, -103, 104, -207, 104, -415]
    on_release:
      then:
        - fan.turn_on:
            id: ifan03_fan
            speed: HIGH
  - platform: remote_receiver #top left button
    name: "Bedroom Fan Light"
    id: remote_light
    raw:
      code: [-207, 104, -103, 104, -104, 103, -104, 207, -104, 103, -104, 104, -103, 104, -103, 104, -104, 103, -104, 104, -725, 104, -311, 103, -518, 104, -933, 103, -104, 103, -726, 103, -311, 104, -518, 104, -207, 104, -103, 104, -414]
    on_release:
      then:
        - light.toggle: ifan03_light

  - platform: remote_receiver  #top right button
    name: "iFan03 Spare Button"
    id: remote_spare_button
    raw:
      code: [-207, 104, -103, 104, -104, 103, -104, 207, -104, 103, -104, 103, -104, 104, -103, 104, -103, 104, -104, 107, -721, 105, -206, 207, -518, 105, -931, 104, -104, 103, -725, 104, -104, 103, -725, 104, -104, 103, -207, 104, -414]
    on_release:
      then:
        - homeassistant.service:
            service: switch.toggle
            data:
              entity_id: switch.effect_light  

The last raw RF remote code can be utilized to toggle anything additional in HA, you will see in my code I use it to turn on the ambient lighting in the bedroom.

Assuming that you have paired your remote to the ifan03 before hand, you should be able to use the remote immediately after reboot, and HA will update the status of the fan accordingly.

RF Remote Pairing: To pair your remote with the iFan03, power off the unit, then return power to the device and press and hold any button on the remote within 5 seconds. and you should here a beep from the iFan03. You will not be required to relearn all the RF codes.

Additional Tinkering: The iFan03 is equip with a buzzer which can be used to beep every time a button is pressed on the RF Remote

3 Likes

What a coincidence, I solved it yesterday. Now waiting to be included in ESPhome documentation. :upside_down_face:

Just added buzzer support, can be switched off using upper right button and from HA dashboard.

2 Likes

Easiest option without flashing is to simply install the sonoff integration. All functions work perfectly and in sync with remote actions.

Thanks for the great work guys, ifan03 works brilliantly for me with ESPHome. With recent issues in Australia with equipment locked out from tuya-convert, I was a little concerned that it was going to be more difficult but inserted a pin header in the existing socket area and all done with a little bit of soldering. Baud rate at 115200 to serial connected programmer and done. Programmer needs to be 3.3V. I was running off 240vac and that needed some care to hold reset at power up. You will not see any blue flashing or any blue light when in program mode on my model. Remote pairing also needs the power cycle and holding any other button other than the wifi button. That took a bit of time to work out. Just press light or a fan speed and all good. Thanks again

Yeah, it works but it’s cloud-based - ESPhome is local.

1 Like

Once configured you can disable cloud mode.

Managed to setup I2C on ifan03 using TP10 which is GPIO05 for sda & GPIO01 (TX) for the scl. The 433Mhz remote still works with this setup using edited esphome yaml from sliwma above. I used a small jumper wire from TP10 pad across to the C2CK pin which I cut the track to so I could solder a 5 pins right angle header to.

Has anyone had a chance to explore the fan changes with ESPHome 1.17.0?

From what I understand speeds need to change from LOW / MEDIUM / HIGH to 33 / 66 / 100 and speed_count: 3 needs to be added to the fan component.

I’m not sure if anything needs to change with ifan03.h.

The above changes seem to work for control within HA but the remote no longer works.