Hello, I would like a trigger for an automation?
one from the list of attributes.
For example, the “summary: 900 test”
Can you help me?
Hello, I would like a trigger for an automation?
one from the list of attributes.
For example, the “summary: 900 test”
Can you help me?
I’m using the template from hpoperator but the events are not sorted. I tried some variants but the events are not sorted.
See the template here:
- trigger:
- platform: time_pattern
minutes: /1
action:
- service: calendar.get_events
data:
duration:
hours: 720
minutes: 0
seconds: 0
start_date_time: "{{ today_at() }}"
target:
entity_id: calendar.familienkalender
response_variable: scheduled_events
- variables:
ev_list: |
{% set ns = namespace(cal_events=[]) %}
{%- for key, value in calendars.items() %}
{%- for event in value.events %}
{%- set ns.cal_events = ns.cal_events + [event] %}
{%- endfor %}
{%- endfor %}
{{ ns.cal_events | sort(attribute='start') | list }}
sensor:
- name: Familienkalender Events
unique_id: familienkalender_events
state: "{{ ev_list | count }}"
attributes:
scheduled_events: "{{ ev_list }}"
icon: mdi:calendar'
Not sure if this will work for you, but maybe change to the below and remove your other sort?
{%- for event in value.events|sort(attribute='start') %}
I don’t see how that is working at all… The template that defines the event list variable isn’t referencing your response variable.
Hello Everyone,
I have added local calendar integration and added two events in the single calendar which repeats monthly.
eg.
Event 1 is due date for electricity bill.
Event 2 is due date for water bill.
Kindly guide how to create two sensors for each event and get how many days are left for the next event.
{{ (state_attr('calendar.events', 'start_time') | as_timestamp - today_at('00:00') | as_timestamp)/(60*60*24) }}
The above returns the days left for the first event only. How to get for both the events ?
Thank you.
I used an SSD1306 OLED screen
I took the liberty of using your solution, my code looks as follows:
- id: page9
lambda: |-
// Print next four collection
char *strFam = strdup(id(cal_garbage).state.c_str());
char delim[] = "~";
char *nxtStrFam = strtok(strFam, delim);
if (nxtStrFam != NULL && strlen(nxtStrFam) > 0) {
it.printf(4, 0, id(font3), TextAlign::TOP_LEFT, "%s", nxtStrFam);
}
nxtStrFam = strtok(NULL, delim);
if (nxtStrFam != NULL && strlen(nxtStrFam) > 0) {
it.printf(128, 0, id(font3), TextAlign::TOP_RIGHT, "%s", nxtStrFam);
}
nxtStrFam = strtok(NULL, delim);
if (nxtStrFam != NULL && strlen(nxtStrFam) > 0) {
it.printf(0, 17, id(font3), TextAlign::TOP_LEFT, "%s", nxtStrFam);
}
nxtStrFam = strtok(NULL, delim);
if (nxtStrFam != NULL && strlen(nxtStrFam) > 0) {
it.printf(128, 17, id(font3), TextAlign::TOP_RIGHT, "%s", nxtStrFam);
}
nxtStrFam = strtok(NULL, delim);
if (nxtStrFam != NULL && strlen(nxtStrFam) > 0) {
it.printf(0, 34, id(font3), TextAlign::TOP_LEFT, "%s", nxtStrFam);
}
nxtStrFam = strtok(NULL, delim);
if (nxtStrFam != NULL && strlen(nxtStrFam) > 0) {
it.printf(128, 34, id(font3), TextAlign::TOP_RIGHT, "%s", nxtStrFam);
}
nxtStrFam = strtok(NULL, delim);
if (nxtStrFam != NULL && strlen(nxtStrFam) > 0) {
it.printf(0, 63, id(font3), TextAlign::BASELINE_LEFT, "%s", nxtStrFam);
}
nxtStrFam = strtok(NULL, delim);
if (nxtStrFam != NULL && strlen(nxtStrFam) > 0) {
it.printf(128, 63, id(font3), TextAlign::BASELINE_RIGHT, "%s", nxtStrFam);
}
this is one of ten screens that shows/renders every 93 seconds.
Unfortunately, the problem I have with it is that this code overflows the RAM memory and the ESP32 restarts approximately every 3 hours and 20 minutes.
Does this code generate some variable that fills the RAM memory and should be removed during the next rendering cycle?
My configuration.yaml.:
- trigger:
- platform: time_pattern
# This will update every hour
hours: "/6"
sensor:
- name: Garbage Data
icon: mdi:calendar
state: "OK"
attributes:
cal_garbage: >-
{% set items = state_attr('sensor.garbage_scheduled_events', 'scheduled_events') | sort(attribute='start') %}
{%- for item in items -%}
{% set delta = (item.start) | as_datetime | as_local - today_at() %}
{%- if delta.days == 0 -%}
{% set start = "Dzisiaj " %}
{%- elif delta.days == 1 -%}
{% set start = "Jutro " %}
{%- elif delta.days == 2 -%}
{% set start = "Pojutrze " %}
{%- else -%}
{% set start = as_timestamp(item.start) | timestamp_custom('%d %b ', default=0) %}
{%- endif -%}
{{start + '~'}}
{{item.summary + '~' }}
{% endfor %}
Have you ever had a problem with RAM overflowing?
May I ask for you advice? When I create an automation based on you code the “ev_list” variable remains empty without any errors.
My Code:
alias: Get Events
description: ""
trigger: []
condition: []
action:
- service: calendar.get_events
target:
entity_id:
- calendar.xxx
- calendar.yyy
data:
duration:
hours: 170
minutes: 0
seconds: 0
response_variable: calendars
- variables:
ev_list: |
{% set ns = namespace(cal_events=[]) %}
{%- for key, value in calendars.items() %}
{%- for event in value.events %}
{%- set ns.cal_events = ns.cal_events + [event] %}
{%- endfor %}
{%- endfor %}
{{ ns.cal_events | sort(attribute='start') | list }}
mode: single
What does the Trace show?
FWIW, here’s another way to do the same thing. The result is a sorted list of consolidated calendar events. However, if you couldn’t get Didgeridrew’s code to work then it’s unlikely this will.
- variables:
ev_list: |
{{ calendars.values() | map(attribute='events')
| sum(start=[]) | sort(attribute='start') }}
Thanks it was my fault - I looked at the wrong step. Thanks for your reply anyway!
Works like a charm, thanks for the hint!
Do you know by any chance if it’s possible to group the events by date?
I want to try to get a ePaper/ESP32 to display a weekly agenda and a grouping by date would be amazing.
The example currently produces a list of calendar events sorted by starting date (and time). What exactly do you mean by “grouping” them by date?
Sorry, I’m still in the process of thinking on how to implement my ePaper Calendar.
Would it be possible to convert it into a string in the process? So for example a string like this:
“Startdate-Starttime-Enddate-Endtime-Subject-Calendarname;”
→ Then I could append all strings, transfert that to the esp, split it there and show it on the display?
Did you get the answer for this question?. I am in the the same process as yours.
I have a ecalendar in a epaper display run by an ESP32. I communicate with HA through MQTT. I am trying to find a way to convert the calendar events into a JSON (?) to send it through the MQTT.
Unfortunatley no. I’m struggeling to get the touchscreen working of my epaper display. This is more or les on hold right now. Nevertheless, if you find a way I’m more than happy to hear it!
Thank you for this wonderful streamlined way to get the results from multiple calendars.
I am successfully using the calendar.get_events
service call to retrieve events from a number of calendars. Then, I format the information and send it along to an epaper dashboard. So far, all is good.
However, I would like to do some formatting next to the event depending on which calendar generated it. For example perhaps I put a little star icon next to the events that come from the “family” calendar.
As I understand the docs, get_events
returns summary, description, start, end, location
.
In situations where more than one calendar is targeted, can the returned data include the calendar_id
?
Not without heavy modifications to the template, or just output the raw response.
I have this template:
- trigger:
- platform: time_pattern
minutes: /1
action:
- service: calendar.get_events
data:
duration:
hours: 2160
minutes: 0
seconds: 0
start_date_time: "{{ today_at() }}"
target:
entity_id:
- calendar.booking1
- calendar.airbnb1
response_variable: calendars
- variables:
ev_list: |
{% set ns = namespace(cal_events=[]) %}
{%- for key, value in calendars.items() %}
{%- for event in value.events %}
{%- set ns.cal_events = ns.cal_events + [event] %}
{%- endfor %}
{%- endfor %}
{{ ns.cal_events | sort(attribute='start') | list }}
sensor:
- name: reservas
unique_id: reservas
state: "{{ ev_list | count }}"
attributes:
scheduled_events: "{{ ev_list }}"
icon: mdi:calendar'
and I get the following values:
scheduled_events:
- start: "2024-09-03"
end: "2024-09-04"
summary: a1
- start: "2024-09-03"
end: "2024-09-04"
summary: b1
- start: "2024-09-04"
end: "2024-09-06"
summary: b2
- start: "2024-09-20"
end: "2024-09-21"
summary: a2
icon: mdi:calendar'
friendly_name: reservas
How can I exclude repeated blocks of “star” values?
I want this:
scheduled_events:
- start: "2024-09-03"
end: "2024-09-04"
summary: a1
- start: "2024-09-04"
end: "2024-09-06"
summary: b2
- start: "2024-09-20"
end: "2024-09-21"
summary: a2
icon: mdi:calendar'
friendly_name: reservas
Thanks
{%- set ns = namespace(unique_ev_list=[]) %}
{%- for item in ev_list %}
{%- if item.start not in ns.unique_ev_list|map(attribute='start')|list %}
{%- set ns.unique_ev_list = ns.unique_ev_list + [item] %}
{%- endif %}
{%- endfor %}
{{ ns.unique_ev_list }}
Hi,
this solution worked for me fine.
But since this October may template didn’t show any events.
I didn’t change anything in the configuration.yaml.
I think the problem starts with the core update 2024.9.3
What have I missed?