Adding 2 very simple automations for office lights. One to turn them ON and one to turn them OFF. Turning on works fine, triggered by door open switch or motion detected.
However, I am struggling to get the OFF one to work. It is fine just using the motion not detected for X mins but ideally I wanted to AND this with door closed. I therefore added a condition that the door is closed but the automation does not turn off the lights at all. Am I right in thinking that as the door needs to be closed BEFORE the automation can run then the transition from detected to clear isn’t detected and therefore it fails? If so, what is the best way around it. I know I could just use a blueprint but want to try and learn YAML etc a bit.
Post your yaml if you want some help as its difficult to guess what you have tried. My guess though is that the door closing is not a condition but a trigger to turn off the light the condition is motion not detected and door closed.
the door needs to be closed before the automation is triggered by the motion sensor.
a way to use the door as a trigger is to add a wait_for_trigger in your actions.
Conditions are notWaits. Conditions check the status at that moment and either pass or fail. If you need to track a sequence of events, you need to use either a Wait for Trigger or Wait template.
If the door may or may not be closed within your 10 seconds of no motion, use a Wait template. If the door closing should always happen after the motion has been stopped for 10 seconds, use a Wait for Trigger.
Understand both bits of code above and understand having a long delay in an Automation can be problematic. However, to expand on the requirement……
It is an office, so on entering the lights will turn on based on the door opening OR motion being detected. I would then close the door (air con on), keeping the lights on. I could be potentially in there for hours working with the lights on. At the end of the day I would require the lights to switch off based on no movement and door closed.
you could also combine the two automations (on and off).
in this automation, the lights turn on when the door or the motion sensor changes state.
after 10 seconds it will check if there is still someone in the room to keep the lights on, if not they turn off.
notice the mode is “restart” wich means the automation will restart when a change is detected, the 10 second wait is then reset.