Deprecate calendar.list_events

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”

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.

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 :rofl:

1 Like

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.

Interesting

I don’t want to have to wake up for my wife events agenda :joy:, but I keep the idea for another usage

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

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.

Have a look at the files called “automations.yaml” and “scripts.yaml” in the home assistant directory.

So simple. I did not know that the automations are directly stored in that file. Thank you

1 Like

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.

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 :grinning: