Days to date Template

Home Assistant Template

Take sensor in D-M-Y format and convert to a number of days from today. Returns “Today” for the current day and “Tomorrow” for tomorrow, then xx days for future days.

{% set date = strptime(states('sensor.rubbish_recycling'), "%d-%m-%Y")) %}
{% set days = (( as_timestamp(date - as_timestamp(now()) )/ (3600*24)) | round(0,"ceil") %}
{% if days == 0 %}
{% set days = 'Today' %}
{% elif days == 1 %}
{% set days = 'Tomorrow' %}
{% else %}
{% set days = days ~ ' days' %}
{% endif %}
{{days}}