Hi everyone, I hope someone can help me, because I have been at this one for a while …
I am trying to create an automation which will set my home alarm to “armed_away” when no phones are at home AND no motion detected on my PIRs for 30 mins.
I know the trigger and actions work fine - the issue is with the template I am using in the condition, but unsure if its a logic or syntax issue.
Any help would be really appreciated.
- id: '1556714123746'
alias: '[Alarm]: Arm Away when no phones at home and no movement at home for 30
min'
trigger:
- entity_id: group.all_pirs
for: 00:30:00
platform: state
to: 'off'
condition:
- condition: template
value_template: '{% if is_state(''group.all_phones'', ''home'')
%}false{% endif %}'
action:
- data:
code: '1111' # this is not my actual alarm code
entity_id: alarm_control_panel.home
service: alarm_control_panel.alarm_arm_away
- data:
message: '[Alarm]: Alarm was automatically armed_away because no motion detected
and no phones at home for 30 min at {{ now().strftime("%I:%M:%S%p") }} on
{{ now().strftime("%B %e, %Y.") }}'
service: persistent_notification.create
Is it possible that when the last person leaves all the PIRs have already been off for 30 minutes? If so, the alarm will not get armed (until at least one PIR senses motion and then they all don’t for another 30 minutes.) This is because you only have a trigger based on the PIRs, but none based on the phones.
You might want to consider this:
trigger:
- entity_id: group.all_pirs
for: 00:30:00
platform: state
to: 'off'
- entity_id: group.all_phones
platform: state
from: home
condition:
- condition: state
entity_id: group.all_pirs
for: 00:30:00
state: 'off'
- condition: template
value_template: "{{ not is_state('group.all_phones', 'home') }}"
Thanks Phil. This makes sense. I am using Life360 for the phone presence, so I guess it could take a while to update that after last motion sensed. I will try your suggestion a bit later and let you know.