I’ve written a script to fetch my agenda items and store them in input_text.agenda_summary_tomorrow
for use in a TTS automation later in the day. While the script works, it only retrieves the first event from each calendar.
If events are spread across different calendars, they are listed correctly. However, when multiple events exist within the same calendar, only the first one is stored.
How can I modify my script to correctly list all events from each calendar in input_text.agenda_summary_tomorrow
?
alias: 📅 Load tomorrow's events
description: Extract tomorrow's events and save them to input_text.agenda_summary_tomorrow.
trigger:
- at: "00:00:00"
platform: time
action:
- service: input_text.set_value
target:
entity_id: input_text.agenda_summary_tomorrow
data:
value: ""
- variables:
tomorrow: "{{ (now() + timedelta(days=1)).strftime('%Y-%m-%d') }}"
calendars:
- calendar.family
- calendar.waste_collection
- calendar.personal_1
- calendar.paper_recycling
- calendar.plastic_recycling
- calendar.private_2
- repeat:
for_each: "{{ calendars }}"
sequence:
- variables:
start_time: "{{ state_attr(repeat.item, 'start_time') | default('') }}"
message: "{{ state_attr(repeat.item, 'message') | default('') }}"
- choose:
- conditions:
- condition: template
value_template: "{{ start_time[:10] == tomorrow and message != '' }}"
sequence:
- service: input_text.set_value
target:
entity_id: input_text.agenda_summary_tomorrow
data:
value: >
{% set current = states('input_text.agenda_summary_tomorrow') %}
{{ [current, message ~ (" om " + start_time[11:16] if start_time[11:16] != "00:00" else "")] | select('!=', '') | join(', ') }}
- choose:
- conditions:
- condition: template
value_template: "{{ states('input_text.agenda_summary_tomorrow') == '' }}"
sequence:
- service: input_text.set_value
target:
entity_id: input_text.agenda_summary_tomorrow
data:
value: "Geen afspraken voor morgen."
mode: single
Kind regards