I’m trying to arm in away mode my house when there is no motion for 30 mins.
I create a motion group and an automatisation. If I use the field ‘for’ to add a 30 mins delay in the trigger, the automatisations will never run. If I’m not using the field for, the automatisation will kick in right away when there is no motion. I’m missing something?
alias: Security - Auto Arm
description: ''
trigger:
- platform: state
entity_id: group.motion
to: 'off'
for:
hours: 00
minutes: 30
seconds: 00
condition:
- condition: not
conditions:
- condition: zone
entity_id: person.xxx
zone: zone.home
- condition: time
before: '16:00:00'
after: '08:00:00'
- condition: device
device_id: 365270f2ff76a2f21ac90d72dd7b5e7e
domain: alarm_control_panel
entity_id: alarm_control_panel.aqara_hub_m1s_597b
type: is_disarmed
action:
- device_id: 365270f2ff76a2f21ac90d72dd7b5e7e
domain: alarm_control_panel
entity_id: alarm_control_panel.aqara_hub_m1s_597b
type: arm_away
- service: notify.mobile_app_pixel_6
data:
title: Home Srcurity
message: Alarm system arm in away mode (30 mins no motion)
mode: single
It’s not a simple delay. It requires group.motion to remain off for at least 30 minutes in order to trigger. In other words, it doesn’t merely wait 30 minutes, like a delay would do, it requires the state value to remain unchanged for 30 minutes. Any motion detected during the 30-minute countdown will reset the countdown.
Your automation is designed to trigger when:
no motion is detected for 30 minutes
and the following conditions are met:
person.xxx is not home
current time is between the hours of 08:00 and 16:00
alarm panel is disarmed
Check the automation’s trace which should be created whenever the State Trigger occurs. Also check the history of group.motion and confirm its state remains off for at least 30 minutes.
If it works without the for but not with it then it really sounds like group.motion is never able to maintain a state of off for 30 minutes. As an experiment, set for to a shorter time period. Also, how are you testing this automation?
I assume you are aware that whenever you restart Home Assistant, execute Reload Automations, or save a new/modified automation in the Automation Editor, all automations are reloaded and any that use for are canceled and restarted (i.e. the 30-minute countdown is canceled and reset).
The results of your experiments continue to show that the entity’s state is capable of remaining off for up to 5 minutes, just not for 30 minutes. It confirms the State Trigger can work correctly but that the entity’s state fails to remain unchanged for as long as 30 minutes. I realize you say it does remain off for that long but the trigger’s behavior disagrees.
Try progressively longer time periods (10, 15, 20, 25), maybe it will reveal the actual limit isn’t 30 but something else. That value might serve as a clue to what’s going on.
As an alternative, if you know how to compose SQL queries, you can use the SQLite Web Add-on to examine the entity’s detailed history in the database. If there’s even a sub-second change from off to on to off it will be visible in the database.