和普通继电器没差别,直接控制模板开关就行了
binary_sensor:
- platform: gpio
pin:
number: $button_pin
inverted: true #反转属性
mode:
input: true #将引脚配置为输入
pullup: true #激活引脚上的内部上拉电阻
name: "${friendly_name}_B1"
id: "${friendly_name}_B1"
on_click: #按钮单击
- min_length: 50ms
max_length: 1000ms
then:
- if:
condition:
lambda: 'return id(${friendly_name}_Keylock).state ;'
then:
- switch.toggle: "${friendly_name}_switch1" #切换开关状态
|