[SOLVED] Template - Date subtraction setup problem

Hi, i can’t get the correct information for a google calendar data.
I want to create a garbage collection card that gives me the day of the week for the next garbage collection (this would also be simple).
I would also like that if the next retreat is tomorrow, instead of the date it appears as “tomorrow”.
The problem is that I can’t subtract the current date from the calendar date, I think because they are different formats.

The sensors are these:

{{ (states.calendar.savno.attributes.start_time)}}
{{ now() }}

and the result i get is
2022-12-13 08:00:00
2022-12-11 22:28:00.364432+01:00

i tried this code but i get an error

{{(((as_timestamp(now()) - as_timestamp(strptime(states.calendar.savno.attributes['start_time'], '%d-%m-%Y %H:%M'))))/60)|round(0)}}

ValueError: Template error: strptime got invalid input ‘2022-12-13 08:00:00’ when rendering template '{{ (states.calendar.savno.attributes.start_time)}}
{{ now() }}

This is my actual card
raccolta

entity: sensor.next_raccolta
name: Raccolta rifiuti
type: custom:multiple-entity-row
entities:
  - entity: calendar.savno
    attribute: start_time
    format: date
    name: ' '

Do you want the date or the day of the week?

{% set start_dt = state_attr('calendar.savno', 'start_time') | as_datetime | as_local %}
{% if start_dt.date() == now().date() %}
Today
{% elif start_dt.date() - now().date() == timedelta(days = 1 ) %}
Tomorrow
{% else %}
{{ start_dt.strftime("%A") }}
{% endif %}

Thanks, I want a day of the week, and your solution is awesome for me, but the day of the week of the English calendar is not simple for my wife to understand and so I changed your code

{{ start_dt.strftime("%A") }}

to this

 {{["Lunedì", "Martedì", "Mercoledì", "Giovedì", "Venerdì", "Sabato", "Domenica"] [start_dt.weekday()]}}

and it works perfectly.
thanks for the help

1 Like