Lots of Template warnings - can't find source

Hi,

HA is generating huge amounts of these log entries, but I can’t find the source:

home-assistant.log.1:2022-01-20 11:33:12 WARNING (MainThread) [homeassistant.helpers.template] Template warning: 'as_timestamp' got invalid input 'None' when rendering template '# {{ as_timestamp(state_attr('sun.sun', 'next_')) | timestamp_custom('%H:%M') }}' but no default was specified. Currently 'as_timestamp' will return 'None', however this template will fail to render in Home Assistant core 2022.1
home-assistant.log.1:2022-01-20 11:33:12 WARNING (MainThread) [homeassistant.helpers.template] Template warning: 'timestamp_custom' got invalid input 'None' when rendering template '# {{ as_timestamp(state_attr('sun.sun', 'next_')) | timestamp_custom('%H:%M') }}' but no default was specified. Currently 'timestamp_custom' will return 'None', however this template will fail to render in Home Assistant core 2022.1
home-assistant.log.1:2022-01-20 11:33:12 WARNING (MainThread) [homeassistant.helpers.template] Template warning: 'as_timestamp' got invalid input 'None' when rendering template '# {{ as_timestamp(state_attr('sun.sun', 'next_r')) | timestamp_custom('%H:%M') }}' but no default was specified. Currently 'as_timestamp' will return 'None', however this template will fail to render in Home Assistant core 2022.1
home-assistant.log.1:2022-01-20 11:33:12 WARNING (MainThread) [homeassistant.helpers.template] Template warning: 'timestamp_custom' got invalid input 'None' when rendering template '# {{ as_timestamp(state_attr('sun.sun', 'next_r')) | timestamp_custom('%H:%M') }}' but no default was specified. Currently 'timestamp_custom' will return 'None', however this template will fail to render in Home Assistant core 2022.1
home-assistant.log.1:2022-01-20 11:33:12 WARNING (MainThread) [homeassistant.helpers.template] Template warning: 'as_timestamp' got invalid input 'None' when rendering template '# {{ as_timestamp(state_attr('sun.sun', 'next_ri')) | timestamp_custom('%H:%M') }}' but no default was specified. Currently 'as_timestamp' will return 'None', however this template will fail to render in Home Assistant core 2022.1
home-assistant.log.1:2022-01-20 11:33:12 WARNING (MainThread) [homeassistant.helpers.template] Template warning: 'timestamp_custom' got invalid input 'None' when rendering template '# {{ as_timestamp(state_attr('sun.sun', 'next_ri')) | timestamp_custom('%H:%M') }}' but no default was specified. Currently 'timestamp_custom' will return 'None', however this template will fail to render in Home Assistant core 2022.1
home-assistant.log.1:2022-01-20 11:33:12 WARNING (MainThread) [homeassistant.helpers.template] Template warning: 'as_timestamp' got invalid input 'None' when rendering template '# {{ as_timestamp(state_attr('sun.sun', 'next_ris')) | timestamp_custom('%H:%M') }}' but no default was specified. Currently 'as_timestamp' will return 'None', however this template will fail to render in Home Assistant core 2022.1
home-assistant.log.1:2022-01-20 11:33:12 WARNING (MainThread) [homeassistant.helpers.template] Template warning: 'timestamp_custom' got invalid input 'None' when rendering template '# {{ as_timestamp(state_attr('sun.sun', 'next_ris')) | timestamp_custom('%H:%M') }}' but no default was specified. Currently 'timestamp_custom' will return 'None', however this template will fail to render in Home Assistant core 2022.1
home-assistant.log.1:2022-01-20 11:33:12 WARNING (MainThread) [homeassistant.helpers.template] Template warning: 'as_timestamp' got invalid input 'None' when rendering template '# {{ as_timestamp(state_attr('sun.sun', 'next_risi')) | timestamp_custom('%H:%M') }}' but no default was specified. Currently 'as_timestamp' will return 'None', however this template will fail to render in Home Assistant core 2022.1
home-assistant.log.1:2022-01-20 11:33:12 WARNING (MainThread) [homeassistant.helpers.template] Template warning: 'timestamp_custom' got invalid input 'None' when rendering template '# {{ as_timestamp(state_attr('sun.sun', 'next_risi')) | timestamp_custom('%H:%M') }}' but no default was specified. Currently 'timestamp_custom' will return 'None', however this template will fail to render in Home Assistant core 2022.1
home-assistant.log.1:2022-01-20 11:33:12 WARNING (MainThread) [homeassistant.helpers.template] Template warning: 'as_timestamp' got invalid input 'None' when rendering template '# {{ as_timestamp(state_attr('sun.sun', 'next_risin')) | timestamp_custom('%H:%M') }}' but no default was specified. Currently 'as_timestamp' will return 'None', however this template will fail to render in Home Assistant core 2022.1
home-assistant.log.1:2022-01-20 11:33:12 WARNING (MainThread) [homeassistant.helpers.template] Template warning: 'timestamp_custom' got invalid input 'None' when rendering template '# {{ as_timestamp(state_attr('sun.sun', 'next_risin')) | timestamp_custom('%H:%M') }}' but no default was specified. Currently 'timestamp_custom' will return 'None', however this template will fail to render in Home Assistant core 2022.1

