Sonoff Ifan04 - ESPHome working code

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.

Good work that makes sense I would love to ditch the capacitors and just use the relays directly with the pull chain switch so it can switch coils properly instead of making weird hums on the full-speed coil when you slow it down.

Found this one (altough it seems you cant buy it anywhere)

its a 6 speed fan controller:
https://nl.aliexpress.com/i/1005002817617439.html?gatewayAdapt=glo2nld

You would have to flash it / program it to your needs, I also saw other 4/5 speed ones, but never a variable one for 230V

Note it says for DC ceiling fan.

Is there a way to expose the buzzer on the PCB to use in Home Assistant. I’d like to be able to use it for notifications or alerts in variouse rooms where iFan’s are installed. For example if my house alarm is triggered at night the buzzer could start beeping in the master bedroom?

Yup just set it up like a regular gpio pin and do what you want with it (GPIO10).

This is the first ESPHome device (iFan04-H) so coding isn’t that obvious to me at the moment.

The good news is, I got your code working just fine once I got the basics of getting code to a device. Even managed to add a few diagnostics and an uptime sensor.

However what I’m looking for is a switch to enable/disable the buzzer when required without having edit the code. A liitle help there would be appreciated.

This is already in the sources above but in case you missed it:

switch:
  - platform: template
    id: buzzer_dummy
    name: "Buzzer"
    optimistic: True

Will give you a button in HA for you to toggle

I was using cpyarger’s code. I changed to that one because it had the buzzer working hard coded.
The yaml code you referred too is from one that wouldn’t enable the buzzer regardless of the switch state.

My current code is a merger of the two, mainly to get the other stats like uptime, wifi ssid etc.

I know its a little picky, but I like the little details :slight_smile:

Be sure to share :slight_smile:

1 Like

This adapter posted above doesn’t even show up in aliexpress anymore.
https://www.aliexpress.com/item/32761423124.html
Are there any suggested adapters from amazon that are known to work??

Thanks!

Just type CH340 in aliexpress and you will find the module pretty quickly by referencing the picture above.

https://www.aliexpress.com/item/32831329095.html

The only thing that matters is that it has an onboard regulator circled in the image above.

I just found this person’s code and it works exceptionally well with the remote so far. Very responsive.

Everyone may want to give it a test and if so report back.

I commented out the controller flash writing stuff. As I never want it to boot up in the last state (power outage or turn on randomly in the night etc.) Always want it off on boot. Probably need to do more than that.

Looks like they also use my I2C addon discovery work.

You can conveniently reuse the buzzer/wifisync buttons on the remote like this for other lights or stuff in the room.

          - if: # Buzzer on/off
              condition:
                lambda: return x == "0106000101";
              then:
                #- switch.toggle: buzzer_enabled
                #- output.turn_on: buzzer
                #- delay: 10ms
                #- output.turn_off: buzzer
                - homeassistant.service:
                    service: light.toggle
                    data:
                      entity_id: light.sengled_e11_n1ea_light
          - if: # Press one of the two bottom buttons on the remote Wifi/RF unsync (Do not hold down)
              condition:
                lambda: return x == "0101000102";
              then:
                - homeassistant.service:
                    service: light.toggle
                    data:
                      area_id: living_room

Make sure to turn this on to control other devices in HA from the ESPHome device

1 Like

Thanks for posting this. I just started using esphome and switched this device from tasmota. I actually use smartbulbs in my fan since the sonoff doesn’t dim (the light wire goes right to hot and not through the sonoff). Adding the light.toggle call service for the bulbs right in the config lets me still use the remote to turn the bulbs on and off with no extra automations.

Overall the code works well, but i did have a situation where quickly turning the fan off after first setting it to low caused the fan to come back on high after a few seconds. It was one of the first times after flashing, I’ll have to see if it happens again.

1 Like

Came here after finding that exact github project. Have you been working with it? I’ve been using your code from earlier this year with no issues. Hate switching code out unless this guy’s git is a better method.

1 Like

I’ve had my ifan04 for a while, but I just decided to convert it over the esphome. I’m using https://github.com/gagebenne/esphome/blob/8835ca6abbcc93e787d27f86f404c2ced0bdefb0/packages/ifan04.yaml for my yaml, but it seems there is an issue with pin 3. I get this error.

INFO ESPHome 2023.12.5
INFO Reading configuration /config/ifan04.yaml...
WARNING ESP8266: Pin 9 (9-10) might already be used by the flash interface in QUAD IO flash mode.
WARNING ESP8266: Pin 10 (9-10) might already be used by the flash interface in QUAD IO flash mode.
Failed config

uart: [source <unicode string>:15]
  
  Pin 3 is used in multiple places.
  - tx_pin: 
      number: 1
      mode: 
        output: True
        input: False
        open_drain: False
        pullup: False
        pulldown: False
        analog: False
      inverted: False
    rx_pin: 
      number: 3
      mode: 
        input: True
        output: False
        open_drain: False
        pullup: False
        pulldown: False
        analog: False
      inverted: False
    baud_rate: 9600
    rx_buffer_size: 256
    stop_bits: 1
    data_bits: 8
    parity: NONE
remote_receiver: [source <unicode string>:20]
  
  Pin 3 is used in multiple places.
  - pin: 
      number: 3
      mode: 
        input: True
        output: False
        open_drain: False
        pullup: False
        pulldown: False
        analog: False
      inverted: False
    dump: []
    tolerance: 25
    buffer_size: 1000
    filter: 50us
    idle: 10ms
    memory_blocks: 3

I did a little searching and it sounds like there might be some brand new checking to prevent accidental config errors. I experimented with adding allow_other_uses: True but I couldn’t figure out the syntax.

Things like that are why it was added. You’re using the same pin for uart RX and the remote receiver which really doesn’t make sense and you’re lucky it works.

This compiled but sounds like it might not be the right thing to do in the end.

uart:
  tx_pin: 1
  rx_pin:
    number: 3
    allow_other_uses: true
  baud_rate: 9600

remote_receiver:
  pin:
    number: 3
    allow_other_uses: true

It’s not. What are you trying to do with that?