Template - default value missing

Hello,
I’m getting the following error after upgrading to 2021.10:

Template warning: 'timestamp_local' got invalid input 'unavailable' when rendering template '{{ (as_timestamp(states("sensor.cert_expiry_timestamp")|timestamp_local))|timestamp_custom("%B %d, %Y") }}' but no default was specified. Currently 'timestamp_local' will return 'unavailable', however this template will fail to render in Home Assistant core 2021.12

The raw value of the “sensor.cert_expiry_timestamp” entity is
20121-11-19T15:00:07+00:00

The value after the template:

value_template: '{{ (as_timestamp(states("sensor.cert_expiry_timestamp")|timestamp_local))|timestamp_custom("%B %d, %Y") }}'

is
November 19, 2021

Where in the template do I insert the default value and what should that value be?
Thanks.

timestamp_local(0)
which will mean that if there is no timestamp passed to it, it will use 0 seconds past midnight Jan 1st 1970.

Adding the (0) after timestamp_local causes the result to be “Unknown”. I verified this in the Developer Tools > Template tester and got the result as “None”

Removing it, results in the correct value “November 19, 2021”

Any other ideas?

Try…

value_template: '{{ (as_timestamp(states("sensor.cert_expiry_timestamp"), as_timestamp(now())|timestamp_local))|timestamp_custom("%B %d, %Y") }}'

Thanks, but that didn’t solve the problem. The error message now is:

Template warning: 'timestamp_local' got invalid input '20121-11-19T15:00:07+00:00' when rendering template '{{ (as_timestamp(states("sensor.cert_expiry_timestamp")|timestamp_local))|timestamp_custom("%B %d, %Y") }}' but no default was specified. Currently 'timestamp_local' will return 'unavailable', however this template will fail to render in Home Assistant core 2021.12

The rendered value is correct “November 19, 2021” but the error message mentions that the default value is missing.

What output gives this?


value_template: '{{ (as_timestamp(states("sensor.cert_expiry_timestamp"), 0)) |timestamp_custom("%B %d, %Y") }}'

EDIT: Corrected typo.

1 Like

The certificate expires in the year 20121?

18100 years from now?

This worked ! After I added a “)” after “0)” to fix a syntax error and restarted HA, there is not a “no default is specified” error and the correct value is rendered. Thanks!

@123Taras LOL…That was a typo on my part. It is 2021 not 20121. Thanks for pointing it out.

Oups, sorry, to many brackets to count for my weak eyes :dizzy_face:‍:dizzy: