Skip to content

Instantly share code, notes, and snippets.

@b2un0
Last active March 3, 2025 14:04
Show Gist options
  • Save b2un0/3954da19fba56a1e950843c6aa7a1d65 to your computer and use it in GitHub Desktop.
Save b2un0/3954da19fba56a1e950843c6aa7a1d65 to your computer and use it in GitHub Desktop.
substitutions:
name: "buro-fan"
friendly_name: "Büro Ventilator"
comment: "Sonoff Ifan03 Ventilator (ESP01 1M)"
on_boot_light: ALWAYS_ON # or ALWAYS_OFF
spare_button_light_entity: "light.buro"
esphome:
name: $name
comment: $comment
esp8266:
board: esp01_1m
api:
encryption:
key: !secret api_encryption
ota:
- platform: esphome
password: !secret ota_password
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
ap:
ssid: "$name Fallback Hotspot"
password: !secret wifi_password
captive_portal:
logger:
level: ERROR
sensor:
- platform: wifi_signal
name: "$name WiFi Signal"
update_interval: 60s
entity_category: diagnostic
button:
- platform: restart
name: "$name restart"
entity_category: diagnostic
- platform: template
name: "$name Buzzer"
id: buzzer
on_press:
- switch.turn_on: buzzer_switch
- delay: 50ms
- switch.turn_off: buzzer_switch
text_sensor:
- platform: uptime
name: "$name Uptime"
entity_category: diagnostic
- platform: wifi_info
ip_address:
id: wifi_ip
name: "$name IP Address"
entity_category: diagnostic
output:
- platform: gpio
id: light_relay
pin: GPIO9
inverted: true
switch:
- platform: gpio
internal: True
id: buzzer_switch
name: "Buzzer"
pin:
number: GPIO10
inverted: true
- platform: gpio
internal: true
pin: GPIO14
id: fan_relay1
restore_mode: ALWAYS_OFF
- platform: gpio
internal: true
pin: GPIO12
id: fan_relay2
restore_mode: ALWAYS_OFF
- platform: gpio
internal: true
pin: GPIO15
id: fan_relay3
restore_mode: ALWAYS_OFF
light:
- platform: binary
name: "$friendly_name"
output: light_relay
id: ifan03_light
restore_mode: $on_boot_light
fan:
- platform: template
id: ifan03_fan
name: "$friendly_name"
speed_count: 3
restore_mode: NO_RESTORE # important
on_turn_on:
- switch.turn_on: fan_relay1
- switch.turn_off: fan_relay2
- switch.turn_off: fan_relay3
on_turn_off:
- switch.turn_off: fan_relay1
- switch.turn_off: fan_relay2
- switch.turn_off: fan_relay3
on_speed_set:
lambda: |-
if (id(ifan03_fan).speed == 1) {
id(fan_relay1).turn_on();
id(fan_relay2).turn_off();
id(fan_relay3).turn_off();
} else if (id(ifan03_fan).speed == 2) {
id(fan_relay1).turn_on();
id(fan_relay2).turn_on();
id(fan_relay3).turn_off();
} else if (id(ifan03_fan).speed == 3) {
id(fan_relay1).turn_off();
id(fan_relay2).turn_off();
id(fan_relay3).turn_on();
}
remote_receiver:
pin: GPIO3
dump: raw
binary_sensor:
# remote button row 3 button 1
- platform: remote_receiver
name: "$name 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
- button.press: buzzer
internal: true
# remote button row 3 button 2
- platform: remote_receiver
name: "$name 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: 1
- button.press: buzzer
internal: true
# remote button row 2 button 2
- platform: remote_receiver
name: "$name 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: 2
- button.press: buzzer
internal: true
# remote button row 2 button 1
- platform: remote_receiver
name: "$name 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: 3
- button.press: buzzer
internal: true
# remote button row 1 button 1
- platform: remote_receiver
name: "$name 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
- button.press: buzzer
internal: true
# remote button row 1 button 2 - used to call a home assistant service
- platform: remote_receiver
name: "$name 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: light.toggle
data:
entity_id: $spare_button_light_entity
- button.press: buzzer
internal: true
@b2un0
Copy link
Author

b2un0 commented Mar 3, 2025

I thought this also first, but you always need to enable relay one to get energy for two and three.

@HannesDi
Copy link

HannesDi commented Mar 3, 2025

Hmn...

That's strange, I assume that there are different revisions of ifan3.

if i use your script as you have built it, then my fan turns very fast on level 2 and 3 and hums very unhealthy (loud)

with my customization everything is as usual and ok.
in my old script this was also solved in the conditions:

   - if:
       condition:
         and:
           - switch.is_on: relay_fan1
           - switch.is_off: relay_fan2
           - switch.is_off: relay_fan3
       then:
         - fan.turn_on:
             id: ${slug}_fan
             speed: 1
   - if:
       condition:
         and:
           - switch.is_off: relay_fan1
           - switch.is_on: relay_fan2
           - switch.is_off: relay_fan3
       then:
         - fan.turn_on:
             id: ${slug}_fan
             speed: 2
   - if:
       condition:
         and:
           - switch.is_off: relay_fan1
           - switch.is_off: relay_fan2
           - switch.is_on: relay_fan3
       then:
         - fan.turn_on:
             id: ${slug}_fan
             speed: 3

But no offense, I just wanted to share my experience.

Best Regards
Hannes

@b2un0
Copy link
Author

b2un0 commented Mar 3, 2025

thats strange :D

previously i used the following code and migrated this for myself to "yaml only" stuff cause of removed platform: custom from esphome.

https://github.com/Jaco1990/sonoff_ifan03_esphome_ha/blob/main/ifan03.h

for my ifan03 speed 2 is the same as speed 1 if i only turn on relay 2

but your right for speed 3 only relay 3 is required (i changed this in this gist).

thanks for your advice

@HannesDi
Copy link

HannesDi commented Mar 3, 2025

So here I am again :-)

I think I know the reason or have a hunch.

It's not the ifan3 that's different, it's the fan that's attached to it.

My fan still has a pull cord on the side with which I can adjust the speed by hand or have to if I don't use a remote control at all.

If I set the cord incorrectly, for example, the fan doesn't come on at all because it is set to OFF. 2 moves further it shows the behavior as you described for level 2.

Apparently the switch disconnects parts of the motor winding or connects other windings.

So my fan with the pull cord is set to level 3 (1 position before OFF) and this works for me with the individual relay control.

I assume that this is also how it is intended... The fan should be at max rotation and the ifan switches the voltage or windings on and off.

Fortunately, we're all tinkerers and research things like this.

I think there is no right or wrong to what you enter in the script because you don't know (at least with my model) how the pull cord is positioned.

Best Regards
Hannes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment