Brief background, I have a Sonoff ifan02 connected to ceiling fan, and a Sonoff T1 wall switch.
Both flashed with EspHome.
I want to be able to increment the fan speed when pressing a button on T1, and ultimately switch it off.
Off>Low>Medium>High>Off, alternatively toggle between Off and Low.
It’s easy enough to use the home assistant service fan.set_percentage to turn it on, but my lack of knowledge on templates/lambdas (I assume that’s what I should use) and HA in general keep me from achieving the goal.
wall_switch - yaml
binary_sensor:
- platform: gpio
pin:
number: GPIO9
mode:
input: true
pullup: true
inverted: true
id: button_2
on_press:
- homeassistant.service:
service: fan.set_percentage
data:
#don't know how to change and check for existing fan state, and toggle as required
percentage: '6'
entity_id: fan.study_fan
# then:
# - light.toggle: light_2
I will also be using this in 4 other rooms, as well as a central NSPanel.
Thanks in advance for any assistance
Thanks for this, after small change to global variable ‘1’, it compiled and uploaded.
However, nothing happens. I have added a few log entries which shows the increment and off states.
- lambda: |-
if (id(fan_speed) < 3) {
ESP_LOGD("main", "Fan speed increment");
id(fan_speed) += 1;
} else {
ESP_LOGD("main", "Fan set to Off");
id(fan_speed) = 0;
}
[17:59:40][D][binary_sensor:036]: 'button_2': Sending state ON
[17:59:40][D][main:048]: Fan speed increment
[17:59:40][D][binary_sensor:036]: 'button_2': Sending state OFF
[18:25:40][D][binary_sensor:036]: 'button_2': Sending state ON
[18:25:40][D][main:048]: Fan speed increment
[18:25:40][D][binary_sensor:036]: 'button_2': Sending state OFF
[18:25:41][D][binary_sensor:036]: 'button_2': Sending state ON
[18:25:41][D][main:048]: Fan speed increment
[18:25:42][D][binary_sensor:036]: 'button_2': Sending state OFF
[18:25:42][D][binary_sensor:036]: 'button_2': Sending state ON
[18:25:43][D][main:051]: Fan set to Off
[18:25:43][D][binary_sensor:036]: 'button_2': Sending state OFF
I suspect the code is correct, but the fan needs an ‘on’ command, the call and percentages works in developer tools.
I managed to get it working. @zoogara Thanks for pointing me in right direction, I admire everyone with their HA and EspHome knowledge.
Here is a working solution: