Calendar Events on my Display

Hello,

I have tried several solutions to display my calendar events on the epaper display, but none of them work.
has worked so far.

Does anyone have a reliable code how I can display the events of multiple calendars?

You can get any calendar event list as a json string, being careful of course of the limitation of string length in ESPHome.

Create a template and a service in ESPHome:

text_sensor:
  - platform: template
    id: all_agenda

api:
  services:
    - service: send_calendar
      variables:
        my_agenda: string
      then:
        - text_sensor.template.publish:
            id: all_agenda
            state: !lambda 'return my_agenda;'

Then in HA, have an automation that publishes your calendar events at an interval:

alias: Get Events
description: ""
trigger:
  - platform: time_pattern
    minutes: "5"
condition: []
action:
  - service: calendar.list_events
    data:
      end_date_time: "2023-10-08 00:00:00"
    response_variable: agenda
    target:
      entity_id: calendar.my_calendar_gmail_com
  - service: notify.persistent_notification
    data:
      title: Daily agenda for {{ now().date() }}
      message: >-
        Your agenda for today: <p> {% for event in agenda.events %} {{
        event.start}}: {{ event.summary }}<br> {% endfor %} </p>
  - service: esphome.webinterface_send_calendar
    data:
      my_agenda: "{{ agenda.events }}"
mode: single

Note I picked an arbitrary date - you can list for a selected interval rather than by end date. This will result in the text sensor in ESPHome being populated with the events in json format:

19:05:00	[D]	[text_sensor:064]	'all_agenda': Sending state '[{'start': '2023-09-29T19:00:00+10:00', 'end': '2023-09-29T20:00:00+10:00', 'summary': 'Test'}, {'start': '2023-10-01', 'end': '2023-10-03', 'summary': "Meagan's Birthday"}, {'start': '2023-10-03T00:00:00+11:00', 'end': '2023-10-04T00:00:00+11:00', 'summary': "Gemma's Birthday"}, {'start': '2023-10-03T02:00:00+11:00', 'end': '2023-10-04T02:00:00+11:00', 'summary': "Peter's Birthday"}]'

It also generates a notification - just for test purposes.

Have a read about calendar services in HA, you could really retrieve whatever you want with a bit of fiddling.

4 Likes

i will try it. thx

Did you update this to the new “get_events” method?

No - sorry. No longer using this code for anything.