e0909
(E0909)
December 19, 2023, 7:30pm
1
Hey guys,
I use several templates to count calendar events for the actual day (as well adding the event titles to the attribute).
template.yaml
- trigger:
platform: time_pattern
minutes: /30
action:
- service: calendar.list_events
target:
entity_id: calendar.privat
data:
start_date_time: "{{ now().strftime('%Y-%m-%d 00:00:00') }}"
end_date_time: "{{ (now() + timedelta(days=1)).strftime('%Y-%m-%d 00:00:00') }}"
response_variable: scheduled_events_privat
sensor:
- name: Scheduled Events PRIVAT 24h
unique_id: scheduled_events_privat_24h
state: "{{ scheduled_events_privat.events | count() }}"
attributes:
scheduled_events_privat: "{{ scheduled_events_privat.events }}"
icon: mdi:calendar
As announced the service ‘calendar.list_events’ is deprecated and will stop working in Home Assistant 2024.6. So I need to use ‘calendar.get_events’.
The output seems to be changed.
calender.list_events
events:
- start: "2023-12-19T09:10:00+01:00"
end: "2023-12-19T10:10:00+01:00"
summary: Zahnarzt
calender.get_events
calendar.privat:
events:
- start: "2023-12-19T09:10:00+01:00"
end: "2023-12-19T10:10:00+01:00"
summary: Zahnarzt
I did not get it working with the calender.get_events service.
Can some one help me out here what I need to change in my template to get it working with the new service?
Thanks
petro
(Petro)
December 19, 2023, 7:33pm
2
- trigger:
platform: time_pattern
minutes: /30
action:
- service: calendar.get_events
target:
entity_id: calendar.privat
data:
start_date_time: "{{ now().strftime('%Y-%m-%d 00:00:00') }}"
end_date_time: "{{ (now() + timedelta(days=1)).strftime('%Y-%m-%d 00:00:00') }}"
response_variable: scheduled_events_privat
sensor:
- name: Scheduled Events PRIVAT 24h
unique_id: scheduled_events_privat_24h
state: "{{ scheduled_events_privat['calendar.privat'].events | count() }}"
attributes:
scheduled_events_privat: "{{ scheduled_events_privat['calendar.privat'].events }}"
icon: mdi:calendar
1 Like
e0909
(E0909)
December 19, 2023, 7:43pm
3
oh wow, that was fast
works!
thank you very much @petro
e0909
(E0909)
December 19, 2023, 8:08pm
4
oh, im not sure why but now i get an error and the sensor is not available anymore.
Logger: homeassistant.helpers.template
Source: helpers/template.py:2260
First occurred: 20:59:00 (5 occurrences)
Last logged: 21:00:00
Template variable error: ‘dict object’ has no attribute ‘calendar.privat’ when rendering ‘{{ scheduled_events_privat[‘calendar.privat’].events | count() }}’
Logger: homeassistant.helpers.sensor
Source: helpers/trigger_template_entity.py:208
First occurred: 20:59:00 (5 occurrences)
Last logged: 21:00:00
Error rendering state template for sensor.scheduled_events_privat_24h: UndefinedError: ‘dict object’ has no attribute ‘calendar.privat’
petro
(Petro)
December 19, 2023, 8:14pm
5
Sorry, didn’t change the service call from calendar.list_events
to calendar.get_events
. Make that change and it’ll work.
1 Like
e0909
(E0909)
December 19, 2023, 8:33pm
7
works now as promised
Thanks again
remmob
January 4, 2024, 1:33pm
8
Thank you, this was very helpful.
I want to format it a bit more
start - end summary | example: 10:00-11:00 Work
and put in place of the entity name, which would give me a list of all the events.
Is that possible?
petro
(Petro)
January 4, 2024, 1:40pm
9
That would have to be done in your notification.
Garyw
(Gary Wilkinson)
July 14, 2024, 12:18am
11
Hi Petro, I think you helped me a year or so ago to get my automation going, however now its changed to get.events I can’t seem to get it right. I have an automation that gets the cal data for the last 24hrs and places it in a sensor that is in the templates directory, every morning piper gives me the cal events for the day I seem to be missing something? Not sure if there is a simpler way of doing it now with all the development, but this is what I have today. Any help would be appreciated.
Automation:
Sensor in templates directory