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.
fields:
  quantity:
    name: Event Quantity
    description: The number of events to return.
    example: 5
    required: true
    selector:
      number:
        min: 1
        max: 100
  calendar:
    name: Calendar
    description: The calendar entity to retrieve event information from.
    example: calendar.example
    required: true
    selector:
      entity:
        domain: calendar
sequence:
  - service: calendar.get_events
    data:
      end_date_time: "{{now() + timedelta(days=365)}}"
    target:
      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
    data:
      calendar: calendar.example
      quantity: 5
    response_variable: x
  - service: notify.notify
    data:
      message: |
        Your next 5 calendar events are as follows {{ x.events | map(attribute='summary') | join(', ') }}

Hhmmmm

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.