I try to make use of the newly introduced availability_template.
This should get rid of errors at startup of hass. I struggle with nesting the value_template in the availability_template.
- platform: template
sensors:
days_gft:
availability_template: >-
{%- if not is_state("sensor.waste_gft", "unavailable") %}
value_template: >-
{% set days = (strptime(states('sensor.waste_gft'), '%Y-%m-%d').strftime('%j') | int) - now().strftime('%j') | int ) %}
{% if days == 0 %}
today
{% elif days == 1 %}
tomorrow
{% elif days >= 2 %}
in {{days}} days
{% else %}
not any time soon
{% endif %}
entity_id: date.time
{% else %}
not available
{% endif %}
Can someone shine a light in the darkness?