Help with templating and automation - always false

I see your problem. You aren’t understanding the differences between YAML and the templating engine and you’re combining single line yaml and multi-line yaml syntax.

When you use some_field: >-, you’re telling the yaml that all indented lines below this belong to this some_field.

When you use some_field: "..." you’re telling the yaml that everything between the quotation marks belongs to this field and is a string. Yaml will naturally remove the quotation marks because it’s not part of the value.

When you combine the 2, your result will always be wrapped in quotes. And "True" does not resolve to True and "False" does not resolve to False.

We would have seen this sooner if you posted your entire yaml, i.e. the field and the template.

Either way, I can see that in your condition.

If you’re going to use multiline notation for your templates, remove the exterior quotes.

condition: template
value_template: >-
  {{ (now()|as_timestamp - state_attr('automation.fan_on_upstairs','last_triggered')|as_timestamp) > 40000 }}

OR keep the quotes and remove the multi-line notation

condition: template
value_template: "{{ (now()|as_timestamp - state_attr('automation.fan_on_upstairs','last_triggered')|as_timestamp) > 40000 }}"

See this thread for understanding the differences between yaml and jinja.

1 Like