So, here’s what I would use. Works even during leap years. Gotta use the time_date platform to get a sensor that updates once a day. Using this will create sensor.date.
sensor:
- platform: time_date
display_options:
- 'date'
- platform: template
sensors:
remaining_days:
entity_id:
- sensor.date
value_template: >
{% set this = now().replace(hour=0).replace(minute=0).replace(second=0).replace(microsecond=0) %}
{% set next = this.month + 1 if this.month + 1 <= 12 else 1 %}
{% set last = this.replace(month=next, day=1) %}
{{ (last.date() - this.date()).days }}
- platform: template
sensors:
past_days:
entity_id:
- sensor.date
value_template: >
{% set this = now().replace(hour=0).replace(minute=0).replace(second=0).replace(microsecond=0) %}
{% set next = this.month + 1 if this.month + 1 <= 12 else 1 %}
{% set first = this.replace(day=1) %}
{{ (this.date() - first.date()).days }}