Template errors (no default)

I’m also seeing some warnings on some templates;

{{ (( as_timestamp(strptime(“2019-02-14” , “%Y-%m-%dT%H:%M:%S”)) - as_timestamp(now()) )/ (3600*24)) | round(0) }}

Tried some things to fix it, but can’t find it… could somebody help me how to get rid of these warnings?

The warning I see is;

  • Template warning: ‘strptime’ got invalid input ‘2019-02-14’ when rendering template ‘{{ (( as_timestamp(strptime(“2019-02-14” , “%Y-%m-%dT%H:%M:%S”)) - as_timestamp(now()) )/ (3600*24)) | round(0) }}’ but no default was specified. Currently ‘strptime’ will return ‘2019-02-14’, however this template will fail to render in Home Assistant core 2021.12
1 Like

Nobody? Hoping somebody can help.

Why have you supplied strptime with a date string containing year, month, and day but asked it to convert it with a pattern that also includes hour, minute, second?

strptime("2019-02-14", "%Y-%m-%dT%H:%M:%S")
                                 ^^^^^^^^^
                     The pattern looks for all of this 
                         in the string "2019-02-14"
                            but it doesn't exist

strptime fails to convert “2019-02-14” to a datetime object so the result is just “2019-02-14” which is string and as_timestamp can’t convert that to a timestamp.

To answer you kind question;
imho i thought this was a good approach because timestamps are in seconds and is do an divide in seconds “(3600*24)”. But this was not a good approach i see now.

Thank you very much for helping. I fixed it now :slight_smile: