iFan04-L Issues

So I recently got a pair of iFan04’s to replace my dumb Hunter fan controllers and flashed them to ESPHome which was simple enough. But since I did not test them before flashing I was wondering if anyone else noticed that the medium speed basically does not exist. High seems fine (afaik it just bypasses any circuit and gives the full power to the fan), and low seems a bit low for my taste, but medium is just low as far as I can tell. I am in the US, and I thought the 04 version was meant for 120v units, so I am kind of at a loss.

Has anyone else experienced this and if so is this just normal?

P.S. I also noticed an audible electronic hum across all settings, but is louder the higher the setting. I do not remember hearing that with stock Hunter controller.

2 Likes

Off the top of my head, that sound like it could be a ground loop issue, which could also cause you to see odd speed issues you described.

No personal experience with the iFan04’s though so i can’t say if this is normal for them, if you have a wiring issue, or a defective unit.

Hopefully someone else with experience with them comes along and can point you in the right direction.

2 Likes

I have 2 of them that both have the same issues. So I guess I could have wired them wrong, or got two bum units, who knows?

What do you think might be wrong with the wiring?

1 Like

Mine on esphome has been working great, other than the slight hum you mentioned, which I’ve noticed with most speed controllers I’ve tried. I remember when I first flashed it, there was discussion about which relays should be active for each speed. Some said that relay 1 was low, relay 2 medium, and relay 3 for high, where others suggested using relays 1 & 2 combined for medium.

I did some testing on my own with a tachometer, and I got similar results to what you’re getting. There was minimal difference between between low and medium with only relay 2 used for medium. I reconfigured it so medium used relays 1 & 2 at the same time, and it then worked as I expected it to. You might be having a similar issue, if you can post the yaml config I may be able to help get it sorted out.

Fan speed control is done via capacitance, they get confusing quickly with serial vs parallel and what’s already used in your fan for high

2 Likes

It might be that the addition of a capacitor will make the whole thing work better, although as you said the L spec is supposed to be setup for low voltage use. Who knows what the fans are designed for. As I understand it, fan speed control does need some pretty good balancing of inductance and capacitance to work correctly.

1 Like
substitutions:
  name:  downstairs-bedroom-fan
  device_description: Sonoff iFan04-L
  friendly_name: Downstairs Bedroom Fan

globals:
  - id: target_fan_speed
    type: int
  - id: start_time_offset
    type: int

esphome:
  name: ${name}
  comment: ${device_description}
  platform: ESP8266
  board: esp01_1m
  on_boot:
    priority: 225
    # turn off the light as early as possible
    then:
      - light.turn_off: fan_light
  on_loop:
    lambda: |-
      if (id(start_time_offset) && (millis() > id(start_time_offset))) {
        ESP_LOGD("IFAN04", "Setting target speed: %d", id(target_fan_speed));
        auto call = id(the_fan).turn_on();
        call.set_speed(id(target_fan_speed));
        call.perform();
        id(start_time_offset) = 0;
      }

# Disable logging on serial as it is used by the remote
logger:
  baud_rate: 0

# Enable Home Assistant API
api:

ota:
  password: !secret esp_ota_password

wifi:
  networks:
  - ssid: !secret lf_wifi_ssid
    password: !secret lf_wifi_password
  - ssid: !secret bh_wifi_ssid
    password: !secret bh_wifi_password

web_server:
  port: 80
  auth:
    username: !secret web_server_username
    password: !secret web_server_password
  
external_components:
  - source: github://ssieb/custom_components
    components: [ ifan04 ]

time:
  - platform: homeassistant
    id: time_homeassistant
    on_time_sync:
      - component.update: sensor_uptime_timestamp

uart:
  tx_pin: GPIO01
  rx_pin: GPIO03
  baud_rate: 9600
#  debug:
#    sequence:
#      - lambda: UARTDebug::log_hex(direction, bytes, ',');

ifan04:
  on_fan:
    - lambda: |-
        if (speed) {
          auto call = id(the_fan).turn_on();
          call.set_speed(speed);
          call.perform();
          if (id(buzzer_dummy).state) {
            switch(id(target_fan_speed)) {
              case 3:
                id(buzzer_pin).turn_on();
                delay(50);
                id(buzzer_pin).turn_off();
                delay(50);
              case 2:
                id(buzzer_pin).turn_on();
                delay(50);
                id(buzzer_pin).turn_off();
                delay(50);
              case 1:
                id(buzzer_pin).turn_on();
                delay(50);
                id(buzzer_pin).turn_off();
            }
          }
        } else {
          id(target_fan_speed) = 0;
          id(start_time_offset) = 0;
          auto call = id(the_fan).turn_off();
          call.perform();
        }
  on_light:
    - light.toggle: fan_light
  on_buzzer:
    - switch.toggle: buzzer_dummy

