I have a nightstand light that I am trying to automate by a detection from the motion sensor when I go up stairs (which triggers the motion sensor) and the time is 10 PM to 11:59 PM.
I have this working, but I’m looking to make sure it only triggers once. If I lay down and turn the light off and the cats come up the stairs within the time window, they trigger the motion sensor which turns the nightstand back on. Is there a way to trigger an automation just once a day? IE After I get in bed and turn it off manually I dont want the motion sensor to turn it on again until the next night.
That’s a common request (limit an automation to execute just once a day) and the simplest way to do it is with a Template Condition that checks the automation’s last_triggered attribute.
If the value is before the start of the day that means it has not executed today (and is allowed to execute its actions).
If the value is anytime today, that means it has already executed once (and is not allowed to execute again today).
For a new automation that has never been triggered, the value of its last_triggered attribute is null. Therefore the following template will attempt to compare null to a datetime object and result in an error.
{{ this.attributes.last_triggered < today_at() }}
The example I posted above guards against that situation by using the default filter to provide a datetime object whose value is older than today.