Hi everybody,
I have an automation that will create a calendar entry when pressing a physical button. This is entry is always named đźš— in garage
.
Let’s say we have an input_number
set to 7
and an input_datetime
set to 12:30
.
How can I trigger an automation at 12:30 if the most recent car in garage entry has occurred longer than 7 days ago? Ideally without actually considering the current time, just the day.
Example: today is May 19th, the automation will fire at 12:30. If most recent calendar entry I am looking for was on May 15th, do nothing (because it’s been less than 7 days). If the entry is dated May 12th, 16:30, do trigger the notification (even though May 19th 12:30 to May 12th 16:30 is not yet 7 days ago, but May 19th to May 12th without considering the exact time is 7 days ago in this case).
I got this so far
service call:
service: calendar.list_events
data:
start_date_time: "{{ now() - timedelta(days=7) }}"
end_date_time: "{{ now() }}"
target:
entity_id: calendar.garage
reply:
events:
- start: "2024-05-14T08:48:29+02:00"
end: "2024-05-14T09:08:29+02:00"
summary: đźš— outside
description: ""
- start: "2024-05-14T11:53:29+02:00"
end: "2024-05-14T12:13:29+02:00"
summary: đźš— car in garage
description: ""
So we are looking for the second entry, because only that one matches đźš— car in garage
. But how do I continue?
Since there might be different titles (i.e., đźš— outside
), the automation needs to go through each entry first to determine which events summary matches; then it needs to pick either the start or end date, check whether it has been 7 days, and then (if true) notify me.
It does no matter which detail (start/end) is picked. Start is always 10 minutes before pressing the physical button to create the event, end is always 10 minutes after. It’s just to get a time frame in there.
Perhaps this could even be a template sensor? So this template sensor would just be a number, namely the number of days from today looking back to the last calendar entry (again, not precisely counting seconds, just the amount of days; even if the car has technically just been in the garage for 6 days and 4 hours, I’d like this number to be 7 already).
I cannot figure this out, but I’m sure it is simple for those jinja2 ninjas here
Thank you in advance for your help