Template warnings - where to add the defaults?

I’m getting below Template Warnings, where do I need to add the defaults so the warnings will be gone?
If you need more info, please let me know.

Effective: >
  {{as_timestamp(state_attr('sensor.weatherbit_weather_alerts','alerts')
    [0].effective_local)|timestamp_custom('%c')}}
Expires: >
  {{as_timestamp(state_attr('sensor.weatherbit_weather_alerts','alerts')
    [0].expires_local)|timestamp_custom('%c')}}

Template warning: 'timestamp_custom' got invalid input 'None' when rendering template '{{as_timestamp(state_attr('sensor.weatherbit_weather_alerts','alerts') [0].effective_local)|timestamp_custom('%c')}}' but no default was specified. Currently 'timestamp_custom' will return 'None', however this template will fail to render in Home Assistant core 2021.12
Template warning: 'as_timestamp' got invalid input 'None' when rendering template '{{as_timestamp(state_attr('sensor.weatherbit_weather_alerts','alerts') [0].expires_local)|timestamp_custom('%c')}}' but no default was specified. Currently 'as_timestamp' will return 'None', however this template will fail to render in Home Assistant core 2021.12
Template warning: 'timestamp_custom' got invalid input 'None' when rendering template '{{as_timestamp(state_attr('sensor.weatherbit_weather_alerts','alerts') [0].expires_local)|timestamp_custom('%c')}}' but no default was specified. Currently 'timestamp_custom' will return 'None', however this template will fail to render in Home Assistant core 2021.12

Try 0 before the closing bracket of as_timestamp:


{{as_timestamp(state_attr('sensor.weatherbit_weather_alerts','alerts') [0].effective_local, 0)

1 Like

Thanks a lot!
It seems solved now. :+1:

The warning message is telling you that the result of all of this:

as_timestamp(state_attr('sensor.weatherbit_weather_alerts','alerts')
    [0].effective_local)

was None.

timestamp_custom cannot process a value of None so it is reported as a warning message.

By adding a default value of 0 for as_timestamp it reports 0 instead of None. Supplying a timestamp of 0 to timestamp_custom will make it report the Unix Epoch time (1970-01-01 00:00:00 offset by your local timezone).

1 Like

Thanks a lot for the explanation, really appreciated. :wink: