Sonoff Ifan04 - ESPHome working code

Hey I am using an ifan04-L.
The ESPHome setup works with the above Yaml from @cpyarger but I have a few issues:

  1. The buzzer won’t mute with the remote.

In addition when I set buzzer_enable: false under fan, the ifan04 just does one long continuous beep when booted normally and won’t go silent at all.

Has anyone else run into this issue?
If so, how did you mute the buzzer?

@ditheo did you manage to mute the buzzer?

  1. The ESPHome addon in HA does show the ifan online and I can add it as a device but I can’t update config or view logs via HA.

Is any one also experiencing this?

Thanks!

I have the same issue when i add set buzzer enable false

I open the sonoff fan and add some tape to the buzzer, it is much lower now

I used iFan04-h in my floor fan. Tried tasmota first and its working. Light relay is used to enable oscillation, but I cant use mushroom card with it. Probably it will be easier to achive with esphome, but when I looked at the code… Its still magic to me. Any tips what I need to change in code to get light cable as fan.oscillate ?

@cpyarger Thanks for your work on this! I just got everything set up using your code. Unfortunately, I am running into the same issue as a previous poster where buzzer_enable: false results in a continuous beep noise. Is this something you could maybe look into? I’d really appreciate it! The beeping is super obnoxious even with a few layers of tape on the buzzer.

I have no clue why you are having a continuous beep. maybe post your yaml file. this is mine, and it works perfectly for me.

substitutions:
  name: dining-room
  friendly_name: Dining Room
external_components:
  - source: github://cpyarger/custom_components@master
    refresh: 0s
esphome:
  name: ${name}
  comment: Sonoff iFan04-L
  # This will allow for (future) project identification,
  # configuration and updates.
  project:
    name: cpyarger.sonoff-ifan04-l
    version: "1.0"
esp8266:
  board: esp01_1m
# Disable logging on serial as it is used by the remote
logger:
  baud_rate: 0
# Enable Home Assistant API
api:
  services:
    - service: fan_cycle
      then:
        - fan.cycle_speed: the_fan
ota:
uart:
  tx_pin: GPIO01
  rx_pin: GPIO03
  baud_rate: 9600
dashboard_import:
  package_import_url: github://cpyarger/esphome-templates/sonoff-ifan04-l.yaml@main


captive_portal:

binary_sensor:
  - platform: gpio
    id: button_light
    pin: GPIO0
    on_press:
      then:
        - light.toggle: fan_light
output:
  - platform: esp8266_pwm
    id: led_pin
    pin: GPIO13
    inverted: true
light:
  - platform: ifan
    id: fan_light
    name: "${friendly_name} Light"
  - platform: monochromatic
    id: led1
    output: led_pin
    default_transition_length: 0s
    restore_mode: always off
button:
  - platform: template
    name: ${friendly_name} Cycle Fan
    on_press:
      then:
        - fan.cycle_speed: the_fan
fan:
  - platform: ifan
    id: the_fan
    name: "${friendly_name} Fan"
    remote_enable: false  
    buzzer_enable: false
ifan04:
  on_fan:
    - lambda: |-
          auto call = speed ? id (the_fan).turn_on() :  id (the_fan).turn_off();
          call.set_speed(speed);
          call.perform();
  on_light:
    - light.toggle: fan_light

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
web_server:
1 Like

I tried it again and it worked. No idea why it was acting so strangely for me and the two other people that had the same issue. I am using this Blueprint to automatically change the fan speed based on a temperature sensor, so I’ll definitely enjoy the silence :slight_smile: Thanks again.

1 Like

Sorry to bug you again, but after the fan was power cycled, the fan continuously beeps again. I tried flashing with no changes and it still beeps continuously. There’s definitely still an issue.

Hello,
This patch seems to have solved @ellaizee’s issue.

HTH.

1 Like