sensor:
  - platform: uptime
    id: sensor_uptime

  - platform: template
    id: sensor_uptime_timestamp
    name: "${friendly_name} Uptime"
    device_class: "timestamp"
    accuracy_decimals: 0
    update_interval: never
    lambda: |-
      static float timestamp = (
        id(time_homeassistant).utcnow().timestamp - id(sensor_uptime).state
      );
      return timestamp;

  - platform: wifi_signal
    name: ${friendly_name} Signal
    update_interval: 60s

binary_sensor:
  - platform: gpio
    id: button
    pin: GPIO0
    on_press:
      then:
        - light.toggle: fan_light

interval:
  - interval: 500ms
    then:
      - if:
          condition:
            not:
              wifi.connected:
          then:
            - light.turn_on:
                id: led1
                brightness: 100%
                transition_length: 0s
            - delay: 250ms
            - light.turn_off:
                id: led1
                transition_length: 250ms

output:
  - platform: template
    id: fanoutput
    type: float
    write_action:
      - lambda: |-
          if (state) {
            int speed = int(state / 0.33);
            if (!id(target_fan_speed) && (speed < 3)) {
              ESP_LOGD("IFAN04", "Fan currently off, boosting speed");
              id(target_fan_speed) = speed;
              state = 1.0;
              id(start_time_offset) = millis() + 5000; // 5 second delay
            } else {
              id(start_time_offset) = 0;
              id(target_fan_speed) = speed;
            }
          }
          if (state < 0.3) {
            // OFF
            id(target_fan_speed) = 0;
            id(start_time_offset) = 0;
            id(fan_relay1).turn_off();
            id(fan_relay2).turn_off();
            id(fan_relay3).turn_off();
          } else if (state < 0.6) {
            // low speed
            id(fan_relay1).turn_on();
            id(fan_relay2).turn_off();
            id(fan_relay3).turn_off();
          } else if (state < 0.9) {
            // medium speed
            id(fan_relay1).turn_off();
            id(fan_relay2).turn_on();
            id(fan_relay3).turn_off();
          } else {
            // high speed
            id(fan_relay1).turn_off();
            id(fan_relay2).turn_off();
            id(fan_relay3).turn_on();
          }

  - platform: gpio
    id: light_relay
    pin: GPIO9
    inverted: true

  - platform: gpio
    id: buzzer_pin
    pin: GPIO10
    inverted: true

  - platform: esp8266_pwm
    id: led_pin
    pin: GPIO13
    inverted: true

light:
  - platform: binary
    id: fan_light
    name: "${friendly_name} Light"
    output: light_relay

  - platform: monochromatic
    id: led1
    output: led_pin
    default_transition_length: 0s
    restore_mode: always off

switch:
  - platform: restart
    name: "${friendly_name} Restart"
    
  - platform: template
    id: buzzer_dummy
    name: "Buzzer"
    optimistic: True

  - platform: gpio
    id: fan_relay1
    pin: GPIO14

  - platform: gpio
    id: fan_relay2
    pin: GPIO12

  - platform: gpio
    id: fan_relay3
    pin: GPIO15

fan:
  - platform: speed
    id: the_fan
    name: "${friendly_name} Fan"
    output: fanoutput
    speed_count: 3

I just pulled this from a Home Assistant thread, so feel free to make any changes as necessary.

Yep, it’s using only relay 2 for medium, which was my issue as well.
Change this section to use both relays 1 & 2 for medium and it should give you a proper medium speed.

// medium speed
id(fan_relay1).turn_on();
id(fan_relay2).turn_on();
id(fan_relay3).turn_off();

As far as low being too slow, that’s going to be dependent on the capacitors in the ifan, and whatever the main run capacitor in your fan is. If your current medium speed is closer to what you want low to be, you could change the low target to use relay 2 instead of relay 1, otherwise you’ll have to experiment with different value capacitors

2 Likes

Thank you so much, it is working perfectly now. Any other suggestions on the configuration?