如图,如何让switch(Relay)的状态必须跟随gpio(button)状态
例如:当Button为关闭时,Relay通过手动也无法打开;
当Button为打开时,Relay通过手动也无法关闭。
附上代码,望大神指点。
binary_sensor:
- platform: status
name: "Sonoff Basic Status"
id: button
- platform: gpio
pin:
number: GPIO0
mode:
input: true
pullup: true
inverted: true
name: "Sonoff Basic Button"
filters:
- delayed_on_off: 5s
on_press:
then:
- switch.turn_on: relay
on_release:
if:
condition:
- switch.is_on: relay
then:
- switch.turn_off: relay
switch:
- platform: gpio
name: "Sonoff Basic Relay"
pin: GPIO2
inverted: true
id: relay
restore_mode: RESTORE_DEFAULT_OFF
|