How to list multiple calendar event in a template

:wave: Hi

I have the Google calendar integration which put the next event in state. I can as well see all events in the calendar view of HA.

I want to achieve the following: I want to be able to list in a message the events of the day with time and name. Would be awesome I can check how attendees are in the event to know if it is a meeting or if it is simply time I blocked.

I want as well to retrieve the last event of the morning in order to know when I can book and automate a message saying when the lunch should be ready.

For now I made some try with node red calling the HA calendar endpoints. It is not so bad except I need to authenticate for this call.

Before I explore more with Node Red do you know if there is a way to do it with HA ?

Go to developer tools → states tab. Copy/Paste the attributes on your calendar entities here. Make sure you do this on a desktop computer because the attribute column will be hidden if the browser window is too small (like on mobile). Be sure to include all entities.

So right now if I am looking at the right place I see:

message: 
all_day: false
start_time: 2021-10-27 10:00:00
end_time: 2021-10-27 10:45:00
location: 
description: 
offset_reached: false
friendly_name: XXXXXX Events

But a lot of things happened lately. What I first did is I use the api node in Node red to fetch the events from /calendars/calendar.XXXXXX. Then there I do some filtering like eliminating the one without any attendees or other specific to my need to have only real meeting and then I expose them in a numerical sensor as an attribute. The state itself being the amount of meetings.
And it works well. That being said I am moving away from Google Agenda so I will probably need to check the calDAV integration.

each event comes through as a separate entity? What’s the name of the entity

Not as far I see. There is only one Boolean entity which is either true or false if there is a meeting going on.

Then the information of the meeting is in the attributes.

But the attributes does not expose following meetings.

1 Like

I have no idea what you’re going on about. Are you using a calendar entity? If not, what type of entity is it? I’m trying to help with the original question, if you moved away from the original question then please say so.

Ok sorry it probably confused you that I called it boolean entity. It is a calendar entity but as result to me it gives a state ‘on’ or ‘off’

I use Google Calendar Event - Home Assistant and put track: True on the calendar I want.

It gaves me this entity:
calendar.clement_xxxxxx_xxxxxx_com

Right now it is ‘off’ and with as attributes:

message: Enfants
all_day: false
start_time: 2021-10-27 15:00:00
end_time: 2021-10-27 18:00:00
location: 
description: 
offset_reached: false
friendly_name: XXXXX Events

And this is the same entity that I shared early on with an other event in attributes

It seems the google calendar integration doesn’t display the events just the next one.
I know someone else asked a very similar question a few weeks ago and I was also very surprised by the entity having data but not… displaying it.

1 Like

This will get you todays calendar events, if they appear as separate entities.

{% set time = ' 00:00:00' %}
{% set start = now().date() %}
{% set end = (start + timedelta(days=1)) ~ time %}
{% set start = start ~ time %}
{% set entities = states.calendar | selectattr('attributes.start_time', '>', start) | rejectattr('attributes.end_time', '>', end) | list %}
{{ entities }}

From this point, you have a list of entities that are happening today, you’ll have to figure out what you want to do with them. If they only list the next entity like @Hellis81 says, then there’s nothing you can do.

1 Like

Hey petro, that was exactly i was looking for. Seems like i can’t find any documentation for this “set entities” function.

the result i get is

<template TemplateState(<state calendar.privat=off; message=Test Termin, all_day=False, start_time=2022-02-09 16:00:00, end_time=2022-02-09 17:00:00, location=None, description=None, offset_reached=False, friendly_name=Privat @ 2022-02-09T00:37:54.043329+01:00>)>

tried to access the data in the list with

{{ entities[0].message }}

any advice would be greatly appreciated. I want to extract information to build a TTS message for upcoming events that day.

set is a keyword in Jinja. entities is a variable. The right side of the equal sign’s result is placed into the entities variable.

The result of that line is a list of state objects, you can only access things that are availabe in the state object. See:

1 Like

Hi Petro,

This is also exactly what I have been looking for, but in the Home assistant dvelper tools → template section, I found this effor:

UndefinedError: 'homeassistant.util.read_only_dict.ReadOnlyDict object' has no attribute 'start_time'

Could you please advise how to modify it?

Regards,
Richard

your calendar entity needs to have a start and end time for it to work. That error is saying it doesn’t

Hi Petro,

I do see start and end time for the output of

