I have a sensor grabbing the day’s events from CalDAV.
- trigger:
trigger: time_pattern
hours: /12
action:
- action: calendar.get_events
data:
start_date_time: "{{ today_at('00:00:00') }}"
end_date_time: "{{ today_at('23:59:59') }}"
target:
entity_id: calendar.ours
response_variable: agenda_today
sensor:
- name: Daily Agenda
unique_id: agenda_today
state: "{{ agenda_today['calendar.ours'].events | count() }}"
attributes:
agenda_today: "{{ agenda_today['calendar.ours'].events }}"
icon: mdi:calendar
This then gets passed to assist for a daily briefing with this template:
Calendar events today: {% set agenda = state_attr('sensor.daily_agenda',
'agenda_today') %} {% if agenda %}
{% for event in agenda %}
{% if event.summary %}
Event: {{ event.summary }}
Location: {% if event.location %}{{ event.location }}{% endif %}
{% endif %}
{% endfor %}
{% else %}
There are no events for today.
{% endif %}
Overall it works well, but I struggle with all-day events due to the time zone offset (I am on Eastern US time). CalDAV sees an all-day event tomorrow (April 11) as from April 10 at 8PM to April 11 at 8PM, rather than April 11 from 12AM to 11:59PM. I think this is where the problem stems from, because it is passing tomorrow’s event to the Daily Agenda sensor as if its starting today.
So when I look at the attributes for the CalDAV sensor, I see this:
Attributes
Message Garbage Day!
All day Yes
Start time April 10, 2025 at 8:00:00 PM
End time April 11, 2025 at 8:00:00 PM
How can I adjust the start_date_time and end_date_time, or the time offset for CalDAV, so my sensor properly reads out only the events happening on that day?
I’ve tried a few different options and had no luck:
start_date_time: "{{ now().astimezone().strftime('%Y-%m-%d 00:00:00') }}"
end_date_time: "{{ now().astimezone().strftime('%Y-%m-%d 23:59:59') }}"
and
start_date_time: "{{ now().astimezone().replace(hour=0, minute=0, second=0, microsecond=0).isoformat() }}"
end_date_time: "{{ now().astimezone().replace(hour=23, minute=59, second=59, microsecond=999999).isoformat() }}"