Problem is, I’ve got absolutely no idea where this template is defined. It was part of a Markdown dashboard card, but I deleted that one. I checked all the plain-text files in my conf dir manually, nowhere to be found. Restarting HA has no effect.

Is there some caching going on?

Installation details:

System Health

version core-2021.12.9
installation_type Home Assistant Container
dev false
hassio false
docker true
user root
virtualenv false
python_version 3.9.7
os_name Linux
os_version 4.4.180+
arch x86_64
timezone Europe/Amsterdam
Home Assistant Cloud
logged_in false
can_reach_cert_server ok
can_reach_cloud_auth ok
can_reach_cloud ok
Lovelace
dashboards 1
resources 0
views 1
mode storage

Each warning appears to be referring to a template that begins with a # symbol (which, in YAML, indicates the line is a comment). It implies that you commented out that line. Do you recall doing that sometime in the past?

Technically speaking, Home Assistant shouldn’t even be checking that line if it’s a comment. :thinking:

Yeah, that’s a bit confusing. But the “#” symbol in this case is Markdown syntax for ‘render as heading’, not a YAML comment.

The YAML looked like this:

type: markdown
content: >
  # {{ as_timestamp(state_attr('sun.sun', 'next_rising')) | timestamp_custom('%H:%M') }}

All the warnings are for the same line of YAML btw, something funky going on during parsing (next_, next_r, next_ri, etc.). That’s why I removed the card.

It did render though, despite the warnings.

Oops! I overlooked the fact you stated it was used in a Markdown card. :man_facepalming:

I agree and it might be due to a bug. I suggest you report it in Core repository on GitHub. Template validation is behaving strangely.

my experience with frontend jinja templates (mainly in template-entity-row) is that you explicitly need to refresh the frontend before restarting otherwise ‘old’ templates remain in cache and throw errors, even though the template has long gone. I guess it also happens in markdown.

btw, the error was correct, in that the defaults hadnt been set in the template, if you fix that, the errors will be gone.

1 Like

Thanks all, the warning message has suddenly magically disappeared from my logs. Must have been a cache.

I’ll give the defaults a try, though I must admit I don’t fully understand yet why it’s necessary here - does not using it expose a bug (the next_, next_r, etc.) or is that expected behaviour of the templating engine?

My newbe assumption would be that sun.sun.next_rising should always be defined (unless something has gone horribly wrong with our universe :grimacing:), so no default is necessery.

Anyway, glad my logging crisis has been averted.

this one solved my issue, was looking all over the place and it kept complaining, still printing the outdated version of my template that I had fixed in the config already and restarted (multiple times). Simply refreshing the frontend made the warnings finally stop.

1 Like