For me, I have 4 fans that use this remote, so I made a universal remote for HA. So I did something very similar.
The only changes I made were simplifying some of the code you gave, and I added wires and code for setting the dipswitches on the back of the remote. I also split it between 2 ESP8266 devices (NodeMCUv2).
And here is the code (passwords removed). One is the Fan Controller and the other is the Fan Picker:
esphome:
name: fanmaster
platform: ESP8266
board: nodemcuv2
# Enable logging
logger:
# Enable Home Assistant API
api:
ota:
password: ""
wifi:
ssid: "IoT_1"
password: ""
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Fanmaster Fallback Hotspot"
password: ""
captive_portal:
switch:
- platform: gpio
pin: 5 #D1
id: relay1
inverted: no
interlock: &interlock_group [relay1, relay2, relay3, relay4, relay5, relay6]
- platform: gpio
pin: 4 #D2
id: relay2
inverted: no
interlock: *interlock_group
- platform: gpio
pin: 2 #D4
id: relay3
inverted: no
interlock: *interlock_group
- platform: gpio
pin: 16 #D0
id: relay4
inverted: no
interlock: *interlock_group
- platform: gpio
pin: 14 #D5
id: relay5
inverted: no
interlock: *interlock_group
- platform: gpio
pin: 12 #D6
id: relay6
inverted: no
interlock: *interlock_group
- platform: template
name: "Toggle Fan Light"
icon: "mdi:lightbulb"
turn_on_action:
- switch.turn_on: relay1
- delay: 260ms
- switch.turn_off: relay1
- platform: template
name: "Dim Fan Light"
icon: "mdi:lightbulb-on"
turn_on_action:
- switch.turn_on: relay1
- delay: 2500ms
- switch.turn_off: relay1
- platform: template
name: "Fan On High"
icon: "mdi:gauge-full"
turn_on_action:
- switch.turn_on: relay4
- delay: 260ms
- switch.turn_off: relay4
- platform: template
name: "Fan On Medium"
icon: "mdi:gauge"
turn_on_action:
- switch.turn_on: relay3
- delay: 260ms
- switch.turn_off: relay3
- platform: template
name: "Fan On Low"
icon: "mdi:gauge-low"
turn_on_action:
- switch.turn_on: relay2
- delay: 260ms
- switch.turn_off: relay2
- platform: template
name: "Fan Off"
icon: "mdi:fan-off"
turn_on_action:
- switch.turn_on: relay5
- delay: 260ms
- switch.turn_off: relay5
- platform: template
name: "Fan Change Rotation"
icon: "mdi:rotate-3d"
turn_on_action:
- switch.turn_on: relay6
- delay: 260ms
- switch.turn_off: relay6
binary_sensor:
- platform: status
name: "Family Room ESPHome Status"
esphome:
name: fanpicker
platform: ESP8266
board: nodemcuv2
# Enable logging
logger:
# Enable Home Assistant API
api:
ota:
password: ""
wifi:
ssid: "IoT_1"
password: ""
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Fanpicker Fallback Hotspot"
password: ""
captive_portal:
switch:
- platform: gpio
pin: D0
id: sw1
name: "sw1"
icon: "mdi:switch"
#on_turn_on:
#on_turn_off:
- platform: gpio
pin: D1
id: sw2
name: "sw2"
icon: "mdi:switch"
#on_turn_on:
#on_turn_off:
- platform: gpio
pin: D2
id: sw3
name: "sw3"
icon: "mdi:switch"
#on_turn_on:
#on_turn_off:
- platform: gpio
pin: D4
id: sw4
name: "sw4"
icon: "mdi:switch"
#on_turn_on:
#on_turn_off:
- platform: gpio
pin: D5
id: sw5
name: "sw5"
icon: "mdi:switch"
#on_turn_on:
#on_turn_off:
- platform: template
name: "Bedroom_Fan"
id: Bedroom_Fan
turn_on_action:
- then:
- switch.turn_on: sw1
- switch.turn_on: sw2
- switch.turn_on: sw3
- switch.template.publish:
id: Bedroom_Fan
state: ON
turn_off_action:
- then:
- switch.turn_off: sw1
- switch.turn_off: sw2
- switch.turn_off: sw3
- switch.turn_off: sw4
- switch.turn_off: sw5
- switch.template.publish:
id: Bedroom_Fan
state: OFF
- platform: template
name: "Office_Fan"
id: Office_Fan
turn_on_action:
- then:
- switch.turn_off: sw1
- switch.turn_off: sw2
- switch.turn_off: sw3
- switch.turn_off: sw4
- switch.turn_off: sw5
- switch.template.publish:
id: Office_Fan
state: ON
turn_off_action:
- then:
- switch.turn_off: sw1
- switch.turn_off: sw2
- switch.turn_off: sw3
- switch.turn_off: sw4
- switch.turn_off: sw5
- switch.template.publish:
id: Office_Fan
state: OFF
- platform: template
name: "Loft_Fan"
id: Loft_Fan
turn_on_action:
- then:
- switch.turn_on: sw1
- switch.turn_off: sw2
- switch.turn_on: sw3
- switch.turn_on: sw4
- switch.turn_on: sw5
- switch.template.publish:
id: Loft_Fan
state: ON
turn_off_action:
- then:
- switch.turn_off: sw1
- switch.turn_off: sw2
- switch.turn_off: sw3
- switch.turn_off: sw4
- switch.turn_off: sw5
- switch.template.publish:
id: Loft_Fan
state: OFF
- platform: template
name: "LivingRoom_Fan"
id: LivingRoom_Fan
turn_on_action:
- then:
- switch.turn_off: sw1
- switch.turn_on: sw2
- switch.turn_on: sw3
- switch.turn_on: sw4
- switch.turn_on: sw5
- switch.template.publish:
id: LivingRoom_Fan
state: ON
turn_off_action:
- then:
- switch.turn_off: sw1
- switch.turn_off: sw2
- switch.turn_off: sw3
- switch.turn_off: sw4
- switch.turn_off: sw5
- switch.template.publish:
id: LivingRoom_Fan
state: OFF
And finally the HA Dashbord View:
Of course I need to design a case and finish it up, but for now it works!
Thanks to the OP for the inspiration!!