不太会精简代码,暂时实现了,开的时候蓝灯,关的时候黄灯。
switch:
- platform: gpio
pin: 14
id: "relay"
name: "relay"
inverted: true
- platform: gpio
pin: 0
name: "yellow"
id: "yellow"
inverted: yes
- platform: gpio
pin: 2
name: "blue"
id: "blue"
inverted: yes
- platform: gpio
pin: 15
name: "light"
id: "light"
- platform: gpio
pin: 12
name: "Action"
id: "gpio12"
- platform: template
name: "Guomei-switch"
id: "auto1"
optimistic: true
turn_on_action:
then:
- switch.turn_on: relay
- switch.turn_on: light
- switch.turn_on: blue
- switch.turn_off: yellow
- switch.turn_on: gpio12
- switch.turn_off: gpio12
turn_off_action:
then:
- switch.turn_off: relay
- switch.turn_on: light
- switch.turn_on: yellow
- switch.turn_off: blue
- switch.turn_on: gpio12
- switch.turn_off: gpio12
binary_sensor:
- platform: gpio
name: "button"
pin: 13
internal: yes
filters:
- invert:
- delayed_on: 50ms
- delayed_off: 50ms
on_click:
- min_length: 50ms
max_length: 500ms
then:
- switch.toggle: relay
- switch.turn_on: light
- switch.turn_on: gpio12
- switch.turn_off: gpio12
- if:
condition:
switch.is_off: relay
then:
- switch.turn_on: yellow
- switch.turn_off: blue
- if:
condition:
switch.is_on: relay
then:
- switch.turn_on: blue
- switch.turn_off: yellow
sensor:
- platform: hlw8012
model: BL0937
sel_pin:
number: 16
inverted: true
cf_pin: 4
cf1_pin: 5
voltage_divider: 1314
current:
name: "HLW8012 Current"
voltage:
name: "HLW8012 Voltage"
power:
name: "HLW8012 Power"
energy:
name: "HLW8012 Energy"
update_interval: 60s
|