I just noticed I’m getting warnings in the log about this sensor.
2022-01-08 10:01:20 WARNING (MainThread) [homeassistant.helpers.template] Template warning: 'timestamp_local' got invalid input '64 days, 0:00:00' when rendering template '{%- set ns = namespace(previous = 2, spring=none, fall=none) %} {%- set today = strptime(states('sensor.date'), '%Y-%m-%d').astimezone().replace(hour=ns.previous) %} {%- for i in range(365) %}
{%- set day = (today + timedelta(days=i)).astimezone() %}
{%- if ns.previous - day.hour == -1 %}
{%- set ns.spring = today + timedelta(days=i) | timestamp_local %}
{%- elif ns.previous - day.hour == 1 %}
{%- set ns.fall = today + timedelta(days=i) | timestamp_local %}
{%- endif %}
{%- set ns.previous = day.hour %}
{%- endfor %} {{ [ns.spring, ns.fall] | min }}' but no default was specified. Currently 'timestamp_local' will return '64 days, 0:00:00', however this template will fail to render in Home Assistant core 2022.1
2022-01-08 10:01:20 WARNING (MainThread) [homeassistant.helpers.template] Template warning: 'timestamp_local' got invalid input '302 days, 0:00:00' when rendering template '{%- set ns = namespace(previous = 2, spring=none, fall=none) %} {%- set today = strptime(states('sensor.date'), '%Y-%m-%d').astimezone().replace(hour=ns.previous) %} {%- for i in range(365) %}
{%- set day = (today + timedelta(days=i)).astimezone() %}
{%- if ns.previous - day.hour == -1 %}
{%- set ns.spring = today + timedelta(days=i) | timestamp_local %}
{%- elif ns.previous - day.hour == 1 %}
{%- set ns.fall = today + timedelta(days=i) | timestamp_local %}
{%- endif %}
{%- set ns.previous = day.hour %}
{%- endfor %} {{ [ns.spring, ns.fall] | min }}' but no default was specified. Currently 'timestamp_local' will return '302 days, 0:00:00', however this template will fail to render in Home Assistant core 2022.1
2022-01-08 10:01:20 WARNING (MainThread) [homeassistant.helpers.template] Template warning: 'timestamp_local' got invalid input '64 days, 0:00:00' when rendering template '{%- set ns = namespace(previous = 2, spring=none, fall=none) %} {%- set today = strptime(states('sensor.date'), '%Y-%m-%d').astimezone().replace(hour=ns.previous) %} {%- for i in range(365) %}
{%- set day = (today + timedelta(days=i)).astimezone() %}
{%- if ns.previous - day.hour == -1 %}
{%- set ns.spring = today + timedelta(days=i) | timestamp_local %}
{%- elif ns.previous - day.hour == 1 %}
{%- set ns.fall = today + timedelta(days=i) | timestamp_local %}
{%- endif %}
{%- set ns.previous = day.hour %}
{%- endfor %} {{ [ns.spring, ns.fall] | min }}' but no default was specified. Currently 'timestamp_local' will return '64 days, 0:00:00', however this template will fail to render in Home Assistant core 2022.1
2022-01-08 10:01:20 WARNING (MainThread) [homeassistant.helpers.template] Template warning: 'timestamp_local' got invalid input '302 days, 0:00:00' when rendering template '{%- set ns = namespace(previous = 2, spring=none, fall=none) %} {%- set today = strptime(states('sensor.date'), '%Y-%m-%d').astimezone().replace(hour=ns.previous) %} {%- for i in range(365) %}
{%- set day = (today + timedelta(days=i)).astimezone() %}
{%- if ns.previous - day.hour == -1 %}
{%- set ns.spring = today + timedelta(days=i) | timestamp_local %}
{%- elif ns.previous - day.hour == 1 %}
{%- set ns.fall = today + timedelta(days=i) | timestamp_local %}
{%- endif %}
{%- set ns.previous = day.hour %}
{%- endfor %} {{ [ns.spring, ns.fall] | min }}' but no default was specified. Currently 'timestamp_local' will return '302 days, 0:00:00', however this template will fail to render in Home Assistant core 2022.1
If I update the template to specify a default value for timestamp_local:
{%- set ns.spring = today + timedelta(days=i) | timestamp_local(0) %}
then I get a data type mismatch:
TypeError: unsupported operand type(s) for +: 'datetime.datetime' and 'int'
I’ve tried to figure out the needed changes but I’m not getting anywhere.
I’ve kind of lost track about what is supposed to be the “latest & greatest” version.
suggestions?
EDIT:
Do I just need to remove the “| timestamp_local” filters from the ns.spring & ns.fall calculations and convert it at the end?
this seems to work:
{%- set ns = namespace(previous = 2, spring=none, fall=none) %}
{%- set today = strptime(states('sensor.date'), '%Y-%m-%d').astimezone().replace(hour=ns.previous) %}
{%- for i in range(365) %}
{%- set day = (today + timedelta(days=i)).astimezone() %}
{%- if ns.previous - day.hour == -1 %}
{%- set ns.spring = today + timedelta(days=i) %}
{%- elif ns.previous - day.hour == 1 %}
{%- set ns.fall = today + timedelta(days=i) %}
{%- endif %}
{%- set ns.previous = day.hour %}
{%- endfor %}
{{as_timestamp([ns.spring,ns.fall]|min)|timestamp_local}}
I haven’t tried it in the system yet to see if I still get warnings but it works in dev tools.