How to list multiple calendar event in a template

Sorry, I’m still in the process of thinking on how to implement my ePaper Calendar.
Would it be possible to convert it into a string in the process? So for example a string like this:
“Startdate-Starttime-Enddate-Endtime-Subject-Calendarname;”
→ Then I could append all strings, transfert that to the esp, split it there and show it on the display?

Did you get the answer for this question?. I am in the the same process as yours.
I have a ecalendar in a epaper display run by an ESP32. I communicate with HA through MQTT. I am trying to find a way to convert the calendar events into a JSON (?) to send it through the MQTT.

Unfortunatley no. I’m struggeling to get the touchscreen working of my epaper display. This is more or les on hold right now. Nevertheless, if you find a way I’m more than happy to hear it!

Thank you for this wonderful streamlined way to get the results from multiple calendars.

I am successfully using the calendar.get_events service call to retrieve events from a number of calendars. Then, I format the information and send it along to an epaper dashboard. So far, all is good.

However, I would like to do some formatting next to the event depending on which calendar generated it. For example perhaps I put a little star icon next to the events that come from the “family” calendar.

As I understand the docs, get_events returns summary, description, start, end, location.

In situations where more than one calendar is targeted, can the returned data include the calendar_id?

Not without heavy modifications to the template, or just output the raw response.

I have this template:

- trigger:
    - platform: time_pattern
      minutes: /1
  action:
    - service: calendar.get_events
      data:
        duration:
          hours: 2160
          minutes: 0
          seconds: 0
        start_date_time: "{{ today_at() }}"
      target:
        entity_id:
          - calendar.booking1
          - calendar.airbnb1
      response_variable: calendars
    - variables:
        ev_list: |
          {% set ns = namespace(cal_events=[]) %}
          {%- for key, value in calendars.items() %}
            {%- for event in value.events %}
              {%- set ns.cal_events = ns.cal_events + [event] %}
            {%- endfor %}
          {%- endfor %}
          {{ ns.cal_events | sort(attribute='start') | list }}

  sensor:
    - name: reservas
      unique_id: reservas
      state: "{{ ev_list | count }}"
      attributes:
        scheduled_events: "{{ ev_list }}"
      icon: mdi:calendar'

and I get the following values:

scheduled_events:
  - start: "2024-09-03"
    end: "2024-09-04"
    summary: a1
  - start: "2024-09-03"
    end: "2024-09-04"
    summary: b1
  - start: "2024-09-04"
    end: "2024-09-06"
    summary: b2
  - start: "2024-09-20"
    end: "2024-09-21"
    summary: a2
icon: mdi:calendar'
friendly_name: reservas

How can I exclude repeated blocks of “star” values?
I want this:

scheduled_events:
  - start: "2024-09-03"
    end: "2024-09-04"
    summary: a1
  - start: "2024-09-04"
    end: "2024-09-06"
    summary: b2
  - start: "2024-09-20"
    end: "2024-09-21"
    summary: a2
icon: mdi:calendar'
friendly_name: reservas

Thanks

1 Like
{%- set ns = namespace(unique_ev_list=[]) %}
{%- for item in ev_list %}
{%- if item.start not in ns.unique_ev_list|map(attribute='start')|list %}
{%- set ns.unique_ev_list = ns.unique_ev_list + [item] %}
{%- endif %}
{%- endfor %}
{{ ns.unique_ev_list }}