Stuck on code checking date

Hi
I have a card showing when my heating is scheduled to next come on (using Google Calendar), but I’m stuck on trying to figure out how to set code to return results only if it’s scheduled to come on for today.

Atm it shows the next scheduled time, even if it’s weeks away.

Example. Today is Saturday 24th. Next planned heating is Friday 30th
image

image

I’m using the Mushroom Template card with the secondary information returning the info.

What I’m trying to do (and failing) is adding an additional condition to the initial “If” to only return results if %d/%m/%y matches today’s date.

What I have so far:

{% if is_state('calendar.heating','off') and (state_attr('calendar.heating', 'start_time') is not none) %}
{{as_timestamp(state_attr('calendar.heating','start_time')) | timestamp_custom('%H:%M')}} - {{as_timestamp(state_attr('calendar.heating','end_time')) | timestamp_custom('%H:%M')}}
{% elif is_state('calendar.heating','off') and (state_attr('calendar.heating', 'start_time') == none) %}
No Schedule
{% else %}
{% endif %}

This is kind of what I’m trying to do:

{% set datecheck = utcnow().strftime('%d/%m/%y') %}
{% if is_state('calendar.heating','off') and (state_attr('calendar.heating', 'start_time')| timestamp_custom('%d/%m/%y') = datecheck) %}
{{as_timestamp(state_attr('calendar.heating','start_time')) | timestamp_custom('%H:%M')}} - {{as_timestamp(state_attr('calendar.heating','end_time')) | timestamp_custom('%H:%M')}}
{% elif is_state('calendar.heating','off') and (state_attr('calendar.heating', 'start_time') == none) %}
No Schedule
{% else %}
{% endif %}

I think I got it working
I had to force the variable to be an integer as well as adding a second which made it easier to validate in the “if”

{% set datenow = (as_timestamp(now()))| timestamp_custom('%y%m%d', True) | float() | round (0) %}
{% set datetomorrow = (as_timestamp(now()) + (1*24*3600))| timestamp_custom('%y%m%d', True) | float() | round (0) %}
{% set datecheck = (as_timestamp(state_attr('calendar.heating','start_time')) | timestamp_custom('%y%m%d') | float() | round (0)) %}

{% if is_state('calendar.heating','off') and datecheck == datenow %}
{{as_timestamp(state_attr('calendar.heating','start_time')) | timestamp_custom('%H:%M')}} - {{as_timestamp(state_attr('calendar.heating','end_time')) | timestamp_custom('%H:%M')}}

{% elif is_state('calendar.heating','off') and datecheck == datetomorrow %}
{{as_timestamp(state_attr('calendar.heating','start_time')) | timestamp_custom('%d/%m/%y')}}
{{as_timestamp(state_attr('calendar.heating','start_time')) | timestamp_custom('%H:%M')}} - {{as_timestamp(state_attr('calendar.heating','end_time')) | timestamp_custom('%H:%M')}}

{% elif is_state('calendar.heating','off') and (state_attr('calendar.heating', 'start_time') == none) %}
No Schedule

{% else %}
No Schedule

{% endif %}

The following example uses datetime objects to simplify the comparison of dates and date arithmetic.

{% set start = state_attr('calendar.heating, 'start_time') %}
{% if start is not none %}
  {% set s = start | as_datetime | as_local %}
  {% if is_state('calendar.heating', 'off') and s.date() in [now().date(), (now() + timedelta(days=1)).date()] %}
     {{ iif(s.date() == now().date(), 'Today', 'Tomorrow') }} {{ start[-8:-3] }} - {{ state_attr('calendar.heating, 'end_time')[-8:-3] }}
  {% else %}
    No Schedule
  {% endif %}
{% else %}
  No Schedule
{% endif %}

EDIT

Correction. Misspelled variable.

That’s really interesting thanks.
Interesting that the t alias isn’t defined (t.date), but as it’s in sequence after s, I guess that’s allowed?

That was a typo. Example has been corrected.

{% set start = state_attr('calendar.heating, 'start_time') %}
{% if start is not none and is_state('calendar.heating', 'off') %}
  {% set s = (start | as_datetime | as_local).date() %}
  {% if s in [now().date(), (now() + timedelta(days=1)).date()] %}
     {{ iif(s == now().date(), 'Today', 'Tomorrow') }} {{ start[-8:-3] }} - {{ state_attr('calendar.heating, 'end_time')[-8:-3] }}
  {% else %}
    No Schedule
  {% endif %}
{% else %}
  No Schedule
{% endif %}