Get upcoming calendar events

Hi all!

As already some other users I try to get a list of upcoming calendar events. My use case is to show them on a epaper display (with esphome). I’m using the Google Calendar integration.

I already tried several several ICS/ICAL custom_components, however they all have huge problems with reoccuring events (e.g. birthdays events show up every month instead once a year) - at least for Google Calenders. They are not usable for my purpose.

In the developer documentation I found a method ‘Get Events’ for the calendar entity, which lists all events in a given date period. Is there a way I can call this method for an existing (Google) calendar - with an custom_component or any other way?

I tried by creating a new custom component. I requested my calendar entity with hass.states and then tried to call the method. However I get an error that this method is not applicable for the calendar entity state (AttributeError: ‘State’ object has no attribute ‘async_get_events’).

There is a feature request for this (or something similar), however it doesnt seem to have gotten any traction.

Here my custom_component code:

import logging
import datetime

_LOGGER = logging.getLogger(__name__)
DOMAIN = "calender_list"

def setup(hass, config):
    # Callback for service call (for testing purpose)
    def handle_refresh(call):

        # Callback method for calendar event list
        def calendar_events(result):
            _LOGGER.info("callback successfull")
            return True
        
        # Get Calendar entity
        entity = hass.states.get('calendar.mabjo')
        _LOGGER.warn("State of calendar entity: %s", entity)
    
        # Call method to get calendar events
        now = datetime.datetime.now()
        entity.async_get_events(
                self.calendar_events,
                hass,
                now, now)

        hass.states.set("hello_service.hello", name)

    # Register service call for testing purpose
    hass.services.register(DOMAIN, "refresh", handle_refresh)
    
    return True