I know, that with the new version defaults values in templates needs to be defined…
Now, I am getting errors with the following block:
do I need to change the as_timestamp(…) into something like this?
as_timestamp(states('sensor.cert_expiry_timestamp_abc_de')) default ('00.00.0000')
s_cert_expiry_abc_de_days:
friendly_name: 'abc.de exiration date'
value_template: >
{{ (as_timestamp(states('sensor.cert_expiry_timestamp_abc_de')) - as_timestamp(states('sensor.date.last_updated')) / 86400) | int }}
icon_template: >-
{% if states('sensor.s_cert_expiry_abc_de_days') | int > 0 %}
mdi:certificate
{% else %}
mdi:certificate-outline
{% endif %}
unit_of_measurement: days
the following errors are thrown in the logs:
Logger: homeassistant.helpers.template
Source: helpers/template.py:1210
First occurred: 7. Oktober 2021, 10:40:35 (8 occurrences)
Last logged: 7. Oktober 2021, 10:40:35
Template warning: 'as_timestamp' got invalid input 'unavailable' when rendering template '{{ ((as_timestamp(states('sensor.cert_expiry_timestamp_abc_de')) - as_timestamp(states.sensor.date.last_updated)) / 86400) | int }}' but no default was specified. Currently 'as_timestamp' will return 'None', however this template will fail to render in Home Assistant core 2021.12
Logger: homeassistant.helpers.event
Source: helpers/template.py:399
First occurred: 7. Oktober 2021, 10:40:35 (4 occurrences)
Last logged: 7. Oktober 2021, 10:40:35
Error while processing template: Template("{{ ((as_timestamp(states('sensor.cert_expiry_timestamp_abc_de')) - as_timestamp(states.sensor.date.last_updated)) / 86400) | int }}")
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 397, in async_render
render_result = _render_with_context(self.template, compiled, **kwargs)
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 1604, in _render_with_context
return template.render(**kwargs)
File "/usr/local/lib/python3.9/site-packages/jinja2/environment.py", line 1304, in render
self.environment.handle_exception()
File "/usr/local/lib/python3.9/site-packages/jinja2/environment.py", line 925, in handle_exception
raise rewrite_traceback_stack(source=source)
File "<template>", line 1, in top-level template code
TypeError: unsupported operand type(s) for -: 'NoneType' and 'float'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 513, in async_render_to_info
render_info._result = self.async_render(variables, strict=strict, **kwargs)
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 399, in async_render
raise TemplateError(err) from err
homeassistant.exceptions.TemplateError: TypeError: unsupported operand type(s) for -: 'NoneType' and 'float'
Logger: homeassistant.components.template.template_entity
Source: components/template/template_entity.py:73
Integration: Template (documentation, issues)
First occurred: 7. Oktober 2021, 10:40:35 (4 occurrences)
Last logged: 7. Oktober 2021, 10:40:35
TemplateError('TypeError: unsupported operand type(s) for -: 'NoneType' and 'float'') while processing template 'Template("{{ ((as_timestamp(states('sensor.cert_expiry_timestamp_abc_de')) - as_timestamp(states.sensor.date.last_updated)) / 86400) | int }}")' for attribute '_attr_native_value' in entity 'sensor.s_cert_expiry_abc_de_days'
Thanks a lot and with best regards,
Chris