I’ve done something somewhat similar, settings sensors to pickup if it’s a school_day or a work_day based on day of the week, as well as Google Calendar integrations.
This thread in the forums helped me a bunch with the formatting: The EPIC Time Conversion and Manipulation Thread!
What I did personally was create a sensor to grab the event date from a calendar (this one’s our school’s publicly available calendar):
date_now_xxxx:
entity_id: sensor.date
value_template: >
{% if states('calendar.xxxx') == 'off' %}
off
{% elif now().timestamp() >= as_timestamp(strptime(states.calendar.xxxx.attributes.start_time, '%Y-%m-%d %H:%M:%S')) and now().timestamp() <= as_timestamp(strptime(states.calendar.xxxx.attributes.start_time, '%Y-%m-%d %H:%M:%S')) %}
on
{% else %}
off
{% endif %}
This would tell me if the event is active currently (on / off). Then I have another sensor to read the type of event and determine if it means school is in / out that day. I also have it reference our family calendar (for if we’re out of town/vacation), as well as days of the week (for if it’s a weekend).
date_schoolday:
value_template: >
{% set ct = states('sensor.date_time') %}
{% set ct = as_timestamp(strptime(ct,'%Y-%m-%d, %H:%M')) %}
{% if 'Saturday' in ct | timestamp_custom("%A") %}
off
{% elif 'Sunday' in ct | timestamp_custom("%A") %}
off
{% elif is_state("sensor.date_now_XXX","on") and 'no school' in states.calendar.XXX.attributes.message.lower() %}
off
{% elif is_state("sensor.date_now_YYY","on") and 'oliday' in states.calendar.YYY.attributes.message.lower() %}
off
{% elif is_state("sensor.date_now_YYY","on") and 'no school' in states.calendar.YYY.attributes.message.lower() %}
off
{% elif is_state("sensor.date_now_YYY","on") and 'family trip' in states.calendar.YYY.attributes.message.lower() %}
off
{% elif is_state("sensor.date_now_ZZZ","on") and 'holiday for all students' in states.sensor.ZZZ_calendar_event_0.attributes.name.lower() %}
off
{% elif is_state("sensor.date_now_ZZZ","on") and 'spring break' in states.sensor.ZZZ_calendar_event_0.attributes.name.lower() %}
off
{% else %}
on
{% endif %}
This then outputs either date_schoolday is ‘on’ or ‘off’ and I can use it in conditions to fire / negate different automations.
You’ll obviously have to play with it to see how your calendar events and such are setup to ensure you’re reading them correctly (start vs. end date [or both!), event title/name/text, etc…
I’m not sure this is exactly what you’re after, but hopefully it helps.