wasty81
(wasty)
December 10, 2023, 7:48pm
1
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
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
Thanks and happy 2nd Advent
wasty
Use the calendar.get_events
service to extract the desired data via a Response variable.
I am playing around with the new calendar.list_events service call. I have the below script and its running without issue. I am wondering how to view the contents of the response_variable “Rockies”. Ultimately I would like to email this on a weekly basis.
service: calendar.list_events
data:
start_date_time: "2022-03-22T20:00:00.000Z"
end_date_time: "2022-03-22T22:00:00.000Z"
target:
entity_id: calendar.colorado_rockies_schedule
response_variable: Rockies
Note: If you are running HA 2023.7 - 2023.11 you will use calendar.list_events
wasty81
(wasty)
December 10, 2023, 7:59pm
3
Didgeridrew:
calendar.get_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.
wasty81
(wasty)
December 10, 2023, 8:11pm
5
Absolutely fabulous! works like a charm
Thanks a lot!
wasty81
(wasty)
December 13, 2023, 6:48am
6
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
wasty81
(wasty)
December 14, 2023, 8:02am
8
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
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