@cpyarger I am looking at getting a bunch of these and want to add support for maintaining the existing light switch (with a zooz momentary switch) to control the light/fan with multi touch. I planned on using the buzzer pin with some slight hardware modifications (https://www.reddit.com/r/sonoff/comments/rqvnpe/ifan04_with_free_gpio_solution/) and slight change to your custom_component but noticed you have a “button_light” button on GPIO0 and was wondering where that was on the device as it might make for a better source for my free GPIO so I could maintain the buzzer functionality.

My god! I have this issue too!! The buzzing is sooooo loud!! I have enabled buzzer_enable for now

Hi Hunter,
Apologies if this is silly question, how do I get the fix compiled or is it already merged with the master branch?
I have the dreaded beep on boot as well.

It’s not merged yet. If you need it right away, replace all instances of github://cpyarger with github://hfuller in your ESPHome yaml and rebuild. Please remember to undo this later, as I don’t intend to maintain my fork once the patch is merged.

Hi. I’m trying to flash a new iFan4-h with the ESPHome code in this thread and I can’t make it. I would use some help.
I soldered pins to the header and connected an USB to TTL. RX/TX cables crossed, power not wired, only ground.
I connect the ifan4 to mains while pushing it’s button. I don’t know how much time it’s required. I push it @5sec.
Then I go into tasmotizer, it recognizes the TTL, fill in the settings and bin, and push the Tasmotize button.
But it never connects. I’ve tried zillions of times, changing cables, swapping RX/TX, another USB TTL… nothing is working.
The device is brand new, never paired to ewelink. But it seems to work because if I power it on without pushing the button it flashes and beeps and I could pair the remote.
I need some help with this.

Edit: Every time I’ve tried it, the TX led in the USB TTL converter flashes, but it seems like the ifan is not responding.
Could be that they changed the firmware and now it can’t be flashed? I can’t find anything on the net.

Read my post from December, Sonoff Ifan04 - ESPHome working code - #18 by NigelHA, and see if that helps.

Hi Higel, Thank you. I also tried swapping TX and RX several times and I always used Tasmotizer, but unfortunately didn’t work. It was like the device didn’t accept coms on the exposed pins. I also tried with the pads underneath.
Starting with the button pressed obviously was doing something, as It didn’t beep or flash the led.

Do you remember if putting your into flash mode did anything like flashing the led even if it was once?

I can’t say that I remember, but I do remember keeping the button pressed through-out the entire flashing process.

Have a gander at this page that was recommended by people in the Tasmoto chat Getting Started - Tasmota

I was having many issues flashing mine. I would suggest testing the device first with esptool: Releases · espressif/esptool · GitHub

Check flash (Useful to get the flash size for the second command 1M etc):

Nix

esptool --port /dev/ttyUSB1 flash_id

or Windows

esptool --port COM4 flash_id

Should spit out something like this:

esptool.py v2.8
Serial port /dev/ttyUSB1
Connecting....
Detecting chip type... ESP8266
Chip is ESP8285
Features: WiFi, Embedded Flash
Crystal is 26MHz
MAC: xx:xx:xx:xx:xx:xx
Enabling default SPI flash mode...
Manufacturer: 5e
Device: 3214
Detected flash size: 1MB
Hard resetting via RTS pin...

A fail will look like this:

esptool.py v2.8
Serial port /dev/ttyUSB0
Connecting........_____....._____....._____....._____....._____....._____....._____

A fatal error occurred: Failed to connect to Espressif device: Timed out waiting for packet header

Once you get a success you can then dump the firmware with:

sudo chmod +x esptool
./esptool --port /dev/ttyUSB0--baud 921600 read_flash 0x00000 0x100000 ifan04lfwbackup001-1.bin

Which should then look something like this:

esptool.py v3.3.2
Serial port /dev/ttyUSB0
Connecting...
Detecting chip type... Unsupported detection protocol, switching and trying again...
Connecting...
Detecting chip type... ESP8266
Chip is ESP8285N08
Features: WiFi, Embedded Flash
Crystal is 26MHz
MAC: xx:xx:xx:xx:xx:xx
Stub is already running. No upload is necessary.
Changing baud rate to 921600
Changed.
1048576 (100 %)
1048576 (100 %)
Read 1048576 bytes at 0x0 in 16.7 seconds (501.9 kbit/s)...
Hard resetting via RTS pin...

If that is not working with your USB to TTL just remove the --baud line so it will default back to 115200.

You should dump the firmware twice and compare just for a sanity check. (If you ever care about returning the worst beeping firmware on earth)

md5sum ifan04lfwbackup001-1.bin
cb5b29008c9459e4014ffdaa12537c94  ifan04lfwbackup001-1.bin
md5sum ifan04lfwbackup001-2.bin
cb5b29008c9459e4014ffdaa12537c94  ifan04lfwbackup001-2.bin

I was having multiple issues. First issue was I was using an FT232RL (not fake) but had no voltage regulator on the board. I think this board consumes a lot of mW with the two radio IC etc.

I ended up wiring it to VAC (Not recommended for safety reasons in the documentation above) then just using TX to TX, RX to RX (Thanks above) and Ground only. Which started dumping the firmware but then would die at 40%.

You can also test if your getting any console data with Putty or Minicom as the device will dump a version line to the serial console when you hold the button down while powered and not synced to the eWeLink app yet (“DIY mode” gets activated with an ad-hoc AP. Check out sonoff.tech/diy-developer for more information about the process. The blurb about the other device seems to work with this one when you hold the sync button down on the 433 remote as well I think).

Serial Console:

FWFAN-XXXXXXXXMCU-IFAN04-XXXXXXXXX v1.1.0

I then bought the recommended USB adapter with the CH340G and an external LDO regulator from that Tasmoto article above from AliExpress for a few dollars (Don’t just grab any CH340G from Ali as some of the boards are garbage with no external LDO. I haven’t got it yet but I remembered I had a second device an ESP-Prog so I hooked that up and at first it had an error:

A fatal error occurred: ESP8266 ROM does not support function read_flash.

This was caused from Debian’s old apt esptool version 2.8. After grabbing the one from the github repo above 3+ it worked fine.

I remembered in the past I also had issues with the laptop dock (USB C) when it’s charging the laptop. I can’t get programmers to flash the ESP for some reason. (USB2TTL plugged into the side of the laptop not the dock) Maybe it’s noisy or something. Soon as I unplug the laptop from power it flashes fine.

So there’s some more food for thought. Try a different computer / programmer / get solid power to it / make sure everything shares the same ground plane.

I just bought my iFan04 a week ago. They are on firmware 3.5 from Sonoff (latest) and still read the flash fine. So your unit age should be ok as well (I had this same concern). People in the Tasmoto chat said there is pretty much nothing Sonoff could do with the firmware to prevent flashing an esp82xx.

Also your question about holding the button down. Your 5 seconds should be fine but maybe you are also activating the “DIY mode” if not power cycling properly. Check if there is a WiFi itead SSID near you. I hold the button down, then flick the power bar on, then count to 2 or 3, then let go, then test with esptool flash id command. (This is of course with no 3v3 connected from the TTL Adapter / ie VAC power)

Otherwise if I had a decent external LDO without VAC attached. I would go: Hold button down, plug in USB, do the count, let go, test the flash.

Note the quality control on Sonoff gear may not be the best… The transformer leads on the back of my board were not removed and touching each other (I’m glad I never plugged it in before taking it apart).

I also had to remove half a mm off both sides with the sanding dremel tool to fit it in the fan bracket mount housing.

Could you not use the SDA/SCL at the top of the board for your extra IO requirements?

Edit: SDA/SCL at the top of the board is connected to the RF module (PIN10(SCL) and PIN9(SDA) of OB38R08 chip) and not the ESP :frowning:

You could technically attach an I2C I/O expander IC there as well maybe. And just plug the standard default light switch direct into it for a super cheap control option.

I was thinking you could add dimming to the unit with something like this. (space willing) pass the iFan04 light relay wire into it then out to the fan light wire. Attach the I2C wires to the Sonoff I2C port at the top of the board.

1 Like

Thank you NonaSuomy for your very informative reply.

That’s the output I’m always getting from esptool. There’s no communication.
I’ve tried several adapters, the d-sun-v30, the yp-01 (that became trashed by the driver when plugged into a w10 laptop), a cp2102 and that one for esp01.
With their own power supply, with mains and only wiring ground, and also powering the board with a lab PSU.
Always same results. Linux and Windows. The firmware version is also 3.5. So I’m using it with their platform and the HA integration for Sonoff.

I wrote here in case there was a known issue or knowledge of the brand locking these boards.

They recommend this specific “Gold” Adapter with a CH340G and external 3v3 LDO on the board: https://www.aliexpress.com/item/32761423124.html
to do any of your device flashing with. Not the CP2102 I’ve had these cheap boards fry my esp’s just from unplugging the laptop from AC be careful. Do your USB to TTL boards have a 3v3 LDO Regulator on them? Can you show a link or picture to the one you are using? This is the part circled in red that should be on the TTL boards to supply power to this hungry fan controller board.

Did you try a completely different computer plugged into AC and not plugged into AC? (Not just dual booting from Windows to Linux)

If you order that one above and then want to try again in the future it’s super easy to do so. I wanted to test their platform out so I understood how it worked before the flashing of custom firmware. Just click the fan in the eWeLink app then click the top right settings button then delete the device from there. It will factory reset it and be back to beeping with no config. Though maybe it shouldn’t matter weather it’s paired or not as it should still just work even then.

As said above they haven’t “Locked” them and apparently it’s improbable. They would probably loose a ton of business if they could.