How I fetch all events in calendar.my_calendar instead of just the next event?

Hi all,

I’m trying to have text-to-speak read out all my calendar event for the day instead of just the next one.

I’m calling the calendar.solvstrom and i’m able to get my start_time and message.

{{ state_attr('calendar.solvstrom', 'start_time') }}
{{ state_attr('calendar.solvstrom', 'message') }}

Here is the entire automation

alias: Get all Google Events at 10am
description: ""
trigger:
  - platform: time
    at: "10:00:00"
condition: []
action:
  - service: homeassistant.update_entity
    target:
      entity_id:
        - calendar.solvstrom
    data: {}
  - service: conversation.process
    data_template:
      agent_id: conversation.chatgpt
      text: >-
        You are an advanced smart home personal assistant for Morten. Your tasks
        is to brief Morten about all of his events. Please list only
        the time and not the date for each event. The event starts on {{
        state_attr('calendar.solvstrom', 'start_time') }}.  The event is about
        {{ state_attr('calendar.solvstrom', 'message') }}.
    response_variable: cal_agent
  - service: tts.cloud_say
    data_template:
      cache: true
      entity_id: media_player.living_room_speaker
      language: en-GB
      message: "{{ cal_agent.response.speech.plain.speech | replace('*', '') }}"
mode: single

you have to call calendar.get_events which will then stuff all the events into a response_variable:

service: calendar.get_events
target:
  entity_id: calendar.solvstrom
data:
  duration:
    end_date_time:  >
      {{ now().date() }} 23:59:00
response_variable: agenda

now all the events will be in a list in agenda['calendar.solvstrom']['events']

how you want to deal with that is up to you, but here’s how you could enumerate them in your text template:

    {% for event in agenda["calendar.solvstrom"]["events"] %}
    the event, {{ event.summary }},  starts at {{ event.start}}
    {% endfor %}

Amazing, that did the trick! :slight_smile:

1 Like

great! glad to hear it’s working for you!