i have 3 sensors, motion + presence + door contact. if any of their states change to Home, turn the Light on. if 3 sensors’ states change to Away and stay away for 10 minutes, turn Lights off.
strange that the Presence sensor is in Home state but Light still turn off. any idea if my yml code is wrong?
alias: auto living room lights on
description: ""
trigger:
- platform: state
entity_id:
- binary_sensor.besense_home_security_motion_detection
- binary_sensor.presence_living_room_presence
- binary_sensor.door_living_room_contact
to: "on"
condition: []
action:
- service: light.turn_on
data: {}
target:
entity_id: light.light_living_room
- wait_for_trigger:
- platform: template
value_template: >-
{% set motion =
expand(['binary_sensor.besense_home_security_motion_detection','binary_sensor.presence_living_room_presence','binary_sensor.door_living_room_contact'])
|selectattr('state', 'eq', 'off') |sort(attribute='last_changed',
reverse=true) %} {{ now() - motion[0].last_changed >
timedelta(minutes=10) if motion != [] else false }}
for:
hours: 0
minutes: 10
seconds: 0
- service: light.turn_off
data: {}
target:
entity_id: light.light_living_room
mode: single