Sonoff Ifan04 - ESPHome working code

Well at that point in time (3 years ago) I did not know about HA and still wanting to have some control over it it seemed OK. Now its garbage obviously but I am sure not too many people are inclined to open up their fan controller and upload firmware… it has its place in the market…

Ill have to dig around I thought I did take a few…

Fair enough.

Well, I cannot imagine sonoff having all the fans to test, Nor am I willing to blow the fan / breaker while playing around with it, so better to double check the different values must be there for a reason one might assume…

Anyway I have to 3d print a extra spacer for this device as its too big to fit the current fan (another reason to buy the lucci I guess) so no rush :slight_smile:

3D print your own enclosure for it. There is a lot of wasted space on the edges as of its weird shape. Not sure how small the space is in your fan but I had to sand down the sides of mine to fit (posted above) Sonoff Ifan04 - ESPHome working code - #83 by NonaSuomy.

It took a while before I had the nerve to install it but here goes:
I ended p printing a spacer between the fan and the cieling (way too high, but ok)

Here it is all installed with WAGO connectors as that just feels way more safe than te screw terminals

For the curious, here the old LUCCI fan controller: (which is now going into the trash JEEJ)


1 Like

Before I forget, What is currently the latest “Working YAML” for ESP home ?

Thanks for the pictures. Instead of throwing it out… If you were able to get custom firmware on it you could technically use it for a table fan or a bathroom fan etc if it still works.

1 Like

I produced what I think is a tidy .yaml-only iFan04-L package:

bedroom-fan.yaml (example)

api:
  encryption:
    key: !secret encryption_key

ota:
  password: !secret ota_password

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

esphome:
  name: bedroom-fan
  friendly_name: "Bedroom Fan"

packages:
  ifan04: github://gagebenne/esphome/packages/ifan04.yaml # !include ifan04.yaml (locally)

That’s it. No other dependencies. The remote works fine. There’s some beeps too if you want. Light works.

If you dislike downloading the package from GitHub, downloading the single .yaml file is just as easy, using !include ifan04.yaml instead.

5 Likes

I just wanted to chime in here since this thread is the first result on google and has been extremely helpful to me. I had trouble getting my ifan04 in programming mode and wanted to post a solution for anyone else that may visit this thread. The ifan04 would power up fine, but when holding gpi0, I would get nothing. My serial flasher (ch340g) would blink the transmit light but never receive. I bought a FT232 and better jumpers since I had been trying to use some thin breadboard cables and still nothing changed.

The solution was powering the ifan with one programmer and flashing with the other.

Ft232 TX/RX to Ifan04 RX/TX
CH340G VCC to Ifan04 3.3v
All 3 grounds connected together.

I saw that some in this thread were able to flash it by connecting it to mains but I wanted to post an alternative that is a little more safe. I also could not get this to work from the web flasher but flashing from the server did.

1 Like

You just need a TTL board with a proper regulator on it which is covered above.

The AC bit is normally only for programming the RF remote if it is not already synced with the fan controller.

Great work!
Will test soon, does your remote respond better now?
Mine is very intermitted clicking with the old way. (Sometimes having to click it 5+ times to get it to respond, even though the battery seems to be in good condition and the led emits on the remote ok)

esphome AttributeError: ‘NoneType’ object has no attribute ‘replace’
You seem to be missing a name: “” for the fan speed-setting entity.

fan:
  - platform: speed
    id: ifan04
    name: ${friendly_name} Fan

The remote seems to be even less responsive like it needs a cooldown before the next button press and multiple clicking as well not sure why or if you get the same response.

Seem to have instances as well where I click something and it does something random. I started by clicking speed 1 and it started on 3, I pressed speed 2 and it turned the light off. I’m not sure if the speed cycling is just an error with fan control as I was having that issue before as well.

There’s definitely a cooldown for the remote for me as well, I think that I guess is just the downside of .yaml-only configuration? Others in this thread have explored more robust remote handling, but then you get into C++ files, and I guess I don’t utilize the remote enough to desire that.

Also, strange that the empty string name doesn’t work. My .yaml is as follows and compiles fine:

esphome:
  name: bedroom-fan
  friendly_name: "Bedroom Fan"

packages:
  common: !include common.yaml
  ifan04: github://gagebenne/esphome/packages/ifan04.yaml

So, in Home Assistant the entities are Bedroom Fan (the fan) and Bedroom Fan Light (light). Otherwise the entity names get repetitive (Bedroom Fan Fan).

Hi there, I hope that someone can help me out.

This is all new to me but I’ve successfully flashed my iFan04-H with Tasmoto 13.0.0. Thanks to you people!!!

Unfortunately the fan is spinning to fast (rotations) for me in preset 1 (LOW). It is not comfortable. I would like to use a percentage-slider (custom setting) to slow it down to let say 20% of maybe even 15% (considering that LOW = 33%). I will never use preset MEDIUM of HIGH.

