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

Hello everyone,

For me it works now.

But the ā€œcaldavUrl:ā€ setting should not be
ā€œhttps://pXX-caldav.icloud.com/{DSid}/calendars/{pGUID}ā€ or
ā€œhttps://pXX-caldav.icloud.com/{DSid}/calendars/{calendarName}ā€
but
ā€œhttps://pXX-caldav.icloud.com/{DSid}/calendars/{GUID}ā€.

This way I receive all data very well.

However, if I
https://pXX-caldav.icloud.com/{DSid}/calendars/{pGUID} or
ā€œhttps://pXX-caldav.icloud.com/{DSid}/calendars/{calendarName}ā€
I keep getting
Ā“Ā“Ā“Ā“
axios error: [object Object]Request failed with status code 404
Ā“Ā“Ā“Ā“
error message.

At least this way it works for me!!

Thank you to all the people who gave me a little feedback!!

Edit 3:
For whoever is experiencing the same thing: Iā€™ve reinstalled everything once again. Removed the addon completely and installed it again. The first fetch didnā€™t succeed as more people experience but this is an known issue. The second fetch did actually work and the sensor is created.

The addon is super sensitive for typoā€™s so please check, dubbel check and triple check everything. For me it seems to work now. Thanks for all the help!!


Iā€™ve tried multiple things. Removing all recurring events without end date. Making the fetch period smaller. Removing the service account and creating a new one but with no result. The error has changed however.

Do you have any suggestions on what the issue could be?

---------
edit2:

I have once again reinstalled everything. Removed the addon and configured it all again. It seems the error has gone for now but no sensors are created.

</s> <s>s6-rc: info: service s6rc-oneshot-runner: starting</s> <s>s6-rc: info: service s6rc-oneshot-runner successfully started</s> <s>s6-rc: info: service fix-attrs: starting</s> <s>s6-rc: info: service fix-attrs successfully started</s> <s>s6-rc: info: service legacy-cont-init: starting</s> <s>cont-init: info: running /etc/cont-init.d/00-banner.sh</s> <s>-----------------------------------------------------------</s> <s> Add-on: Hass Calendar Addon</s> <s> Addon to consume caldav and google calendars and make calendar events available as sensordata in Home Assistant.</s> <s>-----------------------------------------------------------</s> <s> Add-on version: 0.301</s> <s> You are running the latest version of this add-on.</s> <s> System: Home Assistant OS 9.5 (aarch64 / raspberrypi4-64)</s> <s> Home Assistant Core: 2023.4.6</s> <s> Home Assistant Supervisor: 2023.04.1</s> <s>-----------------------------------------------------------</s> <s> Please, share the above information when looking for help</s> <s> or support in, e.g., GitHub, forums or the Discord chat.</s> <s>-----------------------------------------------------------</s> <s>cont-init: info: /etc/cont-init.d/00-banner.sh exited 0</s> <s>cont-init: info: running /etc/cont-init.d/01-log-level.sh</s> <s>cont-init: info: /etc/cont-init.d/01-log-level.sh exited 0</s> <s>s6-rc: info: service legacy-cont-init successfully started</s> <s>s6-rc: info: service legacy-services: starting</s> <s>s6-rc: info: service legacy-services successfully started</s> <s>added 80 packages, and audited 81 packages in 15s</s> <s>23 packages are looking for funding</s> <s> run `npm fund` for details</s> <s>found 0 vulnerabilities</s> <s>npm notice </s> <s>npm notice New minor version of npm available! 9.1.2 -> 9.6.5</s> <s>npm notice Changelog: <https://github.com/npm/cli/releases/tag/v9.6.5></s> <s>npm notice Run `npm install -g [email protected]` to update!</s> <s>npm notice </s> <s>System locale: en-US</s> <s>Luxon locale set to: nl-NL</s> <s>System timeZone: Europe/Amsterdam</s> <s>Luxon timezone set to: Europe/Amsterdam</s> <s>no previously stored options found</s> <s>Calendar(s) queried at: Wed Apr 26 2023 12:15:00 GMT+0200 (Central European Summer Time)</s> <s>postEventsAllCalendars error: TypeError: Cannot read properties of undefined (reading 'length')</s> <s>Events posted to sensor(s) at: Wed Apr 26 2023 12:15:00 GMT+0200 (Central European Summer Time)</s> <s>1 entries found in google calendar</s> <s>Fetching google calendar entry c8r3cpb565im2bb66kp3ab9kc4o34b9oc9ijcbb6ccp68c1gc5h62dpkcg</s> <s>

any idea on what the problem is?

After much searching I found this addon has it read the calendar to a sensor
but get no times in the sensor



Can you see whats wrong in my config?

You can leave out the username, password and cadavUrl fields as youā€™re using a google calendar, but that will not be the cause of the issue youā€™re having. When I look up the BCP-47 locale standard for Sweden it says itā€™s ā€˜sv-SEā€™, so with capitals for SE. Could be that the Luxon library is really strict and needs you to enter it that way.

1 Like

Thanks for the addon which I have managed to get returning data from my google calendar.

Iā€™m now stuck on what to do next - I would like a card on my dashboard to display the date of a specific event, e.g. ā€œTeam catchupā€. Iā€™m assuming I need to search for that text within the summary attributes but I donā€™t know how I would then retrieve the date that goes with the right summary.

I have no experience with jinja or java so I donā€™t really know what to Google search for to help me. If anyone can help with the code, or can point me to a set of tutorials that would help I would be grateful.

For your purpose the standard google calendar integration might actually be the easier route. It is built around the idea of searching for an event as a trigger, then doing something (for instance display the event info).
More info here: Calendar - Home Assistant

As for the jinja template (also required to write one with the standard integration): use chat-gpt, tell it what the data looks like (copy-paste an example from the event yaml) and tell it what you want to do. Chat-gpt and the like are great at rendering python code (jinja comes from the python world)

I thought I might have this sorted but Iā€™m still struggling. Iā€™ve come up with this code:

alias: Team Catchup
description: ""
trigger:
  - platform: calendar
    event: start
    offset: "-2400:0:0"
    entity_id: calendar.work
condition:
  - condition: template
    value_template: "{{ 'Catch' in trigger.calendar_event.summary }}"
action:
  - service: input_datetime.set_datetime
    data_template:
      entity_id: input_datetime.teamcatchup
      date: >
        {% set date_time = as_timestamp(trigger.calendar_event.start) %}
        {{ date_time | timestamp_custom("%Y-%m-%d", true) }}
mode: single

but I am getting this error:
Error: In ā€˜templateā€™ condition: UndefinedError: ā€˜dict objectā€™ has no attribute ā€˜calendar_eventā€™

The huge offset is to catch anything in the next three months.

Iā€™ve run it through ChatGPT a few times but all the revisions it comes back with bring up similar errors. Where am I going wrong?

This add-on works for my personal calendar, but I also have a calendar of my girlfriend which is shared with me. I canā€™t make this add-on work with the shared calendar. If I login to her Google account, she can view my project, what am I missing?

This is in the logs of the add-on:
There was an error loading the gcal data: Error: Not Found

My config:

- calName: google_mine
  calType: google
  calId: [email protected]
  googleServiceAccountKeyfile: SERVICE_ACCOUNT.JSON
- calName: google_girlfriend
  calType: google
  calId: [email protected]
  googleServiceAccountKeyfile: SERVICE_ACCOUNT.JSON

Her calendar is ofcourse shared with mine, with the correct e-mail of the service account. Am I missing something? Will this add-on never work with shared Calendars? Does my girlfriend needs to create her own project + service json file?

Edit:
My girlfriend had to share her calendar with the e-mail of the service account, which was not a person email but an email created by google which I found under ā€˜client-emailā€™ in the json file. This fixed the problem!

That looks like an automation. Thatā€™s a possible route to go, but a jinja template like the part you have under action:date (but more elaborate) should suffice.
You can experiment with templates in the developer tools > templates section of Home Assistant until you get a working template, then use that inside a card.
Iā€™m not a big fan or user of jinja templates, so canā€™t really help you quickly, hope another user with more knowledge sees this and can help you.

This Add-On is incredible, really appreciate the card examples too! Thanks!

Iā€™ve got the OnePerson card working really nicely, felt like it was pretty simple to set up.

Iā€™d love to use the FamilyPlanner card but I donā€™t know where to start. Is there documentation anyware showing how to set this up?

Iā€™ve attempted to change the ā€œcalendar.replaceā€ elements with my calendards but I didnā€™t get anything working.

Thanks in advance!

The sample FamilyPlanner card just needs a few parts replacing to get working. It looks like it may have been made before the addon was updated changing the names of the entities within the calendar sensor data.

If you havenā€™t figured this out already, heres the variables you need to change to get it working.

start_month ā†’ startMonth
start_day ā†’ startDay
start_time ā†’ startTime
whole_day ā†’ wholeDay

The readme file on shows a list of the other names available if you need to access anything else for your calendar.

I found changing the dashboard to a panel made the card far more usable too, however only one card can be displayed when using this, so best to do it in a new dashboard.

views:

  • title: Calendar
    panel: true
1 Like

Is it possible to use this add-on with public calendars?

I tried a simple configuration that just had:

calName: calendar
calType: google
calId: <google ID from calendar>@import.calendar.google.com

The add-on start-up works, but fails when it goes to fetch the calendar.

postEventsAllCalendars error: TypeError: Cannot read properties of undefined (reading 'length')
...
Error: ENOENT: no such file or directory, open '/share/undefined'
...
  errno: -2,
  syscall: 'open',
  code: 'ENOENT',
  path: '/share/undefined'

Iā€™m guessing itā€™s failing trying to read the googleServiceAccountKeyfile?

The calendar is public and is readable in any web browser without google authentication. Is there a way to make this work without the service account?

Thanks in advance!

EDIT:

I modified the code to take out the authorization and it fails. Iā€™m guessing Google doesnā€™t allow use of the API without the service account. Which seems unreasonable since the calendar is public in every way.

"Calendar(s) queried at: Fri Nov 10 2023 12:09:00 GMT-0500 (Eastern Standard Time)
Events posted to sensor(s) at: Fri Nov 10 2023 12:09:00 GMT-0500 (Eastern Standard Time)
There was an error loading the gcal data: Error: The request is missing a valid API key."

No, this addon wasnā€™t written to support public calendars. Including support would be possible, but thatā€™s a change request I would need to find time for to implement. Feel free to open an issue on the addonā€™s Github repository as a reminder.

Thank you for the reply!

As an attempted workaround I watched the network traffic to the google public calendar, and got a URL which uses a valid API key to the JSON object.

When I load that URL in a browser, I get the calendar JSON object as it passes the same arguments used by the google.calendar API.

e.g.:

https://clients6.google.com/calendar/v3/calendars/<google calendar ID redacted>/events?calendarId=<google calendar ID redacted>&singleEvents=true&timeZone=America%2FNew_York&key=<API key>&orderBy=startTime&timeMin=2023-11-10T00%3A00%3A00-05%3A00

So I tried modifying your code to fetch the JSON directly via the URL. I added jquery to the package.json dependencies

"jquery": "^3.7.1"

added it to the prerequisites in index.js

const jQuery = require("jquery");

Defined the calendarURL and modified the fetch routine to call the jquery library (instead of the google.calendar call)

jQuery.getJSON(calendarURL,
        function (err, res) {
          if (err) {
            console.log("There was an error loading the gcal data: " + err);
            return;
          }
...

But when the add-on tries to execute it, it doesnā€™t find getJSON for some reason.

Events posted to sensor(s) at: Sat Nov 11 2023 13:28:00 GMT-0500 (Eastern Standard Time)
/index.js:434
	  jQuery.getJSON(calendarURL,
	         ^

TypeError: jQuery.getJSON is not a function
    at /index.js:434:11
    at Array.forEach (<anonymous>)
    at getEvents (/index.js:58:24)
    at Task._execution (/index.js:564:11)
    at Task.execute (/node_modules/node-cron/src/task.js:17:25)
    at ScheduledTask.now (/node_modules/node-cron/src/scheduled-task.js:38:33)
    at Scheduler.<anonymous> (/node_modules/node-cron/src/scheduled-task.js:25:18)
    at Scheduler.emit (node:events:513:28)
    at Timeout.matchTime [as _onTimeout] (/node_modules/node-cron/src/scheduler.js:30:26)
    at listOnTimeout (node:internal/timers:559:17)

Not sure why that isnā€™t found in jquery, but Iā€™m a novice at home assistant, so maybe Iā€™m missing something.

In any case, Iā€™ll add the request to the Github repository and if you get around to it I can provide the google public URL and the direct URL to the calendar JSON it returns.

Thank you!

According to the documentation you need to create some sort of virtual window too when using jquery in nodeJS.

But anyway, no need to rely on jquery for what youā€™re trying to do. The request can be made with Axios which is already included in the project and the data can be parsed similarly to how the current google calendar data is parsed.

btw, the cheerio-library which is also already included is a jquery compatible solution for nodeJS, but I use that for parsing xml or html data, no need to use it when dealing with json-data.

New version released

0.400 | 2024-02-02

:construction: BREAKING CHANGES

  • Google calendar: I followed Home Assistantā€™s new guidelines for addons and moved the location of the Google Service Account keyfile to the new addon_config folder that is the new proper place for files required by an addon. This means existing users will need to move their keyfile from the share folder to addon_configs/hass_calendar_addon (more info in DOCS).
  • Baikal jcal support deprecated! If you use this add-on with a Baikal calendar, you can no longer use the ā€˜baikalā€™ type in the config. This option relied on the Baikal jcal plugin to provide data. I have no instance to test against and keep everything working when I introduce new features, so decided to deprecate this option. You can still use the ordinary ā€˜caldavā€™ type to process Baikal calendars.

:gift: NEW
Caldav: extra datafields for certain events as requested by some users:

  • yearly recurring events will have an originalStartYear field now too
  • full day events (without start or end time) that span multiple days will have a multiDay = true field and the endDate fields will contain data as well

:bug: BUGFIXES

  • Async logic fixed, the first fetch run should no longer log an error when posting events to the sensor.
  • Should not crash anymore on missing previous events file.

Hi,

Thanks for creating this addon. Can you help with error?Iā€™m running 0.400 version. I copied my json file to ā€œaddon_configs/hass_calendar_addonā€.

Error posting events to sensor(s) at: Sat Feb 10 2024 07:30:00 GMT-0500 (Eastern Standard Time)
Error: ENOENT: no such file or directory, open '/config/sonic-choir-299003-913e6bf0351b.json'
    at Object.openSync (node:fs:596:3)
    at Object.readFileSync (node:fs:464:35)
    at /index.js:320:37
    at new Promise (<anonymous>)
    at getEvents (/index.js:65:10)
    at Task._execution (/index.js:495:27)
    at Task.execute (/node_modules/node-cron/src/task.js:17:25)
    at ScheduledTask.now (/node_modules/node-cron/src/scheduled-task.js:38:33)
    at Scheduler.<anonymous> (/node_modules/node-cron/src/scheduled-task.js:25:18)
    at Scheduler.emit (node:events:517:28) {
  errno: -2,
  syscall: 'open',
  code: 'ENOENT',
  path: '/config/sonic-choir-299003-913e6bf0351b.json'
}

Thank you!

In my case I noticed the addon_configs subfolder for my addon also had a prefix auto-added by Home Assistant. But I run a supervised install on Debian with unsupported Docker config, so maybe thatā€™s down to that specific configuration. Anyway have a look at the addon_configs folder and see if this is the case for you too. My instruction to place the keyfile in addon_configs/hass_calendar_addon is based on Home Assistantā€™s documentation, but I ended up placing it in addon_configs/{prefix}hass_calendar_addon.

1 Like

I finally got around to doing this and that fixed that error. Thank you. I unfortunately have another error if you could help troubleshoot.

Error in getEvents: ReferenceError: err is not defined
    at /index.js:403:72
Error posting events to sensor(s) at: Sat Feb 17 2024 12:30:00 GMT-0500 (Eastern Standard Time)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
ReferenceError: err is not defined
    at /index.js:403:72
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Thanks you for your help!

I see, a typo in my code to render the error message. Please open an issue on Github so I donā€™t forget to fix it.
But this signals that the fetching of the google calendar has failed (regardless of the typo that gives that error message), so something else in your config is probably wrong.

btw, I also want to fix update issues some people have, so will only push fix when thatā€™s ok too.