Intermittent automation template error

'{{ (as_timestamp(now()) - as_timestamp(states.automation.doorbell.attributes.last_triggered | default(0)) | int > 10)}}'

returns:

ValueError: Template error: as_timestamp got invalid input 'None' when rendering template ''{{ (as_timestamp(now()) - as_timestamp(states.automation.doorbell.attributes.last_triggered | default(0)) | int > 10)}}'' but no default was specified

I am trying to debug an automation which isn’t firing. The first time I put the above into the jina template engine it returned true, but, suspicuous, I put it in again and the second time with no changes it returned the above?!

When you use as_timestamp() and it’s unable to convert the value to a timestamp, it will report whatever default value you provided. However, you didn’t provide a default value for as_timestamp() and that’s why it reported a template error.

For more information, refer to petro’s helpful post explaining which functions/filters require a default value.

In addition, it’s preferable to use state_attr() to get an attribute’s value. Refer to the Warning posted in the Templating section of the documentation.