Problem with new service call "calendar.get_events"

Hey y’all!

i having an issue with the new service call “calendar.get_events”. Someone in the community here helped me to get a template sensor, that tells me the name of tomorros event. anything worked fine. but now, with the changing of the call, i thought, i could just switch it out but no…

can someone help me with that?

Here’s my original code im using (and still working):

template:
  - trigger:
      - platform: time
        at: "00:01:00"
      - platform: event
        event_type: event_template_reloaded
    action:
      - service: calendar.list_events
        target:
          entity_id: calendar.sarah_schicht
        data:
          duration:
            hours: 24
        response_variable: agenda
    sensor:
      - name: Tomorrow's Workshift
        state:  "{{ (agenda.events | selectattr('start', 'eq', (now()+timedelta(days=1)).date()|string ) | first).summary }}"
        availability: "{{ (agenda.events | selectattr('start', 'eq', (now()+timedelta(days=1)).date()|string )| first) is defined }}"

Thank you!

I think this may be what you need:

template:
  - trigger:
      - platform: time
        at: "00:01:00"
      - platform: event
        event_type: event_template_reloaded
    action:
      - service: calendar.get_events
        target:
          entity_id: calendar.sarah_schicht
        data:
          duration:
            hours: 24
        response_variable: agenda
    sensor:
      - name: Tomorrow's Workshift
        state:  "{{ (agenda['calendar.sarah_schicht']['events'] | selectattr('start', 'eq', (now()+timedelta(days=1)).date()|string ) | first).summary }}"
        availability: "{{ (agenda['calendar.sarah_schicht']['events'] | selectattr('start', 'eq', (now()+timedelta(days=1)).date()|string )| first) is defined }}"
1 Like

For future reference, the Calendar integration’s documentation includes an example showing how to use calendar.get_events.

The main difference from the previous version is that calendar.get_events can report events for multiple calendars. Therefore you have to specify which calendar you want from the response_variable (even if you asked for events from just one calendar). That’s why templeton_nash’s example, and the one in the documentation, reference the desired calendar’s events like this:

agenda['calendar.sarah_schicht']['events']
      ^^^^^^^^^^^^^^^^^^^^^^^^^^
         Specify the calendar
   even if you only asked for events
          from one calendar. 
2 Likes

Thank your very much for clarification! I marked you as the solution, because it’s more understandable for others what @templeton_nash has changed on my original code. I hope he’s fine with that :wink: