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 %}
1 Like

Amazing, that did the trick! :slight_smile:

1 Like

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

Thanks @armedad still getting head around this

can you point down the right track

alias: Speak My Shift Pattem
sequence:
  - action: calendar.get_events
    metadata: {}
    data:
      end_date_time: |
        {{ now().date() + timedelta(days=5) }} 03:01:00
    target:
      entity_id: calendar.stephan_shift
    response_variable: agenda
  - action: tts.speak
    metadata: {}
    data:
      cache: false
      media_player_entity_id: media_player.cuckoo_clock
      message: |
        {% for event in agenda["calendar.stephan_shift"]["events"] %}
         the event, {{ event.summary }},  starts on {{ event.start}}
        {% endfor %}
    target:
      entity_id: tts.piper

How can I change the event.start not to say “2024-11-02T03:00:00+13:00”
say something like “Saturday the 2 Nov”

what manual should I be reading

hi @myle

generally speaking, please start new threads for new questions. if it’s related to an existing one, you can reference it. in this case, although your new question is related, it stands alone just fine.

doing this as its own separate question helps the community because will be searched and categorized as the independent question that it is.

that said, the way to do what you’re asking for is

{{ as_datetime(event.start | string).strftime('%A %d %b') }}

i’ve casted it to a string… that may be unnecessary as it may already be a string, i’m not positive… but doesn’t hurt…
if you want other tweaks to the output, look at strftime docs.

Thanks Bro

just started reading about the strftime

here Python strptime() - string to datetime object