I have got the iFan03 working correctly with the RF remote and HA. It requires only ESPHome, no other automations or nodeRed. I have gather all my information from a number of posts relating to the iFan02 and iFan03 from the forums and used them all to complete the code, thank you to everyone who shared their code.
In order to make this work you will need to create a “ifan03.h” file in your ESPHome folder within the HA config folder. Then you will need to copy the following code into this file:
#include "esphome.h"
using namespace esphome;
class IFan03Output : public Component, public FloatOutput {
public:
void write_state(float state) override {
if (state < 0.3) {
// OFF
digitalWrite(14, LOW);
digitalWrite(12, LOW);
digitalWrite(15, LOW);
} else if (state < 0.6) {
// low speed
digitalWrite(14, HIGH);
digitalWrite(12, LOW);
digitalWrite(15, LOW);
} else if (state < 0.9) {
// medium speed
digitalWrite(14, HIGH);
digitalWrite(12, HIGH);
digitalWrite(15, LOW);
} else {
// high speed
digitalWrite(14, HIGH);
digitalWrite(12, LOW);
digitalWrite(15, HIGH);
}
}
};
Now you can start building your yaml file using the code below:
esphome:
name: bedroom_ifan03
platform: ESP8266
board: esp01_1m
includes:
- ifan03.h
on_boot:
priority: 225
# turn off the light as early as possible
then:
- light.turn_off: ifan03_light
wifi:
ssid: "SSID"
password: "PASSWORD"
manual_ip:
static_ip: 192.168.1.106
gateway: 192.168.1.1
subnet: 255.255.255.0
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Bedroom Ifan03 Fallback Hotspot"
password: "PASSWORD"
captive_portal:
web_server:
port: 80
# Enable logging
logger:
# Enable Home Assistant API
api:
ota:
output:
- platform: custom
type: float
outputs:
id: fanoutput
lambda: |-
auto ifan03_fan = new IFan03Output();
App.register_component(ifan03_fan);
return {ifan03_fan};
- platform: gpio
pin: GPIO9
id: light_output
light:
- platform: binary
name: "iFan03 Light"
output: light_output
id: ifan03_light
switch:
- platform: template
id: update_fan_speed
optimistic: True
turn_on_action:
then:
- delay: 200ms
- if:
condition:
and:
- switch.is_off: fan_relay1
- switch.is_off: fan_relay2
- switch.is_off: fan_relay3
then:
- fan.turn_off: ifan03_fan
- if:
condition:
and:
- switch.is_on: fan_relay1
- switch.is_off: fan_relay2
- switch.is_off: fan_relay3
then:
- fan.turn_on:
id: ifan03_fan
speed: LOW
- if:
condition:
and:
- switch.is_on: fan_relay1
- switch.is_on: fan_relay2
- switch.is_off: fan_relay3
then:
- fan.turn_on:
id: ifan03_fan
speed: MEDIUM
- if:
condition:
and:
- switch.is_on: fan_relay1
- switch.is_off: fan_relay2
- switch.is_on: fan_relay3
then:
- fan.turn_on:
id: ifan03_fan
speed: HIGH
- switch.turn_off: update_fan_speed
- platform: gpio
pin: GPIO14
id: fan_relay1
- platform: gpio
pin: GPIO12
id: fan_relay2
- platform: gpio
pin: GPIO15
id: fan_relay3
fan:
- platform: speed
output: fanoutput
id: ifan03_fan
name: "Bedroom Fan"
#Remote Control
remote_receiver:
pin: GPIO3
dump: raw
binary_sensor:
- platform: remote_receiver
name: "Bedroom 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
- platform: remote_receiver
name: "Bedroom 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: LOW
- platform: remote_receiver
name: "Bedroom 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: MEDIUM
- platform: remote_receiver
name: "Bedroom 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: HIGH
- platform: remote_receiver #top left button
name: "Bedroom 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
- platform: remote_receiver #top right button
name: "iFan03 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: switch.toggle
data:
entity_id: switch.effect_light
The last raw RF remote code can be utilized to toggle anything additional in HA, you will see in my code I use it to turn on the ambient lighting in the bedroom.
Assuming that you have paired your remote to the ifan03 before hand, you should be able to use the remote immediately after reboot, and HA will update the status of the fan accordingly.
RF Remote Pairing: To pair your remote with the iFan03, power off the unit, then return power to the device and press and hold any button on the remote within 5 seconds. and you should here a beep from the iFan03. You will not be required to relearn all the RF codes.
Additional Tinkering: The iFan03 is equip with a buzzer which can be used to beep every time a button is pressed on the RF Remote