小白在做按键开关的多击实验中,用官方实例,总是不出效果。https://esphome.io/components/binary_sensor/index.html#on-multi-click
on_multi_click:
- timing:
- ON for at most 1s
- OFF for at most 1s
- ON for at most 1s
- OFF for at least 0.2s
then:
- logger.log: "Double Clicked"
后面发现只要将PIN初始化中加入反相即可。
binary_sensor:
- platform: gpio #总开关
# https://esphome.io/components/binary_sensor/gpio.html
pin:
number: D2 #GPIO15
mode: INPUT_PULLUP
inverted: True #一定要加上
filters:
- delayed_on: 50ms
- delayed_off: 50ms
name: ${friendly_name} Main Button
internal: True #false 将此组件标记为内部。内部组件不会暴露在前端
加入inverted: True ,就可以实现上面的单击短按,长按,双击的不同动作了。
又可以继续精彩的HA历程了。
|