Setting a helper to true if an event happens anytime that day

What I’m trying to do: I have a calendar that shows when my team is playing but I wanted to use a conditional card to show on my tablet dashboard not just for the time period of the game but for the entire game day. The calender is an ical from the club and only shows true for the time period of the game.

My issue: Firstly I dont know how to write a template for this.
I want something that detects if there is something on each day for that calendar and if so, set a helper to true and then at midnight it checks again and sets it to false so the card clears off the dashboard until the next game day.

Any help appreciated.

I think the Home Feed Card from HACS will do what you want:

Screenshot 2024-04-28 17.11.51

Here is something that may be able to help you …
Automation that gives you a list of calendar events for that day. You can use that to display in your card - or use markdown card to show “{{ states(‘input_text.games_coming_up’)}}”
It assumes you have calendar already added, called “the_ical_calendar”
It assumes you have a input_text helper “games_coming_up”

alias: AutomationToGetListOfGamesForToday
description: ""
trigger:
  - platform: time
    at: "00:00:00"
condition: []
action:
  - service: calendar.get_events
    target:
      entity_id:
        - calendar.the_ical_calendar
      device_id: []
      area_id: []
    data:
      duration:
        hours: 24
        minutes: 0
        seconds: 0
    response_variable: gamescomingup
  - service: input_text.set_value
    target:
      entity_id: input_text.games_coming_up
    data_template:
      value: |-
        {%- if gamescomingup['calendar.the_ical_calendar'].events %}
            {%- for event in gamescomingup['calendar.the_ical_calendar'].events|sort(attribute='start') %}
              {{ event.summary }} <br>
          {%- endfor %}
        {%- else %} no games today
        {%- endif %}
mode: single

Note - I haven’t tested this, so you may need to make some adjustments.

Cheers, this is a good starting point. I want a boolean so I can trigger the display of another card but this guidance and chatgpt I might get there. I will update if I do.

alias: Set Game Day Boolean
description: ""
trigger:
  - platform: time
    at: "00:00:00"
  - platform: homeassistant
    event: start
condition: []
action:
  - service: calendar.get_events
    target:
      entity_id:
        - calendar.YOUR_CALENDAR
    data:
      start_date_time: "{{ today_at() }}"
      duration: 
        hours: 24
    response_variable: games
  - variables:
      event_today: "{{ games['calendar.YOUR_CALENDAR'].events | count > 0 }}"
  - service: input_boolean.turn_{{ 'on' if event_today else 'off' }}
    target:
      entity_id: input_boolean.YOUR_BOOLEAN
    mode: single

EDIT: Added start_date_time to avoid possible false-positive that could have been caused by a mid-day restart of HA.

2 Likes

Noooooooo! Do not use ChatGPT! :scream:

You are a gent. This worked perfectly. I just copied it to the yaml of the automation editor, updated my calender, alias and boolean and it worked.

Thank you so much.

1 Like