What are the local calendar attributes?

I want to read the attributes of a calendar at any time, not just when an event is triggered, but cannot find any direct documentation on this. There is documentation on
Trigger variables and
Service parameters

By experimentation in the Template Editor I found that the following work OK

"{{ state_attr('calendar.living_room_heating_schedule', 'start_time') }}"
"{{ state_attr('calendar.living_room_heating_schedule', 'end_time') }}"
"{{ state_attr('calendar.living_room_heating_schedule', 'description') }}

(‘start_time’ and ‘end_time’ actually yield a date time string).

However, I cannot read the summary. This does not work:

"{{ state_attr('calendar.living_room_heating_schedule', 'summary') }}"

I guessed at a few alternatives, but none of these work either

"{{ state_attr('calendar.living_room_heating_schedule', 'event_summary') }}"
"{{ state_attr('calendar.living_room_heating_schedule', 'title') }}"
"{{ state_attr('calendar.living_room_heating_schedule', 'name') }}"

Does anyone know what the ‘summary’ attribute is called?
Is this documented anywhere?
Is there a general way of reading the dictionary of attributes for an entity?

It’s


"{{ state_attr('calendar.living_room_heating_schedule', 'message') }}"

Who would have guessed? Yep. that works :+1:

So the full set of information (tested in the template editor) is

{{ states('calendar.hot_water_cylinder_heating_schedule') }} # on or off
{{ state_attr('calendar.hot_water_cylinder_heating_schedule', 'message' ) }} # event summary (name, title)
{{ state_attr('calendar.hot_water_cylinder_heating_schedule', 'description' ) }}
{{ state_attr('calendar.hot_water_cylinder_heating_schedule', 'start_time' ) }}
{{ state_attr('calendar.hot_water_cylinder_heating_schedule', 'end_time' ) }}

I also found by experiment that

  1. If there is no current event (calendar state ‘off’) then these attributes show the next scheduled event
  2. If there is a current event (calendar state ‘on’) then these attributes show that event
  3. If events overlap, i.e. a new event starts before the last one finishes, then these attributes remain those of the first scheduled event until it finishes; only then does the second event become ‘active’ in the sense of showing up in these attributes
  4. If an overlapping event finished before the one it overlaps (the one that started first) then it will never show as active
  5. (NEW) the ‘on’ State change lags the Start event by typically 4 seconds and the ‘off’ State change lags the End event by a similar amount, so…
  6. (NEW) Reading directly from the Calendar (as 1 and 2 above) yields the old data at the time of the Start and End events. So if you read at the start of an event that followed an ‘off’ period, there is no data. If you read at the start of a consecutive event, then you get the data of the first rather than the second event. If you read at the end of an event, you get the data for that event, not the consecutive or next event.
    Experimentally, I recommend waiting a full 30 seconds after the Start or End event before reading any data from the Calendar. Although I measured typically 4 seconds, repeated delays of 10 or 20 seconds allowed errors to persist.
4 Likes

Hi @pedolsky
This helped me too - so thanks a lot :slight_smile:
I’m just curious as to how you knew this - as in are there any documentation where this could be found. Either for calendar or just in general for Home Assistant. If so I’d give that a look next time tinkering with non-GUI stuff :slight_smile:

Thanks

Several days of trial and error, I’m afraid, plus the tips in this thread. :man_shrugging:
The Calendar documentation is sadly lacking in detail.

I would like to put in a feature request that the Start event and ‘on’ status occur simultaneously and that the data read from the Calendar is current at that time. Similarly the End event and ‘off’ status should occur simultaneously, with the data set (as now) to the next event.

Also, I would prefer that the current event be the one that started latest (instead of earliest), so you could piggy-back one event on top of the other - for instance to add a temporary one-off event without having to delete the regular event. However, in the case of the Heating X2 Blueprint, I dd not regard either that or the delay important enough to write special code. My workaround is to add a 30 second delay to my start and end event triggers, then read the data. That has proven experimentally reliable. I am reading the data from the Calendar rather than the trigger data because I want to access it at any time, and adding helpers to store the information (as I did in Heating X release 1) is overcomplicated.

Hey, found this thread after playing with calendar entities for the first time.

Do you know if there’s a way of finding the event after the next one?

So, I have a meal calendar. Every day an event at 3pm and another at 11pm. I launch reminders to prepare the food several hours earlier (4.30pm etc for dinner).

But on Thursdays we prepare food to take away, so actually I would like to launch the reminder for Thursday’s lunch event on Wednesdays at 8pm or so (when the actual next event is still Wed’s dinner). I’d love to have a second sensor telling me the next event after, so I can use that sensor instead for this other reminder.

this service call will allow you to get calendar events

2 Likes

Hey. This is quite an old thread and I have since learned that it is better to use the service calendar.get_events than to read the attributes. The service response data is a list of calendar events that you can sort in a template using Jijna filters. In your case sort by start time, then take the second one | [1].

See for more This posting

1 Like

Yeah, I managed! Thanks.
I defined the variables I wanted like so from the agenda response-variable of the service call.

nextdaymessage: "{{ agenda['calendar.meals'].events[1].summary }}"
nextdaydesc: "{{ agenda['calendar.meals'].events[1].description }}"

And then used those variables into my reminder message script.

1 Like