本帖最后由 dscao 于 2022-12-18 23:25 编辑
alias: 客厅灯与筒灯面板互开互关
description: ""
trigger:
- platform: state
entity_id:
- light.ke_ting_deng_kai_guan
- switch.0x00124b0014d0231b_channel_3
to: "on"
from: "off"
- platform: state
entity_id:
- light.ke_ting_deng_kai_guan
- switch.0x00124b0014d0231b_channel_3
from: "on"
to: "off"
condition: []
action:
- choose:
- conditions:
- condition: template
value_template: "{{ trigger.to_state.state == "off" }}"
sequence:
- service: light.turn_off
data: {}
target:
entity_id:
- light.ke_ting_deng_kai_guan
- service: switch.turn_off
data: {}
target:
entity_id: switch.0x00124b0014d0231b_channel_3
- conditions:
- condition: template
value_template: "{{ trigger.to_state.state == "on" }}"
sequence:
- service: light.turn_on
data: {}
target:
entity_id:
- light.ke_ting_deng_kai_guan
- service: switch.turn_on
data: {}
target:
entity_id: switch.0x00124b0014d0231b_channel_3
default: []
mode: restart
复制代码
今天看微信中提到这个,搜索找到了这里,看到也有些年份了,另外我使用的类似但有些不同。也发出来分享一下,不是很简洁,请勿拍砖啊。
现在新版在UI中配置自动化非常方便 ,主要就是开关和灯两个类型的实体需要同步控制的就加入进来,有多个少个需要同步就加多个进来。所谓同步控制实际上就是 一个开就全部开,一个关就全部关。所以可以这样操作。
为什么这里触发条件写了两个, on to off 和 off to on,类似的我都会写两条,防止有些情况下从不可用状态回到开或关状态导致触发。
因为用的是zigbee墙壁开关,这里的开关和灯都有状态反馈,两个开关的面板上都有指示灯。
如果是两个开关相反的互开关,比如我的太阳能热水器和燃气热水器,只要一个开另一个就关,可以两个同时关,但不允许同时开。写法会复杂一些,而且操作上不能快速连续开关,按一次要等几秒等自动化完成再按下一次,否则可能导致自动连续不停的切换。
alias: 燃气热水器与太阳能互控
description: ""
trigger:
- platform: state
entity_id:
- switch.28d1272b27be_outlet
- switch.28d12736597a_outlet
to: "on"
condition: []
action:
- choose:
- conditions:
- condition: template
value_template: "{{ trigger.entity_id == "switch.28d1272b27be_outlet" }}"
sequence:
- service: switch.turn_off
data: {}
target:
entity_id: switch.28d12736597a_outlet
- conditions:
- condition: template
value_template: "{{ trigger.entity_id == "switch.28d12736597a_outlet" }}"
sequence:
- service: switch.turn_off
data: {}
target:
entity_id: switch.28d1272b27be_outlet
default: []
mode: single
复制代码
这个代码从UI中复制出来的,也可以复制回去。就是UI的自动化中创建一个自动化,右上角点击“以YAML编辑”,复制进去,再点击“以图形界面编辑”,之后就很方便修改了。