I’m struggling to identify the issue with the automation below. I’m using a mmwave presence sensor to detect occupancy in the bathroom, the lights should turn on when detected (depending on time of day) and then turn off only after occupancy ends +5mins. However at the moment they just turn off regardless after the 5mins is up. I extracted the original code from the motion lights blueprint and turned it into an automation as I wanted to extend the options available in it.
Any pointers gratefully received!
alias: Presence Lights - Bathroom Mirror + Lights (5mins / Conditional)
description: ""
trigger:
- platform: state
entity_id:
- binary_sensor.presence_sensor_main_bathroom_presence
to: "on"
condition: []
action:
- alias: Turn on the light
service: light.turn_on
target:
entity_id: light.main_bathroom_mirror
data: {}
- if:
- condition: time
after: "07:00:00"
before: "22:00:00"
then:
- service: light.turn_on
metadata: {}
data: {}
target:
entity_id: light.main_bathroom_lights
- alias: Wait until there is no motion from device
wait_for_trigger:
- platform: state
entity_id:
- binary_sensor.presence_sensor_main_bathroom_presence
from: "on"
to: "off"
timeout:
hours: 0
minutes: 0
seconds: 0
milliseconds: 0
- alias: Wait the number of seconds that has been set
delay:
hours: 0
minutes: 5
seconds: 0
milliseconds: 0
- alias: Turn off the light
service: light.turn_off
target:
entity_id:
- light.main_bathroom_mirror
- light.main_bathroom_lights
data: {}
mode: restart
max_exceeded: silent
Your wait is timing out immediately because you have specified a timeout of 0 seconds… delete the timeout completely and save the automation. Sometimes this happens due to a UI glitch if you simply place your cursor in any of the timeout unit fields.
This means I can also put the timers on the dashboard. So I can see how much time is left, and if I need to - manually end the timer, which will trigger the timer finished event and turn the lights off.
Not sure it is a risk, but it’s a hack, because you rely on an implicit safeguard mechanism to implement business logic (the fact that presence can be detected while waiting to turn the lights off).