Show calendar title/item (YAML)

Hi,

I’m trying to create a cool informational “next matchday” calendar for my football matches.
I’ve got the Google Calendar intergrated, in the calendar are all the matchdays.

How can I display the upcoming title of the next event? (e.g. upcoming Saturday it will be my team vs another team). When Saturday is passed show the one for the week next and so on and on…)

I did something similar with my garbage pick-up but as that is using sensors which contains the date it’s a bit easier. I have no clue how to tackle this and show the title of the upcoming calendar item…

Anybody who could help? :slight_smile: Greatly appreciated!

(just for ref, this is the garbage “script” i’ve made)

          waste: >
            {{-'\u26A0\uFE0F'}} Let op, {% set trash_dict = 
            { states('sensor.organic_waste_pickup') : "Groene bak", 
            states('sensor.packages_waste_pickup'): "Plastic bak",
            states('sensor.paper_waste_pickup'): "Papierbak",
            states('sensor.non_recyclable_waste_pickup'): "Grijze bak"} %}
            {% set next_date = trash_dict.keys()|sort|first %}
            {{ trash_dict.get(next_date)}} aan de straat {{ (next_date|as_datetime).strftime("%A, %d %B") }}

Almost got it!

football: >
            {{'\u26BD'}} {{ states.calendar.football.attributes.message }}, location {{ states.calendar.football.attributes.location }}. Starts at {{ states.calendar.football.attributes.start_time}}

However, this shows the date in this format: 2022-09-24 12:00.
How can I set this format to “Saturday, 24 September” ?

Greatly appreciated :smiley:

{{ state_attr('calendar.football', 'start_time') | as_timestamp | timestamp_custom('%A, %d %B') }}

NOTE

It’s preferable to use the state_attr() function to get an attribute’s value

{{ state_attr('calendar.football', 'message') }}

as opposed to referencing it directly

{{ states.calendar.football.attributes.message }}

for the reason explained in the documentation’s warning box.


Example

      football: >
        {{'\u26BD'}} {{ state_attr('calendar.football', 'message') }}, location {{ state_attr('calendar.football', 'location') }}. Starts at {{ state_attr('calendar.football', 'start_time') | as_timestamp | timestamp_custom('%A, %d %B') }}
1 Like

Many thanks for your detailled answer, got it working!

1 Like