本帖最后由 dizherui 于 2021-5-15 12:00 编辑
求大神指教,目前需要两组形式:
1、开关打开之后开始循环,直至开关被关闭后停止
2、开关打开之后开始循环,循环10次后自动关闭
想在ESPHOME内部实现,我该怎么去写?网上没搜索到示例 求大神帮忙
目前我是用template做的虚拟开关,控制script,做开关每一组灯
switch:
- platform: template
name: "W1"
icon: "mdi:gate"
optimistic: true
on_turn_on:
then:
- script.execute: sp_turn_on
- logger.log: "全开灯"
on_turn_off:
- script.execute: sp_turn_off
- logger.log: "全闭灯"
script:
- id: sp_turn_on
mode: single
then:
- light.turn_on:
id: relay0
brightness: 100%
transition_length: 0s
- light.turn_on:
id: relay1
brightness: 100%
transition_length: 0s
- id: sp_turn_off
mode: single
then:
- light.turn_off:
id: relay0
transition_length: 0s
- light.turn_off:
id: relay1
transition_length: 0s
目前简单实现了虚拟开关打开,无限循环开关灯,直到虚拟开关被关闭,停止
- platform: template
name: "Warning"
id: Warning
#:无限循环
icon: "mdi:gate"
optimistic: true
on_turn_off:
- logger.log: "危险!警示灯!"
- light.turn_off: Warning_light
- light.turn_off: Warning_light1
on_turn_on:
while:
condition:
switch.is_on: Warning
then:
- logger.log: "危险!警示灯!"
- light.turn_on: Warning_light
- delay: 1s
- light.turn_off: Warning_light
- light.turn_on: Warning_light1
- delay: 1s
- light.turn_off: Warning_light1
|