Is there a way to check if "another event in the next 24 hours", DURING an event in a calendar?

Basically, my work auto-publishes my schedule to a Google calendar. I’d like an automation to run only on my pre-last day of work (and I can’t just use weekdays because I’m on rotating shifts).

I have the Google calendar integration set up, I thought I could use the “start_time” as it shows the time of the next event, but turns out that shows the start_time of the current event if there is currently one. While at my work there will always be an event “currently” so the start_time will always be the time I started work, and not the start time of the next shift.

I thought of maybe using the search function when configuring the calendar, but all the events have the same title as it’s auto-generated by my work… I’d need to somehow “look ahead 24 hours” and check if there is an event there, if yes then don’t do anything, if no (this is my last day) then run the automation.

I can’t just run the automation when I leave sadly, has to be done before (while I’m at work). Is there a way to create maybe a template-calendar that’s always 24 hours in advance? Like that I could check that calendar and decide if today is my last day…?

Thanks a lot!!

It would be much easier to answer if we would know something about the calendar.
Does it have all the events in one entity or multiple entities with one event in each?

Hi! Thank you. Sorry, I thought it was always the same, but I basically followed this guide and so I only have 1 entity for this calendar (since all the events are in the same calendar and have the same titles, only the start and end times change.

So yeah just one entity, looks like this (changed the characters of course):
image

I search for “shift” because all shifts have that word in them and all vacation days have “Leave” in the title, so this filters those out. But other than that… it’s all in one entity.

I don’t use the google calendar but if the data is there then I know how to handle it in Home Assistant.

Try if you can connect your calendar with this integration instead:
tybritten/ical-sensor-homeassistant: an iCal Sensor for Home Assistant (github.com)
It will give you multiple entities

Thanks for the link. I tried installing that several times, both manually or with HACS, when I do the setup it creates an integration but no devices nor entities are added. Didn’t see anything in the HA log… tried with a few different public .ics links, never worked. It’s probably something I’m doing wrong, I will look into it or try to find another integration that does a similar thing (multiple entities per calendar), thank you!

I wasn’t sure it was going to work. I use that integration on my office365 calendar.
Yes, see if you can find a better calendar integration.

Do you always work the previous day, or is it more complicated than that? And, do you need the previous event to fire exactly at the start time of that event, or is there more flexibility?

Whoops, had forgotten about this thread. Thanks for the reply! Sadly the schedule is all over the place, sometimes I work many days in a row, sometimes not, so the best way to find out would really be to “look ahead” in the calendar.

And no I would not need the event to fire at a specific time, I would just run an automation some time during my current shift (thus during a current calendar event), and if the next day contains a work event = do something, if not = do something else. If that makes sense! Thanks a lot

How about this: When the current event ends, you can have a state trigger with a delayed action far enough into the future (i.e. more than the 15 min the Google Calendar integration takes to update). At that point in time, the calendars state will be off, but there will be a start time attribute for the next event (if any). If there is none (i.e. the attribute doesn’t exist), do your thing. This should work, unless the end time of your shift is already too late.

Thank you for the detailed idea, but sadly I’m really needing my “detection” to happen before the end of the shift. The way the work calendar is built makes it so that I’ll usually leave work even before the event ends, so I really need to “look ahead” to the next event before this one is over

I’m not sure there’s a way with the default Google calendar integration I’m using, unless I can somehow create a new “offset” calendar that is running 8hrs or 12hrs too early, and it can check if it has any upcoming event in the next 24hrs

1 Like

Did you ever fix this? I’m trying to accomplish the same…

No, and I just googled a similar question and laughed when the first thread I found looked liked “the exact same problem I would have” and then I realised it was me who posted it.

Did you find a solution to this by any chance?

2 Likes

Is there any way to do this now?
I tried messing with the calendar trigger in automations, with offsets and all that, but it seems like I still can’t get any info about the “next event” during a current event.

I need this for an automation because I want to check if I work tomorrow at least 1hr before my shift today ends… so I really need to find a way to check the “next event” during the event that is happening right now.

1 Like