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

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.

I was able to get it to work in HA 2021.6.5.

my yaml

substitutions:
  device_name: ifan03_1
  friendly_name: iFan03-1
  userpass: password
  wifi_pass: wifi-password
  ssid: ssid

  
wifi:
  ssid: "${ssid}"
  password: "${wifi_pass}"

  ap:
    ssid: "${friendly_name}"
    password: "${userpass}"

captive_portal:

logger:

api:
  password: "${userpass}"

ota:
  password: "${userpass}"

esphome:
  name: ${device_name}
  platform: ESP8266
  board: esp01_1m
  includes:
    - ifan03.h
  on_boot:
    priority: 225
    # turn off the light as early as possible
    then:
      - light.turn_off: ${device_name}_light


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

  - platform: gpio
    pin: GPIO9
    inverted: True
    id: light_output

light:
  - platform: binary
    name: "${friendly_name} Light"
    output: light_output
    id: ${device_name}_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: ${device_name}_fan
        - if:
            condition:
              and:
                - switch.is_on: fan_relay1
                - switch.is_off: fan_relay2
                - switch.is_off: fan_relay3
            then:
              - fan.turn_on:
                  id: ${device_name}_fan
                  speed: 1
        - if:
            condition:
              and:
                - switch.is_on: fan_relay1
                - switch.is_on: fan_relay2
                - switch.is_off: fan_relay3
            then:
              - fan.turn_on:
                  id: ${device_name}_fan
                  speed: 2
        - if:
            condition:
              and:
                - switch.is_on: fan_relay1
                - switch.is_off: fan_relay2
                - switch.is_on: fan_relay3
            then:
              - fan.turn_on:
                  id: ${device_name}_fan
                  speed: 3
        - 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: ${device_name}_fan
    name: "${friendly_name} Fan"
    speed_count: 3

with the ifan03.h

#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);
      }
    }
};

I have a sonoff 433 bridge that deals with the remotes, I have 4 of the fans and the remotes, when paired, change the other fans. when not paired the remotes all broadcast different commands.

Does the code above work with the latest HA fan speed (percentage) requirements and the remote works as well?

Hi @finity , I no longer use this integration, sorry.

Hi @finity, the code still works with minor adjustments. The ifan03.h file remains the same but in your actual code for the devices you need to make the following changes to the "speed: " lines.

  - 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: 33
   
        - if:
            condition:
              and:
                - switch.is_off: fan_relay1
                - switch.is_on: fan_relay2
                - switch.is_off: fan_relay3
            then:
              - fan.turn_on:
                  id: ifan03_fan
                  speed: 66
        - 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: 100
        - switch.turn_off: update_fan_speed

2 Likes

The code with the percentages is working fine, but my RF remote has stopped working. I’ve used @sliwma 's codeand changed it the speeds to %, but the RF remote has completely stopped working now, have tried re-paring, but I don’t hear the beep sound from the iFAN when attempting the paring steps, any suggestions?