Migrating from calendar.list_events to calendar.get_events

Just noticed that in the latest version of home-assistant, calendar.list_events is deprecated in favour of calendar.get_events which supports multiple calendar entities as an input.

I’m having trouble migrating one of my automations that currently iterates through events in each calendar in a template. With list_events, i’m running the script multiple times for each calendar and concatenating the outputs. With get_events, i shouldn’t need to do this and use the script one. However, the output from the service is different and not sure how to iterate the new output format…

list_events:

events:
  - start: "2023-12-08T15:40:00+00:00"
    end: "2023-12-08T16:15:00+00:00"
    summary: "Piano Lesson "
  - start: "2023-12-08T17:00:00+00:00"
    end: "2023-12-08T18:00:00+00:00"
    summary: "Swimming"
        {%- for event in agenda.events %}
        - Summary: {{ event.summary }}
         {%- if event.location is defined %}
            Location: {{ event.location }}
          {% endif -%}
        {%- endfor %}

get_events:

calendar.family_calendar:
  events:
    - start: "2023-12-08T15:40:00+00:00"
      end: "2023-12-08T16:15:00+00:00"
      summary: "Piano Lesson "
    - start: "2023-12-08T17:00:00+00:00"
      end: "2023-12-08T18:00:00+00:00"
      summary: "Swimming "
calendar.work
  events:
    - start: "2023-12-08T09:00:00+00:00"
      end: "2023-12-08T10:00:00+00:00"
      summary: "Meeting"

How do I modify the above template to iterate the calendars in the new output ?

Thanks

1 Like

Solved it. The new output is returned as a dictionary. This now works:

{%- for key, value in agenda.items() %}
  {%- for event in value.events %}
    - Summary: {{ event.summary }}
    {%- if event.location is defined %}
      Location: {{ event.location }}
    {% endif -%}
  {%- endfor %}
{%- endfor %}
3 Likes

I’ve got a similar issue when trying to use an automation to trigger the state of a binary sensor from tomorrow’s calendar events.

Everything works fine when I use list_events, but it breaks when I switch to get_events.

The binary sensor is currently set with the following template (where trigger.event.data.cal_events is the output of the list_events):

    state: |
      {{ trigger.event.data.cal_events['events']
      | map(attribute='summary') 
      | select('search', 'my string')
      | list | count > 0 }}

However, I can’t figure out how to modify the state calculation to take the new get_events dictionary output into account.

Just figured it out. Since all my events that I’m concerned about come from a single calendar, I just use the calendar’s name as an index before the events.

The new code now looks like this:

    state: |
      {{ trigger.event.data.cal_events['calendar.my_cal']['events']
      | map(attribute='summary') 
      | select('search', 'my string')
      | list | count > 0 }}

Hi togehter, it seems there are a lot of calender experts :slight_smile: in this post I opened a new topic because i need help (I am new and lost :frowning: ): https://community.home-assistant.io/t/calender-meetings-of-today-into-sensor/656488?u=uli1900 please take a look on my new topic. Thanks

Same error after upgrading to 11.2

Detected use of deprecated service `calendar.lists_events’
Use calendar.get_events instead which supports multiple entities.
Please replace this service and adjust your automations and scripts and select submit to close this issue.

I only have one calendar.
And two automations.
Each calls one event off the one calendar - One turns state of switch on. The other turns state of switch off

How to I rectify this annoying error?

Thanks

I have a script that runs once a day to check the webpage of my electricity distribution company for any scheduled maintenance in my neighborhood. If maintenance is scheduled, it adds the event to my calendar and raises a warning. Since scheduled maintenance is a rare occurrence, I overlooked the transition from using calendar.list_events to calendar.get_events . Yesterday, I received a warning about this issue, along with a repair warning. The message advised me to replace the deprecated service with calendar.get_events , which supports multiple entities. I quickly found the solution after reading your post. Thank you very much!

1 Like