Template as trigger not working

Hi,

I’m trying to trigger a WLED device using the automation below.

I’ve verified that the boolean state of the template correctly transitions from false to true (and back again) according to the status of Zwift (sensor.zwift_online_xxxxxx) via the developer template test area as well as in the automation template debugger itself.
Running the automation action manually also works as expected.

Despite this I cannot get the automation to trigger for some reason. Can anyone kindly help?

I have tried restarting HA also but this has had no effect. I’m on HA Core version 2026.2.2 on the latest HA OS 17.1.

The automation was set-up via the UI but I’ve copied the YAML out unmodified to paste here. Is there any reason this shouldn’t trigger?

alias: Zwift HR Automation (Zwift Online)
description: ""
triggers:
  - trigger: template
    value_template: |-
      {% if  states('sensor.zwift_online_xxxxxx') == "True" %}
         # Zwift online default
         true 
         {% else %}
         false
      {% endif %}  
conditions: []
actions:
  - device_id: 241e197ed1502711a1191b9b9c43ec79
    domain: select
    entity_id: ae6d3860b8bcf144cc6f2afce9ff4367
    type: select_option
    option: Default
mode: single

Many thanks,

Jason

Others will check, but I think this simplifies things a but…
Your original I think was just missing the .state if I am correct.
However all the template wants is true or false, and your original sensor you are stating gives you that. (Are you sure that’s not a binary sensor?)

    value_template: |-
      {% states('sensor.zwift_online_xxxxxx.state') %}
alias: Zwift HR Automation (Zwift Online)
description: ""
triggers:
  - trigger: template
    value_template: |-
      {{ states('sensor.zwift_online_xxxxxx') | bool(false) }}
conditions: []
actions:
  - device_id: 241e197ed1502711a1191b9b9c43ec79
    domain: select
    entity_id: ae6d3860b8bcf144cc6f2afce9ff4367
    type: select_option
    option: Default
mode: single

You may already know this but a Template Trigger will trigger only when the template’s result changes from false to true.

1 Like

Thanks both! I can confirm that the script Taras posted worked correctly and triggered when Zwift was online.

I’m a little confused why that works and my own script doesn’t since they both evaluate to either true or false. Is it because my script is missing the bool() part?

Many thanks,

Jason

Your version includes a YAML-style comment in the middle of a Jinja2 template (specifically where it’s supposed to return true). Jinja2 comments use different syntax so that entire line became part of what was supposed to be a logical true response (rendering it invalid).

1 Like

Oh, that’s interesting! Thanks for that info. Very helpful! Hopefully I can get all the other triggers working now.
Best wishes,
Jason

1 Like