Please help with this template

I copied this code from another post and modified it to run correctly in Developer Tools → Template. It returns true or false depending upon the last triggered time is greater than or less than 21600.

But, in the automation itself, when I create a Condition → Template and paste this exact line in Value template box and press the Test button, it throws an error. The purpose of this condition is to prevent automation from running if it has been run in the past 6 hours.

{{(as_timestamp(now())) - as_timestamp(state_attr("automation.reboot_router_on_malfunction","last_triggered")) | default(0) | int > 21600}}

I have tried various combinations of whitespaces, single quotes vs double quotes, tried pasting it in YAML directly: nothing works in Value template. What am I doing wrong?

Thanks…

Currently, there’s a bug with the Test button (it can’t evaluate template conditions properly).

You have confirmed it works correctly in the Template Editor and that’s more than sufficient to confirm it’s valid.


If you are interested, here’s another way to construct the template.

{{ now() - state_attr("automation.reboot_router_on_malfunction","last_triggered") | default(now(), true) > timedelta(hours=6) }}

Thank you so much…!!!

1 Like