I want to at midnight check if there has been no motion detected in the downstairs of the house within the last half hour (say) and if that’s true, arm the HASS alarm component.
I’ve got this working in code.
But what if there HAS been movement within the last half hour? It would indicate maybe that it’s Christmas Eve and we’re very unusually still up roaming about wrapping presents and hanging stockings. I’m just using Christmas Eve as an example that this is a real world possibility.
How, without loads of almost identical automations (which would only vary because the trigger time would keep incrementing) create a postponement until the automation passes all the conditions? Would I create a loop with a timer?
EDIT: I guess what I’m really asking (just realised) is there an ELSE action you can use with automations?
The automation you created sounds fine, I wouldn’t change it.
I would suggest a separate automation that runs after midnight and checks if the house is armed. 99% of the time it will be, because your first automation will already have taken care of it. This second automation takes care of the other 1% of the time.
The big question is: When should this second automation run? You could have it run once, say at 1:00 AM (it also checks if there’s no motion before arming). Only problem is it won’t arm if there’s still motion. Alternately, you could make it run every 15 minutes and a condition would limit its hours operation (midnight to 6:00AM?). That’ll definitely arm it (eventually, unless you party till dawn).
Caveat: what I dislike about this kind of timer-based automation is how easily it can become an inconvenience. It’s after midnight, the house is armed and you disarm it because you have to do something. It’s late, you’re bleary-eyed and fuzzy-headed, the task is mundane or one-of-a-kind (leave something out on the front porch to be picked up by a friend … or watching a meteor shower) and you take more than 15 minutes to do it. You completely forget the second automation will dutifully re-arm the house (no motion inside the house) … and you re-enter the house and unwittingly cause a false alarm.
Sounds like what you’re looking for is to arm the alarm:
A) at midnight if there has been no motion for at least one hour, or
B) when there has been no motion for some amount of time (1/2 hr, 1 hr, …?) and it is after midnight and before some other time.
Does that sound right?
I don’t use the alarm component, so not really familiar with it, and you didn’t say exactly which entity or entities you use for motion detection and what their states are for motion and not, but maybe something along these lines might work for you:
automation:
- alias: Arm alarm at midnight if no motion for a while
trigger:
platform: time
at: '00:00:00'
condition:
condition: state
entity_id: binary_sensor.motion
state: 'off'
for:
hours: 1
action:
# Add service call to arm alarm
- alias: Arm alarm when no motion and after midnight
trigger:
platform: state
entity_id: binary_sensor.motion
to: 'off'
for:
hours: 1
condition:
condition: time
before: '05:00:00'
action:
# Add service call to arm alarm
Note the time condition with only before specified implies after midnight as well.