Hi,
I’m discovering HA and ESPHome actually, which seems powerfull, but I don’t find how I could handle what I need (that I previously did by manual coding in Arduino IDE and calling an URL from Jeedom, but now that I moved to HA, I think ESPHome would be the good choice !)
I have 2 push buttons, let’s call them B0 and B1. I have 4 lights, L0, L1, L2, L3. L0 is the ceiling light.
I want such scenario:
- Single press B0 : turn L0 on, value 10%
- Hold press B0 : turn L0 on, value 50%
- Long hold press B0 : turn L0 on, value 100%
- Single press B1 : turn L1 on, value 10%
- Double press B1 : turn L1, L2, L3 on, value 10%
- Hold press B1 : turn L1, L2, L3 on, value 50%
- Long hold press B1 : turn L1, L2, L3 on, value 100%
- Single press B0 if L0 is on : turn L0 off.
- Single press B1 if L1 or L2 or L3 is on : turn L1, L2, L3 off
Until now, I can do all of this, using the following ESPHome configuration:
text_sensor:
- platform: template
name: 'Button 1'
id: button1
icon: 'mdi:toggle-switch'
on_value: # When a state is set
then:
- if:
condition:
text_sensor.state:
id: button1
state: ''
else: # If non-empty
- delay: 20ms
- text_sensor.template.publish:
id: button1
state: !lambda 'return "";' # Reset to empty
- platform: template
name: 'Button 2'
id: button2
icon: 'mdi:toggle-switch'
on_value: # When a state is set
then:
- if:
condition:
text_sensor.state:
id: button2
state: ''
else: # If non-empty
- delay: 20ms
- text_sensor.template.publish:
id: button2
state: !lambda 'return "";' # Reset to empty
binary_sensor:
- platform: gpio
pin:
number: D2
mode: INPUT_PULLUP
id: raw_switch_state
internal: true
filters:
- invert:
- delayed_on: 30ms
- delayed_off: 30ms
on_multi_click:
- timing:
- ON for 40ms to 400ms
- OFF for at least 500ms
then:
- text_sensor.template.publish:
id: button1
state: !lambda 'return "single";'
- timing:
- ON for 40ms to 400ms
- OFF for 40ms to 400ms
- ON for 40ms to 400ms
- OFF for at least 500ms
then:
- text_sensor.template.publish:
id: button1
state: !lambda 'return "double";'
- timing:
- ON for 40ms to 400ms
- OFF for 40ms to 400ms
- ON for 40ms to 400ms
- OFF for 40ms to 400ms
- ON for 40ms to 400ms
- OFF for at least 500ms
then:
- text_sensor.template.publish:
id: button1
state: !lambda 'return "triple";'
- timing:
- ON for at least 1500ms
then:
- text_sensor.template.publish:
id: button1
state: !lambda 'return "hold";'
- timing:
- ON for at least 3000ms
then:
- text_sensor.template.publish:
id: button1
state: !lambda 'return "longhold";'
- platform: gpio
pin:
number: D3
mode: INPUT_PULLUP
id: raw_switch_state2
internal: true
filters:
- invert:
- delayed_on: 30ms
- delayed_off: 30ms
on_multi_click:
- timing:
- ON for 40ms to 400ms
- OFF for at least 500ms
then:
- text_sensor.template.publish:
id: button2
state: !lambda 'return "single";'
- timing:
- ON for 40ms to 400ms
- OFF for 40ms to 400ms
- ON for 40ms to 400ms
- OFF for at least 500ms
then:
- text_sensor.template.publish:
id: button2
state: !lambda 'return "double";'
- timing:
- ON for 40ms to 400ms
- OFF for 40ms to 400ms
- ON for 40ms to 400ms
- OFF for 40ms to 400ms
- ON for 40ms to 400ms
- OFF for at least 500ms
then:
- text_sensor.template.publish:
id: button2
state: !lambda 'return "triple";'
- timing:
- ON for at least 1500ms
then:
- text_sensor.template.publish:
id: button2
state: !lambda 'return "hold";'
- timing:
- ON for at least 3000ms
then:
- text_sensor.template.publish:
id: button2
state: !lambda 'return "longhold";'
But now, I’d like to add:
- Long press B0 and B1 : turn all house lights off
How can I achieve detection of both buttons pressed to trigger a text to HA on this behavior?
I know I could apply a scenario in HA, but the thing is, if B0 is pressed slightly before B1, HA will be first notified of B0 press before B1 press and will trigger B0 pressed scenario before “both buttons pressed” scenario.
I know in this case it would work, because “turn all lights off” would cancel “turn L0 on, value 50%”, but in other cases in my house, such coincidence may not appear, and I would like to avoid a slight flash of intensity on the bulb, as it is in the bedroom
Thanks for your help!