For all our lights I have automations that turn them off after it has been on for a certain length of time with no motion in the room.
HOWEVER in case my kids were simply really still for an hour, say reading a book, I have another automation that will trigger on motion IF the light is off and IF the automatic off automation ran within the last 60 seconds - this way if their light turns off and they were about to go turn it back on it instantly turns back on. This is the condition I wrote for checking if the turn off automation has run within 60 seconds:
Probably because automation.night_time has never been triggered so it has no last_triggered attribute. As a result, state_attr() reports None and that’s what the error message is complaining about (cannot subtract None from the value of now()).
The error will go away after the automation has triggered and acquired a last_triggered attribute.
FWIW, it’s possible to mitigate this, by adding more filters to the template, but I chose not to do that here given that the issue only affects a new, un-triggered automation. If you’re interested, refer to the example in this post to learn how to use the default filter to provide a default value for the case where the automation has never been triggered yet.
Ah! Would you have any thoughts on, this? Surely if it’s used as a condition it will never trigger?
Used to work on previous versions of HA but not the most recent.
Not sure if this meets your requirements but, if used in a Template Condition, it checks if the last time an automation triggered was over 12 hours ago.
Really appreciate the fast response. I added it in a template condition but changed hours to minutes, I’m guessing that’s what broke it. Basically I’m trying to make garage door close when the Bluetooth beacon in my car is detected as “away”. It works, but I don’t want it to do it when I get home, only when I leave, so I’m trying to make it only close the door if the automation for it to open when the Bluetooth beacon is detected wasn’t ran in the last few minutes.
Alternatively, if I could get it to close only if home assistant did not open it.
Again I really appreciate the response and any input.
Hi all! I’d like to do exactly the same but as a condition in the actions. However the delta is always zero because last triggered is “now” in the actions of the automation itself. Any solution?
The idea is to do something special if someone is ringing again my doorbell in the same minute.
Here’s a reduced test case. If I hit run, a minute appart or not, it does not matter, the same path is always taken. I guess the last_triggered is taken as the triggering happening now, so the time delta is always 0. But I’m not sure how to verify this theory.
I have tested a similar version of this automation, using a Philips Hue Dimmer Switch to serve as the remote control, and confirmed it works.
The trigger variable named is_repeated reports true or false depending on whether the value of last_triggered was less than a minute ago.
The is_repeated variable is used in the service call to determine which entity should be toggled. It uses the homeassistant.toggle service because it works for both lights and switches.