hatoto
(hatoto)
December 10, 2023, 6:13pm
1
Hello
Does someone have an example of code, for using calendar.get_events
in an automation script ?
I can’t find the documentation for this new command.
I am using something like :
alias: Agenda_tomorrow
description: ""
trigger:
- platform: time
at: "19:30:00"
condition: []
action:
- service: calendar.list_events
target:
entity_id:
- calendar.john
device_id: []
area_id: []
data:
duration:
hours: 24
minutes: 0
seconds: 0
response_variable: agenda
- service: notify.gandi
data:
title: >-
tomorrow {{ (as_timestamp(now())+ (16500)) |
timestamp_custom("%d-%m-%Y", True) }}
message: >-
tomorrow: {{"\n"}} {% for event in agenda.events %}
{{as_timestamp(event.start)| timestamp_custom("%d-%m-%Y %-I:%M",
True)}}: {{ event.summary }} {{"\n"}} {% endfor %}
mode: single
It Works, but a notification is sent in HA: “Deprecate calendar.list_events”
123
(Taras)
December 10, 2023, 6:21pm
2
alias: Agenda_tomorrow
description: ""
trigger:
- platform: time
at: "19:30:00"
condition: []
action:
- service: calendar.get_events
target:
entity_id:
- calendar.john
data:
duration:
hours: 24
response_variable: agenda
- service: notify.gandi
data:
title: >-
tomorrow {{ (as_timestamp(now())+ (16500)) |
timestamp_custom("%d-%m-%Y", True) }}
message: >-
tomorrow: {{"\n"}} {% for event in agenda['calendar.john'].events %}
{{as_timestamp(event.start)| timestamp_custom("%d-%m-%Y %-I:%M",
True)}}: {{ event.summary }} {{"\n"}} {% endfor %}
mode: single
The new service call allows you to get events from multiple calendars. When referencing the response_variable, you need to specify which calendar even if you are only using one calendar.
hatoto
(hatoto)
December 10, 2023, 6:33pm
3
oh , OK
Thank you very much Taras.
Very quick reply, and now the code works.
I have seen the possibility to access multiple agenda, but I hadn’t seen how to distinguish each of them.
I have tried many hours before asking on community
1 Like
Olivier1974
(Olivier Toussaint)
December 10, 2023, 6:45pm
4
If you query more than one calendar, you can loop between them like so:
alias: Agenda_tomorrow
description: ""
trigger:
- platform: time
at: "19:30:00"
condition: []
action:
- service: calendar.get_events
target:
entity_id:
- calendar.john
- calendar.someone_else
data:
duration:
hours: 24
response_variable: agenda
- service: notify.gandi
data:
title: >-
tomorrow {{ (as_timestamp(now())+ (16500)) |
timestamp_custom("%d-%m-%Y", True) }}
message: >-
tomorrow: {{"\n"}}
{% for key, value in agenda.items() %}
{% for event in value.events %}
{{as_timestamp(event.start)| timestamp_custom("%d-%m-%Y %-I:%M", True)}}: {{ event.summary }} {{"\n"}}
{% endfor %}
{% endfor %}
{{ key }}
will contain calendar.john
or calendar.someone_else
. You can try to manipulate the value and make it appear somewhere in your text.
hatoto
(hatoto)
December 10, 2023, 8:54pm
5
Interesting
I don’t want to have to wake up for my wife events agenda , but I keep the idea for another usage
Olivier1974
(Olivier Toussaint)
December 11, 2023, 7:41pm
6
Indeed, I’m using it because my son and daughter have their own calendar, but both are under the school holiday calendar as well.
So for my son, it is
- calendar.conges_scolaires
- calendar.maxime
And my daughter
- calendar.conges_scolaires
- calendar.chloe
MehrCurry
(Guido Zockoll)
December 13, 2023, 7:20am
7
I got the same deprecation warning. How can i find the automation which is using the deprecated service? I have defined lots of automations in the UI, so clicking each to check will not be the best solution.
Olivier1974
(Olivier Toussaint)
December 13, 2023, 4:46pm
8
Have a look at the files called “automations.yaml
” and “scripts.yaml
” in the home assistant directory.
MehrCurry
(Guido Zockoll)
December 13, 2023, 8:29pm
9
So simple. I did not know that the automations are directly stored in that file. Thank you
1 Like
MehrCurry
(Guido Zockoll)
December 14, 2023, 8:53am
10
For anyone having the same issue. I could not find the service call in the automations.yaml. In fact, it was in one of the blueprints i use.
Olivier1974
(Olivier Toussaint)
December 14, 2023, 6:04pm
11
Indeed, folder “blueprints
”
I continue to get this message and have no idea how to sort it out. I’d love it if that was done automatically in one of the official updates. Thank you