{% set time = ' 00:00:00' %}
{% set start = now().date() %}
{% set end = (start + timedelta(days=1)) ~ time %}
{% set start = start ~ time %}
{{ states.calendar  | list }}
[<template TemplateState(<state calendar.family_calendar=off; offset_reached=False, friendly_name=family_calendar @ 2022-03-28T14:42:49.516789+02:00>)>, <template TemplateState(<state calendar.holidays_in_germany=off; message=Palm Sunday, all_day=True, start_time=2022-04-10 00:00:00, end_time=2022-04-11 00:00:00, location=, description=Observance
To hide observances, go to Google Calendar Settings > Holidays in Germany, offset_reached=False, friendly_name=Holidays in @ 2022-03-28T14:42:47.613284+02:00>)>, <template TemplateState(<state calendar.richard_calendar=off; message=Lunch, all_day=False, start_time=2022-03-29 13:30:00, end_time=2022-03-29 14:15:00, location=, description=, offset_reached=False, friendly_name=richard_calendar @ 2022-03-28T19:20:46.690701+02:00>)>, <template TemplateState(<state calendar.school_vacation=off; message=Vacation, all_day=False, start_time=2022-04-11 01:45:00, end_time=2022-04-11 02:00:00, location=, description=2:00, offset_reached=False, friendly_name=school_vacation @ 2022-03-28T14:42:43.547137+02:00>)>, <template TemplateState(<state calendar.sheng_ri=off; offset_reached=False, friendly_name=生日 @ 2022-03-28T14:42:45.989382+02:00>)>, <template TemplateState(<state calendar.task_important=off; message=Important: application form for Zehao and 60 Euro, all_day=False, start_time=2022-03-30 07:45:00, end_time=2022-03-30 08:00:00, location=, description=, offset_reached=False, friendly_name=task_important @ 2022-03-28T14:42:44.944210+02:00>)>, <template TemplateState(<state calendar.tv_time_calendar=off; message=TV_Time, all_day=False, start_time=2022-03-29 18:20:00, end_time=2022-03-29 18:40:00, location=, description=, offset_reached=False, friendly_name=tv_time_calendar @ 2022-03-28T18:35:46.402878+02:00>)>, <template TemplateState(<state calendar.vivian_calendar=off; message=面试, all_day=False, start_time=2022-03-29 10:00:00, end_time=2022-03-29 11:00:00, location=, description=, offset_reached=False, friendly_name=vivian_calendar @ 2022-03-28T14:42:47.164417+02:00>)>, <template TemplateState(<state calendar.weather=on; message=Forecast for 广东省深圳市 (19° | 15°), all_day=True, start_time=2022-03-28 00:00:00, end_time=2022-03-29 00:00:00, location=, description=, offset_reached=False, friendly_name=Weather @ 2022-03-28T14:42:47.998908+02:00>)>, <template TemplateState(<state calendar.zehao_calendar=off; message=School Time, all_day=False, start_time=2022-03-29 08:00:00, end_time=2022-03-29 12:40:00, location=, description=, offset_reached=False, friendly_name=zehao_calendar @ 2022-03-28T20:00:46.941931+02:00>)>, <template TemplateState(<state calendar.zherui_calendar=off; message=Sports, Sports and Sports, all_day=False, start_time=2022-04-01 07:30:00, end_time=2022-04-01 07:45:00, location=, description=, offset_reached=False, friendly_name=zherui_calendar @ 2022-03-28T14:42:49.217703+02:00>)>]

I have tried to adapt this code to work in template, but I still only get the current next entry in the calendar.
The problem I encounter is I am trying to send a notification 2hrs before a calendar event but can only read one event. so in my below example, there are 2 entries at 11am in the calendar for our cleaning company; HA is sending two notifications for the same address. Things work fine if the entries are at different times, but our calendar is fed from AirBNB for the checkin time / check out time of a guest and we have 5 properties, so there can be up to 5 entries at the same time for a cleaning task.

Any idea how I can trigger the text message for all entries in the calendar that are the same time?

alias: Notify Vicky of clean Today
description: ''
trigger:
  - platform: calendar
    event: start
    offset: '-2:0:0'
    entity_id: calendar.vicki_YYY
condition:
  - condition: template
    value_template: >-
      {{ 'cleaning' in
      states.calendar.vicki_YYY.attributes.description.lower() }}
action:
  - if:
      - condition: template
        value_template: >-
          {{ '30c' in states.calendar.vicki_YYY.attributes.location.lower()
          }}
    then:
      - service: rest_command.websms_txt
        data:
          message_to: 64271234567
          message_text: >-
            This is a friendly reminder that you have a clean at 30c XXX Dr
            today
  - if:
      - condition: template
        value_template: >-
          {{ '30d' in states.calendar.vicki_YYY.attributes.location.lower()
          }}
    then:
      - service: rest_command.websms_txt
        data:
          message_to: 64271234567
          message_text: >-
            This is a friendly reminder that you have a clean at 30d XXX Dr
            today
  - if:
      - condition: template
        value_template: >-
          {{ '132c' in states.calendar.vicki_YYY.attributes.location.lower()
          }}
    then:
      - service: rest_command.websms_txt
        data:
          message_to: 64271234567
          message_text: >-
            This is a friendly reminder that you have a clean at 132c XXX st
            today
  - if:
      - condition: template
        value_template: >-
          {{ '30e' in states.calendar.vicki_YYY.attributes.location.lower()
          }}
    then:
      - service: rest_command.websms_txt
        data:
          message_to: 64271234567
          message_text: >-
            This is a friendly reminder that you have a clean at 30e XXX Dr
            today
mode: queued

Like others, I’m trying pull up a list of google calendar entries.
My use case is that I have Tesco deliveries twice a week. The Tesco app puts the delivery into google calendar which has all my other events too. I book the slot a few weeks in advance and then populate the order the evening before the delivery is due. Yesterday I forgot I had a delivery due today so am paying £6.50 for a few raspberries (a placeholder). I want HA to look at my google calendar once a day and notify me if there is an event tomorrow with the title or message ‘Tesco order due’.
Like others, all i can see is the next event and its attributes.

1 Like

My use case is that I am interested in all events of the day from a single calendar.
And the calendar entity only contains the next event.

For example, there is a meeting at 10:00 and a presentation at 14:30.

Then I am trying to have a preview of the day by being notified everyday at 8:30 about the events of the day if only if there is any.

Currently, I am using Alexa, but it notifies me even when there isn’t any event.

There is a feature request for this functionality.

If you are also interested in getting a calender event list, please vote for this feature: Calendar - new entitites that show a list of events with a certain scope

My use case is to show a list of upcoming events on a epaper display. I already tried some ICS/ICAL custom_components, however they all seem to have huge problems with reoccuring events (e.g. birthdays events).

1 Like

I’m just curious if anyone has solved this. I can only pull the next event in a given calendar, but sometimes even that doesn’t work (perhaps because it’s more than X hours away?).

Is there any way to pull a list of entities/attributes for upcoming events? Ideally in Node Red.

Office integration and calendar works