一開始接觸 ha 時, 因為 node-red 比較視覺化, 所以就持續用了幾一陣子.
而 automation 則是最近才開始玩, 這支 automation 才剛完成, 所以想說拿上來跟大家分享,
順便看有沒有大師, 可以幫忙看看有沒有可以再改進的地方.
使用的感應器:
sonoff rf 開窗感應器(gate15inside)...只能感應開, 沒有関....手上既有的, 將就用.
aqara 人体移動感應器(binary_sensor.motion_aq2).
tuya 牆壁開關, 控制燈(switch.restroom_sunlight)
進入衛生間:
離開衛生間
- 開門时, 如果偵測室內無人, 則関燈.
- 把人体感應器的狀態設為沒人, 以免立馬有人再進衛生間時產生誤判.
- alias: restroom turn on light before enter
trigger:
- platform: event
event_type: sonoff.remote
event_data:
name: gate15inside
condition:
condition: and
conditions:
- condition: state
entity_id: binary_sensor.motion_aq2
state: "off"
action:
- service: switch.turn_on
target:
entity_id: switch.restroom_sunlight
- alias: restroom turn off light while leave
trigger:
- platform: event
event_type: sonoff.remote
event_data:
name: gate15inside
condition:
condition: and
conditions:
- condition: state
entity_id: binary_sensor.motion_aq2
state: "on"
action:
- service: switch.turn_off
target:
entity_id: switch.restroom_sunlight
- delay: "00:00:02"
- service: python_script.set_state
data_template:
entity_id: binary_sensor.motion_aq2
state: off
|