Calendar: List Events to return next {X} events

While it’s great that the calendar.list_events can retrieve future events based on them occuring in a future period of time, it would be good to also return the next {X} events regardless of when they are in the future.

alias: N-Quantity Events from calendar
description: A script to return a given number of calendar events.
    name: Event Quantity
    description: The number of events to return.
    example: 5
    required: true
        min: 1
        max: 100
    name: Calendar
    description: The calendar entity to retrieve event information from.
    example: calendar.example
    required: true
        domain: calendar
  - service: calendar.get_events
      end_date_time: "{{now() + timedelta(days=365)}}"
      entity_id: "{{ calendar }}"
    response_variable: agenda
  - variables:
      scheduled: "{{ {'events': agenda[calendar].events[:quantity]} }}"
  - stop: Return the response variable back to the calling script or automation
    response_variable: scheduled
mode: single

EDIT: Updated to use calendar.get_events

1 Like

I was just looking for this feature. Where does this need to be created?

What I posted above is a script. Once created it can be called as a service from automations, scripts, or trigger-based template sensors.

  - service: script.n_quantity_calendar_events
      calendar: calendar.example
      quantity: 5
    response_variable: x
  - service: notify.notify
      message: |
        Your next 5 calendar events are as follows {{ | map(attribute='summary') | join(', ') }}


What im wanting is to show the list of upcoming events on the Dashboard. Right now i just have the standard calendar card.

Basically show the date, time and subject of the next ‘x’ events.

You may want to check out Atomic Calendar Revive Card. It’s a flexible and feature-packed card with both Calendar and list (“Event”) viewing modes. You can use the maxEventCount configuration option to limit the number of events shown when using Event Mode.