本帖最后由 jyz_0501 于 2019-8-30 01:04 编辑
以前利用绿米人体感应器 做开关灯的操作 一直是写两个自动化, 一个是开灯 一个是关灯,这样房间多了,光自动开关灯就要双倍的。
实在是有些臃肿
强迫症的我决定换掉它。
版本一:(以前的版本)
- id: 4d9ac4ca4fb94648bf0ccbec2e450343
alias: 自动开次卧灯
trigger:
- entity_id: binary_sensor.motion_sensor_158d0002b70e92
from: 'off'
platform: state
to: 'on'
condition:
- condition: state
entity_id: light.guestroomlight
state: 'off'
- below: '10'
condition: numeric_state
entity_id: sensor.illumination_158d0002b70e92
action:
- data:
entity_id: light.guestroomlight
entity_id: light.guestroomlight
service: light.turn_on
- id: '15595744010686'
alias: 自动关次卧灯
trigger:
- entity_id: binary_sensor.motion_sensor_158d0002b70e92
from: 'on'
platform: state
to: 'off'
condition:
- condition: state
entity_id: light.guestroomlight
state: 'on'
action:
- data:
entity_id: light.guestroomlight
service: light.turn_off
版本二:(优化后)
- id: '1567093370829'
alias: 自动开关玄关灯
trigger:
entity_id: binary_sensor.motion_sensor_158d000237a917
from: 'off'
platform: state
to: 'on'
condition:
- condition: state
entity_id: switch.wall_switch_left_158d0002425dcb
state: 'off'
action:
- data:
entity_id: switch.wall_switch_left_158d0002425dcb
service: switch.turn_on
- timeout: 0:10:00
wait_template: '{{is_state("binary_sensor.motion_sensor_158d000237a917","off")}}'
- data:
entity_id: switch.wall_switch_left_158d0002425dcb
service: switch.turn_off
版本三:(再次优化)
event触发时间比state的周期要短,state是120秒,event是60秒
- id: '1567093370829'
alias: 自动开关玄关灯
trigger:
- event_data:
entity_id: binary_sensor.motion_sensor_158d000237a917
event_type: xiaomi_aqara.motion
platform: event
condition:
- condition: state
entity_id: switch.wall_switch_left_158d0002425dcb
state: 'off'
action:
- data:
entity_id: switch.wall_switch_left_158d0002425dcb
service: switch.turn_on
- timeout: 0:10:00
wait_template: '{{is_state("binary_sensor.motion_sensor_158d000237a917","off")}}'
- data:
entity_id: switch.wall_switch_left_158d0002425dcb
service: switch.turn_off
|