I am currently working to build out a node utilizing three relays with interlocks to control a three speed fan from HASS. I haven’t wired it all up and tested yet.
What I am currently trying to figure out is how to utilize one momentary button switch as a binary sensor (unless there is a better route) to toggle between modes. i.e. If off, go low, if low go med, if med go high and if high go low by checking and determining which if any relays are on (utilizing interlock). Does anyone have any suggestions as to how to program the automation. Looking to do this onboard and not have the logic reliant on HASS.
I have based my programming off of this video’s: Home Assistant #ESPHome #Sonoff - 3-Speed Smart Fan Convert - YouTube
Thanks!
esphome:
name: box_fan_one
platform: ESP8266
board: d1_mini
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_pass
manual_ip:
static_ip: x.x.x.x
gateway: x.x.x.x
subnet: x.x.x.x
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Box Fan Fallback Hotspot"
password: !secret ap_fallback_pass
captive_portal:
# Enable logging
logger:
# Enable Home Assistant API
api:
password: !secret api_pass
ota:
password: !secret ota_pass
substitutions: #for the name of the fan to input below
name: box_fan_one
binary_sensor:
- platform: homeassistant #For home assistant default click
entity_id: input_boolean.${name}
id: ${name}
on_press:
then:
switch.turn_on: relay1
on_release:
then:
- switch.turn_off: relay1
- switch.turn_off: relay2
- switch.turn_off: relay3
- platform: gpio # For push button onboard
id: push_button
pin:
number: D2
mode: INPUT_PULLUP
on_press:
if: #insert logic to check relay state and determine what to turn on
switch:
- platform: gpio
name: "${name}_High"
pin: D1
icon: mdi:fan
id: relay1
interlock: &interlock_group [relay1, relay2, relay3]
interlock_wait_time: 300ms
- platform: gpio
name: "${name}_Medium"
pin: D2
inverted: true
icon: mdi:fan
id: relay2
interlock: *interlock_group
interlock_wait_time: 300ms
- platform: gpio
name: "${name}_Low"
pin: D3
inverted: true
icon: mdi:fan
id: relay3
interlock: *interlock_group
interlock_wait_time: 300ms