Skip to content

Instantly share code, notes, and snippets.

@albertnis
Created February 17, 2020 07:07
Show Gist options
  • Star 20 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save albertnis/f33066b0b3623a9839a3429c8f19f4d4 to your computer and use it in GitHub Desktop.
Save albertnis/f33066b0b3623a9839a3429c8f19f4d4 to your computer and use it in GitHub Desktop.
Making a custom multi-click push button using ESPHome
esphome:
name: bedside_button
platform: ESP8266
board: esp12e
wifi:
ssid: "ssid"
password: "example"
logger:
api:
password: "example"
ota:
password: "example"
light:
- platform: monochromatic
id: bedside_indicator
name: "Bedside Indicator"
output: led_out
default_transition_length: .3s
restore_mode: RESTORE_DEFAULT_OFF
output:
- platform: esp8266_pwm
id: led_out
pin: GPIO13
binary_sensor:
- platform: gpio
pin:
number: GPIO5
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 330ms
then:
- text_sensor.template.publish:
id: bedside_button
state: !lambda 'return "single";'
- timing:
- ON for 40ms to 400ms
- OFF for 40ms to 300ms
- ON for 40ms to 400ms
- OFF for at least 330ms
then:
- text_sensor.template.publish:
id: bedside_button
state: !lambda 'return "double";'
- timing:
- ON for 40ms to 400ms
- OFF for 40ms to 300ms
- ON for 40ms to 400ms
- OFF for 40ms to 300ms
- ON for 40ms to 400ms
- OFF for at least 50ms
then:
- text_sensor.template.publish:
id: bedside_button
state: !lambda 'return "triple";'
- timing:
- ON for at least 2s
then:
- text_sensor.template.publish:
id: bedside_button
state: !lambda 'return "hold";'
text_sensor:
- platform: template
name: "Bedside button"
id: bedside_button
icon: "mdi:toggle-switch"
on_value:
then:
- if:
condition:
text_sensor.state:
id: bedside_button
state: ""
else:
- delay: 20ms
- text_sensor.template.publish:
id: bedside_button
state: !lambda 'return "";'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment