šŸ“… Calendar Add-On + some calendar designs

Im sorry for my missed excerpt out of my caldav, but i used the time to get a bit used to your addon and i wanted to share my setup with all of you.

So one snippet out of my use case is that i combine two calendars dedicated to hold trash dates for different places (here lambsheim and frankenthal). Also i Filter all the events to only hold events in the upcoming week, search in there name for a matching trash type and give them a symbol and shortname.
I think this way i would be possible to get a neat integration of trashdays from different serviceholders via the exported trashlists - mine let them export directly to CalDav so this is seamlessly easy.

          {% set d1 = states.sensor.cal_frankenthal.state %}
          {% set d2 = states.sensor.cal_lambsheim.state %}
          {% set d3 = ((d1|int)+(d2|int)) %}
          {% set a = states.sensor.cal_frankenthal.attributes.data %}
          {% set b = states.sensor.cal_lambsheim.attributes.data %}
          {% set i = (a + b) | sort(attribute='endDate')%}
          {% for h in i%}
          {% set filter = (((as_timestamp(h.endDate) - as_timestamp(now())) / 60) | int)  %}
          {% if filter < 10080 %}
          {%- if  loop.first %}[ {% endif %} { "name": '{{loop.index}}',{%- if 'Frankenthal' in h.description -%}  "location": 'FT',{%- elif 'Lambsheim' in h.description -%}"location": 'LA',{% endif%}{%- if 'Altpapier' in h.description -%}  "symbol": 'šŸŸ¦', "trash": "Papier",{%- elif 'Schadstoff' in h.description -%}"symbol": 'šŸŸ„',"trash": "Schadstoffe",{%- elif 'Restabfall' in h.description -%}"symbol": 'ā¬›',"trash": "Restabfall",{%- elif 'Wertstoffe\, Bioabfall' in h.description -%}"symbol": 'šŸŸØšŸŸ«',"trash": "Papier & Plastik", {%- elif 'Abfuhr' in h.description -%}"symbol": 'šŸŸ«', "trash": "Bio",{%- endif %} "summary": '{{h.description}}', "minutes_till": {{((as_timestamp(h.endDate) - as_timestamp(now())) / 60) | int }},"state": {{d3}}, "start_time": '{{h.start_day}}.{{'%02d' % h.start_month_digits}}.{{h.year}} {{h.start_time}} Uhr', "time_z": '{{h.startDate[:-14]}} {{h.start_time}} - {{h.end_time}}' } {%- if not loop.last %},{% endif -%}
          {%- else -%}
          {%- endif %}
          {%- endfor %}]

after that i just put them in a markdowncard an let this be displayed as follows:

<b>Termine Frankenthal & Lambsheim</b>
| | |  
|:---:|:---|
{% for i in states.sensor.upcoming_events.attributes["object_lauft"] %}{% if i["summary"] == NULL %}
{%- else -%}
| {{i["symbol"]}} | <b>{{i["trash"]}} {{i["location"]}} |
| |{{ i["start_time"] }} | |
| |noch  {{ i["minutes_till"] }} Minuten | |
{%- endif %}
{% endfor %}

Bildschirmfoto 2022-05-13 um 09.05.40

Im still having issues with the startDate and endDate of the calendar integration - but this finally is my fault cause i hadnt had the time to export my log for you - sorry for that again.

Greetings=)

I do that, but what is the next step?

Frontend ā€¦

screenb

Hallo Bernd,

it sounds like youā€™re not familiar with sensor data, templating or the developer tools of Home Assistant. You will need to familiarize yourself with those concepts if you want to use your calendar data somewhere.

Your screenshot indicates that the addon is working properly, navigate to the dev-tools and search for the name you gave your calendar there. It should look something like this:

In my addon documentation Iā€™ve linked to the Home Assistant documentation about templating. You can test your templating syntax in the dev tools too, like this:

The post before yours in this thread by user Flipso contains an example of some more complex templating syntax inside a markdown card.

Personally Iā€™m not very fond of the jinja templating syntax that Home Assistant uses and prefer to write javascript for this instead. You can do this inside a custom button card. In my initial post in this thread I link to two example custom button cards.

Eitherway if youā€™re not familiar with scripting languages youā€™ll have a bit of a learning curve ahead Iā€™m afraid.

Hello, do recurring full day events work with that?

I would like an automation to behave differently depending on which full day event is active.

The default caldav integration is not able to detect recurring full day eventsā€¦

Recurring events will have the recurring: true attribute.

However I remember from testing with a birthday that I still needed to fix some things. I donā€™t remember exactly, but I think the year may be incorrect in the sensor data now if the event has been in your calendar for several years. Itā€™s on my to-do list to investigate and fix this sometime.

hi @EdwardEnglish, sorry my memory failed me, the recurring events attribute is currently only there for google calendar events, not for events from a caldav calendar. I do plan on adding support for recurring events, but canā€™t say when I will find time to work on it. I did start reading up on the documenation and having a look at examples. It seems like the most complex bit here will be calculating the current applicable date of a recurring event as the data gives you the initial date and a recurrence format, not a ready made list of future dates.

Hello @kdw2060
I try to setup your addon for my google calendar but I am struggling a bit. I have a few questions.
My config looks like this:

locale: de
fetchDays: 5
fetchCRON: '*/30 * * * *'
calendarList:
  - calName: Geburtstage
    calType: google
    calId: xxxxxxxxxxxxx
    googleServiceAccountKeyfile: google_credential.json

The log tells me the following:

23 packages are looking for funding
  run npm fund for details
found 0 vulnerabilities
Calendar(s) queried at: Wed Jul 13 2022 01:30:00 GMT+0200 (Central European Summer Time)
postEventsAllCalendars error: TypeError: Cannot read properties of undefined (reading 'length')
CRON-Task: Events posted to sensor(s) at: Wed Jul 13 2022 01:30:00 GMT+0200 (Central European Summer Time)
There was an error loading the gcal data: Error: No key or keyFile set.

So I guess this one ā€œgoogleServiceAccountKeyfileā€ is wrong.

I copied it to \share
Is the folder name needed for the attribute as well?

Then I have a question regarding the addon folder. There should be the data folder with the allFutureEvents.json.

I installed your addon (as well as all other installed addons) directly via the admin UI in Home assistant. When I go to \addons the folder is empty. There is no file or directory inside. So I am wondering if this was the right way to copy my credential files to the \share folder.

And I saw something that I need to provide my service account email to my calender and share the calender with this email. But I donā€™t know where do I get this service account email?

Your configuration looks good, no errors there as far as I can see (I cannot know if your calId is correct off course). The \share folder is not a subfolder of addons, itā€™s a seperate standard folder in the HA folder structure (see this earlier reply).

As the loading of the events failed itā€™s logical there is no allFutureEvents.json file yet.

The service-account email was presented to you when you made the service account, but is also visible inside the service-account json file. Just open it with a text editor and copy paste te e-mail. How to share a calendar with that e-mail adress is shown in this earlier reply.

I think you might not have placed the serviceaccount json file in the right folder and/or you didnā€™t share the calendar with the service-account e-mail adress.

@kdw2060
OK, I used a wrong json file.
I think I now have the correct file, but I am not able to retrieve events:

found 0 vulnerabilities
Previously stored events posted to sensor(s) at: Wed Jul 13 2022 12:28:49 GMT+0200 (Central European Summer Time)
postEventsAllCalendars error: TypeError: Cannot read properties of undefined (reading ā€˜lengthā€™)
Calendar(s) queried at: Wed Jul 13 2022 12:30:00 GMT+0200 (Central European Summer Time)
postEventsAllCalendars error: TypeError: Cannot read properties of undefined (reading ā€˜lengthā€™)
CRON-Task: Events posted to sensor(s) at: Wed Jul 13 2022 12:30:00 GMT+0200 (Central European Summer Time)
There was an error loading the gcal data: Error: Not Found

I think there was a typo in the calendar ID. Now there is just the error with Cannot read properties of undefined.

Calendar(s) queried at: Wed Jul 13 2022 12:40:00 GMT+0200 (Central European Summer Time)
postEventsAllCalendars error: TypeError: Cannot read properties of undefined (reading 'length')
CRON-Task: Events posted to sensor(s) at: Wed Jul 13 2022 12:40:00 GMT+0200 (Central European Summer Time)

But I donā€™t know what else can I do.

Is it correct, that it should show up under the entity: sensor.. So in my case sensor.Geburtstage ?

Ok, after a restart the sensor shows up. Thank you for your support

Hello, The baikal and caldav woking without plugin install? My Hass Calendar working in caldav mode whitout error, but the sensor data emply.
Thx

I donĀ“t use baikal myself, so I canā€™t set up tests for that. From the other users that do use Baikal I understand that that baikal plugin that is mentioned in the docs is not required if you choose ā€˜caldavā€™ as calendar type indeed.

If your calendar is empty thatā€™s probably a config issue. To not annoy the other users here I suggest you post your config settings in the github-issue that you re-opened. Iā€™ll see if thereā€™s a glaring issue visible there.

After being disappointed with the default Google Calendar integration (because you can only see one event per calendar), I was excited to find this earlier today.

I have a personal calendar and a work calendar. I was able to get them to both show up using your Calendar Add-On. Amazing!

1
There didnā€™t seem to be any way to read my work calendar that had been shared with my personal calendar, so I had to set up another json file for it too. Was there any easier way?

2
Is there any way to merge them into a single sensor?
(perhaps with each event having a field showing the calendar origin)

Iā€™d like to grab the 4 next events regardless of which calendar theyā€™re on. I could read in the next 4 events from both calendars and then sort that by date and throw out the last 4.

A single sensor would be much easier for this use case.

3
I could never get the en localization to work (so went with en-ca). Tried multiple times, seems missing (same error the person shared earlier where they were also using en)

4
My startdate is showing up like:

    startDate: '2022-08-24T00:00:00.000Z'
    year: 22
    start_month: Aug
    start_day: 23
    start_time: '17:00'
    start_month_digits: 8
    endDate: '2022-08-24T00:50:00.000Z'

But the event starts at 17:00 on 8-23
Iā€™d expect it to be:
2022-08-23 17:00:00
So it could be used to trigger an automation.
Is this because my localization is wrong? Thoughts?

5
This is so great! Iā€™ve got my next 3 meetings showing up on my dashboard (with heavy use of the custom:button-card)

You mean an extra Google service account? If the work calendar and personal calendar are both calendars under the same Google account that shouldnā€™t be necessary. Off course if you use two seperate Google accounts then probably yes. Iā€™d have to delve into the google api documentation and do some tests to find out exactly if itā€™s possible to share calendars between 2 accounts in such a way that one service account can access them.

2
Is there any way to merge them into a single sensor?
(perhaps with each event having a field showing the calendar origin)

Iā€™d like to grab the 4 next events regardless of which calendar theyā€™re on. I could read in the next 4 events from both calendars and then sort that by date and throw out the last 4.

A single sensor would be much easier for this use case.

That could be done, but I donā€™t see it becoming a priority on my to do list anytime soon. Am currently mainly working on improving how recurring events are handled. Like you said, handling this yourself with frontend-code in the card is the way to achieve this now.

Iā€™m also busy switching from moment.js to Luxon, paying extra attention to possible date-time mishaps. That should hopefully help to fix both those issues.

Hi
I try to use this add on with nextcloud but without success.
This is my config :

- calName: nextcloudThomas
  calType: caldav
  username: $username
  password: $password
  caldavUrl: https://$domain/remote.php/dav/calendars/admin/personal/

Logs are good

Calendar(s) queried at: Wed Sep 14 2022 09:30:12 GMT+0200 (Central European Summer Time)
CRON-Task: Events posted to sensor(s) at: Wed Sep 14 2022 09:30:12 GMT+0200 (Central European Summer Time)
Calendar(s) queried at: Wed Sep 14 2022 10:00:12 GMT+0200 (Central European Summer Time)
CRON-Task: Events posted to sensor(s) at: Wed Sep 14 2022 10:00:12 GMT+0200 (Central European Summer Time)
Calendar(s) queried at: Wed Sep 14 2022 10:30:12 GMT+0200 (Central European Summer Time)
CRON-Task: Events posted to sensor(s) at: Wed Sep 14 2022 10:30:12 GMT+0200 (Central European Summer Time)

But senor.nextcloudThomas is not created.

Thanks for your help

Hi @elyisum , it seems as if no events are retrieved, and hence no sensor created.
Itā€™s hard to guess whatā€™s going on here. Are you familiar with Postman or similar tools with which to test api-calls? Iā€™d need the response of those to understand whatā€™s going on here.
In this earlier support issue on github you find some screenshots and explanation about working with postman (ignore the apple/icloud specific stuff)

Hi @kdw2060
I installed postman, for now, I only have an error 500.
I continue my researchs

Edit, now I get

    <s:exception>Sabre\DAV\Exception\BadRequest</s:exception>
    <s:message>A calendar-query REPORT on a calendar with a Depth: 0 is undefined. Set Depth to 1</s:message>

New edit:
If I add Depth 1 in header, now i have a status 207
I donā€™t know what this tatus means

<?xml version="1.0"?>
<d:multistatus xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns" xmlns:cal="urn:ietf:params:xml:ns:caldav" xmlns:cs="http://calendarserver.org/ns/" xmlns:oc="http://owncloud.org/ns" xmlns:nc="http://nextcloud.org/ns"/>

If you want, I can create an account for you on my nextcloud so you can make some tests

Hi @ thundergreen
Did you managed to retrieve the events from nextcloud ?

The 207 reponse is good, only the response doesnā€™t return any events for some reason. Most obvious reason could be the date-range in the request body doesnā€™t contain events. Else having access to a test account may be handy in deed. You can send me a DM, but I canā€™t make any promises when I will find the time to work on it. Might be some months.

Hi @kdw2060, bumped on this, browsed through topic and on GH but couldnā€™t find an answer.
I run HA core, so without add on store, and use nextcloud: I wonder if there is a way to get this working for my case?