Template for finding a specific ical calendar event

I’m trying to automate my kid’s alarm in the morning, so it will automatically adapt if school starts later because of last minute scheduling changes. This is very important in puberty :wink:

Her school calendar is available through a published iCal calendar. So I just installed the iCal sensor custom component. It shows me 6 sensors for the next 6 events in the calendar. I would like to know: what is the start time of the first upcoming event containing a hyphen (-) in the summary attribute?

Can someone help me out with a template? I’m stuck, don’t know how to approach this.

(screenshot removed)

Thanks in advance!

Copy-paste the following template into the Template Editor and confirm it reports the desired value.

{% set x = states.sensor
  | selectattr('object_id', 'match', 'ical_magister_')
  | selectattr('attributes.summary', 'search', '-')
  | map(attribute='attributes.start') | list %}
{{ x|first if x != [] else '' }}

It will report nothing (empty string) if none of the sensors contain a hyphen in their summary attribute (the screenshot you posted doesn’t show a hyphen in any of the sensors).

1 Like

Thanks @123 that works like a charm!

1 Like

Thank you! This is a big help for doing other templates with calendars.

1 Like