HI,
trying to determine wether the garbage is due in 2 days, I use this template sensor:
value_template: >
{% set papier = (as_timestamp(strptime(states('sensor.trash_papier'), '%d-%m-%Y')) -
(2 * 86400 )) | timestamp_custom('%d-%m-%Y') %}
{% set gft = (as_timestamp(strptime(states('sensor.trash_gft'), '%d-%m-%Y')) -
(2 * 86400 )) | timestamp_custom('%d-%m-%Y') %}
{% set plastic = (as_timestamp(strptime(states('sensor.trash_plastic'), '%d-%m-%Y')) -
(2 * 86400 )) | timestamp_custom('%d-%m-%Y') %}
{% set rest = (as_timestamp(strptime(states('sensor.trash_restafval'), '%d-%m-%Y')) -
(2 * 86400 )) | timestamp_custom('%d-%m-%Y') %}
{% set date = now().strftime('%d-%m-%Y') %}
{% if date == papier %} Papier
{% elif date == gft %} Gft
{% elif date == plastic %} Plastic
{% elif date == rest %} Restafval
{% else %} Geen
{% endif %}
Can this be changed so it won’t create this error:
2019-07-02 08:11:34 ERROR (MainThread) [homeassistant.helpers.entity] Update for sensor.afval_overmorgen fails
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 220, in async_update_ha_state
await self.async_device_update()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 375, in async_device_update
await self.async_update()
File "/usr/src/homeassistant/homeassistant/components/template/sensor.py", line 191, in async_update
self._state = self._template.async_render()
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 191, in async_render
return self._compiled.render(kwargs).strip()
File "/usr/local/lib/python3.7/site-packages/jinja2/asyncsupport.py", line 76, in render
return original_render(self, *args, **kwargs)
File "/usr/local/lib/python3.7/site-packages/jinja2/environment.py", line 1008, in render
return self.environment.handle_exception(exc_info, True)
File "/usr/local/lib/python3.7/site-packages/jinja2/environment.py", line 780, in handle_exception
reraise(exc_type, exc_value, tb)
File "/usr/local/lib/python3.7/site-packages/jinja2/_compat.py", line 37, in reraise
raise value.with_traceback(tb)
File "<template>", line 1, in top-level template code
TypeError: unsupported operand type(s) for -: 'NoneType' and 'int'
the sensor.trash_ xxx sensors have this format:
since these are made by a custom component, they probably aren’t initialized at the time HA tries to read them. Still, seeing this more than a few times in the startup log, and if possible like to prevent that.
thanks for having a look!