- platform: gpio
id: ${devicetype}_${devicename}_button_${key}
name: "${friendly_devicename}按鍵${key}"
disabled_by_default: true
pin:
number: ${gpioid}
mode: INPUT_PULLUP
inverted: true
on_multi_click:
- timing:
- ON for at least 2s
- OFF for at least 0.5s
then:
switch.toggle: ${devicetype}_${devicename}_switch_${key}
- timing:
- ON for at most 1s
- OFF for at least 0.5s
then:
if:
condition:
api.connected:
then:
homeassistant.event:
event: esphome.events
data:
id: ${devicetype}-${devicename}
method: click
button: ${key}
else:
switch.toggle: ${devicetype}_${devicename}_switch_${key}
- timing:
- ON for at most 1s
- OFF for at most 1s
- ON for at most 1s
- OFF for at least 0.2s
then:
homeassistant.event:
event: esphome.events
data:
id: ${devicetype}-${devicename}
method: doubleclick
button: ${key}