Automation trigger not fired, how to troubleshoot?

Dear community:

I have the below automation, basically it turns on indoor camera 30 minutes after last person leaves home, and turn off camera when anybody is home. The turn_off trigger seems to work without issue however the turn_on trigger is not fired when both users are not at home for more than 30 minutes. There is no sign in log to indicate any issue, and also according to the logbook there was no changed or unknown value during the 30 minutes.
It’s first time I use a template trigger with “for”, is it supported in this way? Thank you for your help!

alias: Away/Home Indoor Camera ON/OFF
description: ""
triggers:
  - value_template: >
      {{ is_state('device_tracker.xxxxx_iphone', 'not_home') and
      is_state('device_tracker.xxxx_iphone', 'not_home') }}
    for:
      minutes: 30
    id: turn_on
    trigger: template
  - entity_id:
      - device_tracker.xxxx_iphone
      - device_tracker.xxxxx_iphone
    to: home
    id: turn_off
    trigger: state
conditions: []
actions:
  - target:
      entity_id: switch.indoor_cameras
    action: switch.{{ trigger.id }}
mode: queued

What does TRACES show?

Nothing, it’s not triggered at all until somebody goes home and it was first triggered there.
Could it be some gramma mistake? I’m quite new to HA, and still don’t understand what to use after the name of attribute:

  • “|”
  • “|>”
  • “>”
  • “>-”

When using non-stationary device trackers like your phones, the value not_home really means “not in any named zone”. If you have created zones other than home, it would be better to structure your template using not instead of specifying the value not_home. That way it will still fire if one or both people reach named zones within the 30 minutes.

trigger: template
value_template: >
  {{ not is_state('device_tracker.xxxxx_iphone', 'home') and not
  is_state('device_tracker.xxxx_iphone', 'home') }}
for:
  minutes: 30
id: turn_on

For most cases an even better option is to use a Numeric State trigger based on the zone entity, whose state is the count of person entities in that zone:

trigger: numeric_state
below: 1
entity_id: zone.home
for: "00:30:00"
1 Like

Would it not be far easier to trigger on home zone state changing to 0?

@Arh , I think the GUI only allows for Below and Above a value for zone.home. That may be why there is no equals 0.

You can use a State trigger, but you would need to guard against false positives on restart.

trigger: state
to: 0
not_from: unavailable
entity_id: zone.home
for: "00:30:00"

In this case it probably wouldn’t be an issue to leave out the not_from, but in other circumstances it could be critical. Using a the Numeric State trigger avoids that, and it is the better choice for the inverse trigger for people arriving home.

That’s something new I didn’t know thank you for the suggestion. I assume the number means number for devices in home zone? I checked my log and looks like it’s always either 1 or 0, never turns to 2 :joy:

Edit: ok I know why now. My wife doesn’t have HA account and uses HomeKit mainly, her phone is tracked but not linked to a person.