Access to calender.ics entries

Hi all,

I am currently using the HACS waste collection Schedule.
My waste collector uses ICS entries.
I have successfully added them to my calender, and i have successfully added a notification for an entry.
Now my problem is, that every monday 3 waste bins are collected simultaneously.
“Biotonne”, Restmuelltonne" and “Gelber Sack”. All 3 are inside my calender but the Calender.ics has as an attribute only “restmuelltonne”, so i can only send within the notification, “restmuelltonne”:

alias: Müll 15:30
description: ""
trigger:
  - platform: calendar
    event: start
    offset: "-8:30:0"
    entity_id: calendar.ics
condition: []
action:
  - service: notify.all_telegram
    data_template:
      title: Müllbenachrichtigung
      message: >-
        Morgen wird folgender Müll abgeholt:  {{ state_attr("calendar.ics",
        "message") }}
mode: single

Screenshot 2023-12-10 204522

I know it’s just a first world problem, and i could just add the rest by myself, but somehow i should have access to other entries :slight_smile:

Thanks and happy 2nd Advent
wasty

Use the calendar.get_events service to extract the desired data via a Response variable.

Note: If you are running HA 2023.7 - 2023.11 you will use calendar.list_events

Thanks.
With

service: calendar.get_events
data:
  start_date_time: "2023-12-11 00:00:00"
  end_date_time: "2023-12-11 00:00:00"
target:
  entity_id: calendar.ics

i receive all three events:

calendar.ics:
  events:
    - start: "2023-12-11"
      end: "2023-12-12"
      summary: Restmuelltonne
    - start: "2023-12-11"
      end: "2023-12-12"
      summary: Biotonne
    - start: "2023-12-11"
      end: "2023-12-12"
      summary: Gelber Sack

But how do i access the indivdual name within summary?

BR
Wasty

alias: Müll 15:30
description: ""
trigger:
  - platform: calendar
    event: start
    offset: "-8:30:0"
    entity_id: calendar.ics
condition: []
action:
  - service: calendar.get_events
    data:
      start_date_time: "{{ now() }}"
      duration:
        hours: 24
    target:
      entity_id: calendar.ics
    response_variable: agenda
  - service: notify.all_telegram
    data_template:
      title: Müllbenachrichtigung
      message: >-
        Morgen wird folgender Müll abgeholt:  {{ agenda['calendar.ics'].events | map(attribute='summary') | join(', ') }}
mode: single

You’ll need to modify the start_date_time and duration to meet your needs and calendar setup.

Absolutely fabulous! works like a charm :slight_smile:
Thanks a lot!

I just found one little flaw with the script.
I get a notification every day. even when there are no appointments. In this case the message is empty.
How do i send it only when there are appointments?
i tried it with

service: notify.all_telegram
data_template:
  title: Müllbenachrichtigung
  message: >
    {% if states('calendar.ics.get_events.events') == ' ' %}#
      Morgen wird folgender Müll abgeholt:  {{ agenda['calendar.ics'].events | map(attribute='summary') | join(', ') }}
    {% else %}
      none
    {% endif %}

But this does not work. it always jumps into the else-clause
BR
Wasty

Add a template condition before the service call to check that there are events to send:

action:
  - service: calendar.get_events
    data:
      start_date_time: "{{ now() }}"
      duration:
        hours: 24
    target:
      entity_id: calendar.ics
    response_variable: agenda
  - condition: template
    value_template: "{{ agenda['calendar.ics'].events | count > 0 }}"
  - service: notify.all_telegram
    data_template:
      title: Müllbenachrichtigung
      message: >-
        Morgen wird folgender Müll abgeholt:  {{ agenda['calendar.ics'].events | map(attribute='summary') | join(', ') }}
mode: single

Thanks a lot.
You cannot imagine how long i tried with different states, templates and conditions, and you solved it in more or less one single line :smiley:

Thanks a lot again!

Hi,

i tried to use this Code for my notifications, i get a message, but its missing die Information about the Clalendar event, when viewing the code in the Template Editor i get “UndefinedError: ‘agenda’ is undefined”

alias: Notify - Müll
description: ""
triggers:
  - trigger: calendar
    entity_id: calendar.mull
    event: start
    offset: "-48:0:0"
conditions: []
actions:
  - action: calendar.get_events
    metadata: {}
    data:
      duration:
        hours: 48
        minutes: 0
        seconds: 0
    target:
      entity_id: calendar.mull
    response_variable: agenda
  - data_template:
      title: Müllbenachrichtigung
      message: >-
        Morgen wird folgender Müll abgeholt:  {{ agenda['calendar.mull'].events
        | map(attribute='summary') | join(', ') }}
    action: notify.greenapi
mode: single