How do I troubleshoot my automation not firing automatically but it works manually

I’m looking for some help with an automation that does not fire. I am relatively new to using a template to make an automation fire so I thought I would start with something simple. I have two boolean input switches, one for me and one for my wife. When I leave or she leaves, the switch turns off. When I or she come home, the switch turns on.

My goal is: when both my wife and I are away from home both of our switches will be off and the indoor cameras will turn on. I wrote the automation. I tested the automation by manually running it and it turns the cameras off or on as expected. I turn on or off the switches to simulate us being home or away but the automation never fires. I put the template into ‘Developer Tools → Template the results will show “true” or “false” as expected.

So why is my automation not firing?

Please note that I do not wish to use home or zones for presence detection. This automation is being run for our vacation condo and my HA is physically at my primary residence.

YAML for the automation to turn on cameras when both of us are not home

alias: PV everyone away turn on camera
description: ""
triggers:
  - trigger: template
    value_template: >-
      "{{ is_state('input_boolean.pv_ds_home', 'off') and
      is_state('input_boolean.pv_sc_home', 'off') }}"
conditions: []
actions:
  - type: turn_on
    device_id: d1ceb8ec8d1842287344f323f902226c
    entity_id: d2ce8f892e0a1861d39dfef9cc9a41fd
    domain: switch
  - type: turn_on
    device_id: b888bbd1a4ee2876166b6f121905e1f6
    entity_id: 07c611818484404620edd9703529f77c
    domain: switch
  - type: turn_on
    device_id: b4d6f5a549e2eeb42a59084fb3f0d52f
    entity_id: 931bc109a014824d3104cd85d918083a
    domain: switch
mode: single

YAML for the automation to turn off cameras when either of us are home

alias: PV off when anyone home
description: ""
triggers:
  - trigger: template
    value_template: >-
      "{{ is_state('input_boolean.pv_ds_home', 'on') or
      is_state('input_boolean.pv_sc_home', 'on') }}"
conditions: []
actions:
  - type: turn_off
    device_id: d1ceb8ec8d1842287344f323f902226c
    entity_id: d2ce8f892e0a1861d39dfef9cc9a41fd
    domain: switch
  - type: turn_off
    device_id: b888bbd1a4ee2876166b6f121905e1f6
    entity_id: 07c611818484404620edd9703529f77c
    domain: switch
  - type: turn_off
    device_id: b4d6f5a549e2eeb42a59084fb3f0d52f
    entity_id: 931bc109a014824d3104cd85d918083a
    domain: switch
mode: single

I appreciate any help I receive here in advance.

A Template Trigger will fire when the result of its template changes from false to true.

That means your Template Trigger will fire when one of the two Input Booleans it monitors changes its state from on to off.

For example, if the first Input Boolean is currently off and the second one is on, the Template Trigger will fire when the second Input Boolean’s state changes to off.

If they’re both currently off, the Template Trigger will not fire. One of them must first change to on and then to off to cause the Template Trigger to fire.


Manually running an automation simply executes the actions, it doesn’t test the trigger.

2 comments…

  1. As 123 said, Do these ever go to on, so that they can be triggered when they change to off? Automations #1: trigger only fires when it changes from not true to true

  2. Why and how to avoid device_ids in automations and scripts

You need to remove the double quotes if you are using a multi-line quote indicator like >-.

As you have it, the template always renders as the string “{{ is_state(‘input_boolean.pv_ds_home’, ‘on’) or is_state(‘input_boolean.pv_sc_home’, ‘on’) }}”; which is always treated as true. It will never fired, because it will never change from false to true.

The correct configuration is:

  - trigger: template
    value_template: >-
      {{ is_state('input_boolean.pv_ds_home', 'on') or
      is_state('input_boolean.pv_sc_home', 'on') }}

Thank you Didgeridrew. It was the double quotes.