I’m hoping to be able to do so by using ESPHome. So i tried installing/flashing my iFan to ESPHome. But what ever I try, the flashing itself works (progress bar is showing 100% and the end messages are hopeful).

After flashing I always end up with the error message: An error occurred. Improv Wi-Fi Serial not detected. Then the iFan is unreachable, no connection to WiFi and no little blue light on the board or clicks on booting etc…

I tried:

  1. On my Windows 10 laptop: Flashing to ESPHome from Tasmoto webui (IP address of the iFan, than option ‘Firmware upgrade’
  2. On my Windows 10 laptop: Use Tasmotizer to install the bin file from HA.
  3. Install the ESPHome Add-on in HA and then try to add a new device via de webuser UI.
  4. Attachted the TTL directly on my HA device (Mac mini) and then try to install the bin-file from HA

To be sure I have HA up and running with MQTT and Tasmoto. Both working great. Also the remote of the iFan is working great. So that would be enough (no need for ESPHome), when the fan would spin/rotate less…

I once had ESPHome add-on installed on HA and then it discovered the iFan (something like 'ESP+last digits of the mac address), that is where I got the bin-file from. But whatever I try, ESPHome does not find the iFan anymore and I’m able to add a device manually…

Can someone help me?

Thank you in advance.

Review my posts above on flashing from the esptools and make sure your serial dongle has a regulator on it.

Sorry, Even if you get the ESPhome working, the PCB design of the sonoff ifan04 is done in such a manner that a % slider will never work.

There will always be only 3 settings 33%/66%/99(100)%. If you want more control over the fan you will need to find a different method (not sure which one tough)

Thank you for your reply. That’s unfortunate! I was hoping to use other percentages for spinning (slower the fan down a bit).

I’m not familiar with electronics and mainboards and chips. Do you have any knowledge to make my fan spin slower with an iFan04 (the use of WiFi and HA is very convenient of course).
I would not mind (let someone) soldering it.

Thank you in advance.

Thank you for your quick reply!
I read your post several times and I feel like I tried all the options you posted here. I also read the posts in your links. But I will give it an other try of course.

I bought a TTL with a 3,3 and 5 V regulator (jumper) and FT323RL chip. It my first flashing experience with a TTL and jumper wires etc…

Maybe the TTL (chip) is able to flash the iFan04-H to Tasmoto but not to ESPHome…?!
Is there a difference in flashing capabilities of the TTL that I have missed reading about flashing??

Just to be clear. The flashing of the iFan to ESPHome seems succesfull (the message at the end states: ‘Configuration installed’ or ‘Congratulations etc.’. But the iFan seems dead afterwards (i read somewhere that maybe it’s in an eternal boot cycle).

Go to your relays buttons on the tasmota webui and push multiple relays that is what we do in the above configurations. So for speed 1 you press relay 1 for speed 2 you press relay 1 and 2 for speed 3 you press 1 and 3.

I’m currently trying out tasmota because you said the RF remote works fine in it where it doesn’t in esphome.

Use the “logs” button there while the ttl usb device is connected and you will see what it is doing.

If you add stuff to the yaml before actually just getting it on the network then I would remove everything and just get a basic yaml. ie it should boot up as an ap then you can manually connect it to your network by connecting directly to the device just to rule everything out.

You may have added my I2C code which could cause a boot loop. I commented it out in case future people do the same.

There is no easy way to do what you are asking using the iFan04.

the iFan04 (and iFan03 and iFan02 and likely every other 3 speed fan controller) changes the speed by turning on relays that insert or remove specific values of capacitors in the fan voltage supply circuit that causes the fan to spin at higher or lower speeds determined by the electrical characteristics of the capacitors.

So you can only ever end up with 3 distinct speeds.

you might be able to put a different value of capacitor in the circuit (replacing one or all of the existing capacitors) but unless you find someone who designs electronic circuits getting the correct value of capacitor for the desired speed (along with the correct electrical ratings so you don’t burn down your house) isn’t going tgo be easy.

OTOH, where are you located?

if you are in the US then you might be able to use an IFan03 and end up with a lower speed. The iFan04 was a redesignb of the iFan03 which was originally designed to run on 230v systems. And when it wsas run on 120v systems a common complaint was that the fan was too slow on the lower speeds.

so an iFan03 might solve your problem OOTB with just flashing Tasmota or ESPHome on it and no hardware modifications needed.

The iFan04 has two versions H is for Higher voltage areas L is for the lower voltage areas. You may just even have to replace the capacitor in the fan if it is easier to access usually just sitting in the space with the wires. (Not sure what value you would need or what motor your fan uses to find the value you would need)

yeah, you’re right. I forgot about that. Thanks for the correction.

but I still remember hearing that the biggest complaints that people had about the iFan03 was that the slow speeds were too slow so one of them might be OK for the OP.

I actually replaced the caps in my iFan03’s and they seemed to work better for me but I was always a bit nervous about my soldering job so when the iFan04’s came out I replaced mine with those.

I actually have a couple of the original (unmodified) iFan02’s along with the modified iFan03’s laying around that I’ll probably never use.