Automation to set a Variable based on tomorrows calendar

Hi,

I’m using Home Assistant to schedule the nightly charging of my EV. Until now I justed flipped a switch named “DriveTomorrow” to false if I don’t need to get to work tomorrow.

Now I have the idea to get an automation to check everyday at 22:00 if there is a Calender Entry named “Homeoffice” in my calender the next day and make the decision based on that and set DriveTomorrow to either true of false.

I spend the whole night but can’t find a solution for that problem. I can’t use the calender trigger because I want to trigger it at a specific time and I also want it to trigger if there is NO such a event and set DriveTomorrow to true and charge the EV.

Every idea or workaround is welcome

I use Google Calendar and have all-day events with various sub-calendars.
Create a sub-calendar “Home Office” and that calendar will show in HA.
In that calendar you create an all-day event with whatever title you want on the desired days.

Trigger
Calendar Home Office
time off-set minus 2 (as it is an all-day event, it starts at midnight, therefore 10 pm is minus 2.
Action
whatever you want.

You didn’t share the actual entities, so make sure to change the calendar and switch/boolean/whatever as needed…

trigger:
    - platform: time
      at: "22:00:00"
condition: []
action:
  - alias: Get calendar events for tomorrow
    service: calendar.get_events
    data:
      duration:
        hours: 24
        start_date_time: "{{ today_at() + timedelta(days=1) }}"
    target:
      entity_id: calendar.EXAMPLE
    response_variable: agenda
  - variables:
      homeoffice: |
        {{ agenda['calendar.EXAMPLE'].events | selectattr('summary', 'search', 'Homeoffice', true) | list | count > 0 }}
  - service: input_boolean.turn_{{ 'on' if homeoffice else 'off' }} 
    target:
      entity_id: input_boolean.drivetomorrow

this is not just working perfectly, I also love the elegance of that solution. Using a “hack” to turn_on or turn_off a boolean is something I never saw. And the calender magic itself is wonderfu.

<3 Thank you very very much