Check Calendar for Particular All Day Event

Hello!
I am hoping for some help with templates I’m working on. One is to detect whether it’s a school night and another to detect if it’s a no school day. I have a calendar with an all day event titled No School. For some reason it is picking up the event from the following day. I appreciate any help anyone can provide.

- trigger:
  - platform: time
    at: "00:01:00"
  action:
    - service: calendar.get_events
      data:
        start_date_time: "{{ today_at('00:00:00')}}"
        end_date_time: "{{ today_at('23:59:00')}}"
      target:
        entity_id: calendar.family
      response_variable: no_school_agenda
    - service: calendar.get_events
      data:
        start_date_time: "{{ today_at('00:00:00') + timedelta(days=1)}}"
        end_date_time: "{{ today_at('23:59:00') + timedelta(days=1)}}"
      target:
        entity_id: calendar.family
      response_variable: school_night_agenda
  binary_sensor:
    - name: No School
      unique_id: 22b30b2a-c8e6-11ee-a506-0242ac120002
      icon: mdi:calendar-alert
      state: |-
        {% set search_term = '(?i)no school' %}
        {{ no_school_agenda['calendar.family'].events 
        | selectattr('summary', 'search', search_term) | list | count > 0 }}
    - name: School Night
      unique_id: 121c1692-c8e8-11ee-a506-0242ac120002
      icon: mdi:calendar-alert
      state: |-
        {% set search_term = '(?i)no school' %}
        {{ school_night_agenda['calendar.family'].events 
        | selectattr('summary', 'search', search_term) | list | count < 1 }}

For which sensor? From what you have posted that is the expected behavior for School Night.

Here’s some additional information.

If I have a no school event for today, No School is on and School Night is on.
If I have a no school event for tomorrow, No School is on and School Night is off.
If I have no no school events, No School is off and School Night is on.

You’re only providing partial information… those appear to be the correct outcomes based on your previous post.

If those are the expected values, what values are being returned?

How are you testing your changes to the calendar?

I appreciate you taking time to help me out. I have temporarily changed my trigger to:

- trigger:
  - platform: time_pattern
    minutes: /1

This allows me to change my calendar and see the results a minute later. I have my iOS calendar linked to home assistant so that I just make changes on my phone and they’re reflected in the calendar right away.

If I have a no school event for only today, No School is on and School Night is on. This is expected
If I have a no school event for only tomorrow, No School is on and School Night is off. This is not expected. I would expect No School to be off since there’s nothing on the calendar for today.
If I have no no school events, No School is off and School Night is on. This is expected

Please let me know if there’s any other information I can provide!

I can’t reproduce what you are seeing, but I don’t use iOS. I’ve tested both HA Local Calendar and Google Calendar and they are returning the expected values for all three cases.

If you run the two services in the the Service tool are the contents of responses what is expected?

I’m seeing a mirror image of what school day & school night logic looks like in my brain. Monday is a school day, Sunday is therefore a school night. Conversely Saturday is a non- school day, thus Friday night is not a school night.

Swapping “no_school_agenda” with “school_night_agenda” in your binary_sensor should yield results reflecting the above logic & satisfy what I surmise you intend.

Praying my 77 YO brain is not tricking me.

I didn’t realize I could test this out in the services section. Here’s the response:

calendar.family:
  events:
    - start: "2024-03-02"
      end: "2024-03-03"
      summary: No School

Is there anything I can do to still be able to use this without modifying the actual calendar entry?

Looks correct to me. Saturday == No School as I see it. For clarity assume “2024-03-03” has “T00:00:00-…” tacked onto it You are seeing midnight to midnight.

Sorry, the internet went down last night and since it’s a CalDav calendar, it disappeared from home assistant.

I tried to add a no school event to my calendar for today and one for tomorrow.

Then, when I try to run the get events service, it gives me today’s and tomorrow’s event. It does this even if I change the start time to 01:00:00 and end time to 23:00:00. Maybe I just need to add logic to check if the start date is the date that I’m looking for and move on?

Same problem reported here; today and tomorrow’s all-day events are returned.

It may be due to an issue with the particular CalDav server you’re using.

I fought with all day events for a long time and gave up for now. I just add entries on a particular calendar at 7am where I look for the description and then take action based on that. I just set them for 15 minutes generally.