CalDav with iCloud working

Just a heads up that the new caldav component seems to be working perfectly with iCloud calendars.

You have to determine your iCloud caldav URL and I’m using two factor authentication so I created an app specific password.

Here is my config:

calendar:
  - platform: caldav
    url: !secret icloud_url
    username: !secret icloud_username
    password: !secret icloud_app_specific_password
    calendars:
      - 'Family' 

When it comes up you get some sensors you can use in automations – I’m hoping to automatically disable some wakeup routines on non school days and holidays.

8 Likes

Hi walt,

I followed your instructions, however i am getting a kind of error with the URL, i ended up with a URL like this:
https://pxx-caldav.icloud.com/1698xxxx43/principal//calendars/FF7XXXXA-DB4E-466F-87EF-XXXX1AE01E17

I use my icloud account email address as my username and for the password i have generated an app specific password.

I am running HASS 0.60.0.

Jurgen

1 Like

Ah i found the mistake, i used the wrong username :expressionless:. It is working, adding custom calendars gives me additional sensors, very very nice!!

Thanks to the guys/gals who worked on the Caldav component!

1 Like

I’m still getting “unauthorized” errors. What was the format of the username you used? Is it the full email address or just the first bit? Do we know if this works with accounts with 2 factor authentication?

User name is the email address. You will need to generate an app specific password if you have two factor enabled.

App specific password was what I needed! Thanks for the help!

Had a long time fighting out what the correct URL really is:
https://p43-caldav.icloud.com/102529920/calendars/6C2E048D-17C2-4D5E-93A1-C87D1B0A9BA7/
(I changed some numbers, this URL isn’t really mine :wink:)

And while testing I created a app specific password yesterday, it wasn’t working until I created a new one tonight. No idea if it got deleted because I never signed in with it…?!

Hope this can help someone…

1 Like

Hey there. Thanks for sharing this - helped a lot!!

Do you guys also have a problem with “all day” events?
My attributes stay empty with on of them active on a day.

If theres a start time it works well…

Just a head’s up to everyone, it appears caldav broke sometime in the latest releases. I fixed the issue by just using the older version renamed to /custom_components/calendar/caldav2.py and modified the config to use caldav2 as the platform.

Is this still broken? I managed to get this working briefly with 3 custom calendars from my iCloud calendar. They were visible on Hass and I set up the automations I wanted to drive with them. When the first event should have activated nothing happened and after restarting Hass the calendar was no longer there.

Checking the logs shows this error every time I restart:

2018-05-23 14:16:23 ERROR (MainThread) [homeassistant.components.calendar] Error while setting up platform caldav Traceback (most recent call last): 
File "/usr/src/app/homeassistant/helpers/entity_platform.py", line 129, in _async_setup_platform SLOW_SETUP_MAX_WAIT, loop=hass.loop) 
File "/usr/local/lib/python3.6/asyncio/tasks.py", line 358, in wait_for return fut.result() 
File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run result = self.fn(*self.args, **self.kwargs) 
File "/usr/src/app/homeassistant/components/calendar/caldav.py", line 89, in setup_platform cust_calendar.get(CONF_SEARCH))) 
File "/usr/src/app/homeassistant/components/calendar/caldav.py", line 111, in __init__ super().__init__(hass, device_data) 
File "/usr/src/app/homeassistant/components/calendar/__init__.py", line 72, in __init__ self.update() 
File "/usr/src/app/homeassistant/components/calendar/__init__.py", line 138, in update if not self.data or not self.data.update(): 
File "/usr/src/app/homeassistant/util/__init__.py", line 319, in wrapper result = method(*args, **kwargs) 
File "/usr/src/app/homeassistant/components/calendar/caldav.py", line 155, in update and not self.is_over(event.instance.vevent))), None) 
File "/usr/src/app/homeassistant/components/calendar/caldav.py", line 155, in <genexpr> and not self.is_over(event.instance.vevent))), None) 
File "/usr/src/app/homeassistant/components/calendar/caldav.py", line 198, in is_over WebDavCalendarData.get_end_date(vevent) 
TypeError: can't compare offset-naive and offset-aware datetimes

Any ideas?

speedyyellow,

I had exactly the same. I managed to get this working briefly with 1 custom calendar from my iCloud calendar. It was visible in homeassistant and I set up the Node-red automations I wanted to drive irrigation. When the first event should have activated nothing happened and after restarting homeassistant, the calendar has never returned. For dev, i have a daily event from 08:30 to 17:50 in the Irrigation calendar.

My configuration.

#########################################################
# calendar used to drive irrigation dates and times
# the iCloud Irrigation calendar has all of the data
# calendar event location will contain the JSON value group to run
# node-red will parse JSON and queue up each valve and duration
# queued events are sent to esp32 via mqtt
#########################################################
calendar:
  - platform: caldav
    url: https://p52-caldav.icloud.com:443/123456789/calendars
    username: userid
    password: icloudapppwd xxxx-xxxx-xxxx-xxxx
    calendars:
      - 'Irrigation'

My environment:
Ubuntu 16.04.5 LTS (GNU/Linux 4.4.0-137-generic x86_64)
home assistant 0.80.1
python 3.6.6

Logfile contents after homeassistant restart
2018-10-16 21:40:21 ERROR (MainThread) [homeassistant.components.calendar] Error while setting up platform caldav
Traceback (most recent call last):
File “/srv/homeassistant/lib/python3.6/site-packages/homeassistant/helpers/entity_platform.py”, line 128, in _async_setup_platform
SLOW_SETUP_MAX_WAIT, loop=hass.loop)
File “/usr/lib/python3.6/asyncio/tasks.py”, line 358, in wait_for
return fut.result()
File “/usr/lib/python3.6/concurrent/futures/thread.py”, line 56, in run
result = self.fn(*self.args, **self.kwargs)
File “/srv/homeassistant/lib/python3.6/site-packages/homeassistant/components/calendar/caldav.py”, line 98, in setup_platform
WebDavCalendarEventDevice(hass, device_data, calendar)
File “/srv/homeassistant/lib/python3.6/site-packages/homeassistant/components/calendar/caldav.py”, line 111, in init
super().init(hass, device_data)
File “/srv/homeassistant/lib/python3.6/site-packages/homeassistant/components/calendar/init.py”, line 89, in init
self.update()
File “/srv/homeassistant/lib/python3.6/site-packages/homeassistant/components/calendar/init.py”, line 155, in update
if not self.data or not self.data.update():
File “/srv/homeassistant/lib/python3.6/site-packages/homeassistant/util/init.py”, line 324, in wrapper
result = method(*args, **kwargs)
File “/srv/homeassistant/lib/python3.6/site-packages/homeassistant/components/calendar/caldav.py”, line 186, in update
and not self.is_over(event.instance.vevent))), None)
File “/srv/homeassistant/lib/python3.6/site-packages/homeassistant/components/calendar/caldav.py”, line 186, in
and not self.is_over(event.instance.vevent))), None)
File “/srv/homeassistant/lib/python3.6/site-packages/homeassistant/components/calendar/caldav.py”, line 229, in is_over
WebDavCalendarData.get_end_date(vevent)
TypeError: can’t compare offset-naive and offset-aware datetimes

walt,

i followed your link, copied the code from that version of caldav.py, created custom_components/calendar/caldavcust.py, and pasted the code. i still receive errors at restart. you say “the old version” worked for you?

Having trouble getting this to work:

My config is as follows:

calendar:
  - platform: caldav2
    username: !secret icloud_username
    password: !secret icloud_password
    url: !secret icloud_url
    calendars:
      - 'Jeremy (iCloud)'
      - 'Anja'
      - 'Family'

I’ve tried both the version of CalDav in the latest Home Assistant 80.3 and the “old version” as linked above and I can get the 3 calendars to show up but they contain no attributes at all.

When I look through the log I do see this…

2018-10-21 14:08:33 DEBUG (SyncWorker_6) [custom_components.calendar.caldav2] No matching event found in the 0 results for Family
2018-10-21 14:08:34 DEBUG (SyncWorker_6) [custom_components.calendar.caldav2] No matching event found in the 0 results for Jeremy (iCloud)
2018-10-21 14:08:35 DEBUG (SyncWorker_6) [custom_components.calendar.caldav2] No matching event found in the 1 results for Anja

So it looks like it can log in just fine, the URL, app specific password, and username is all good. There is something on each calendar in the future. Shouldn’t it be pulling at least one event? Any ideas?

Still trying to get this to work with my irrigation calendar in iCloud.

homeassistant: 0.86.0 – installed today.
ubuntu 16.4 – dist-upgrade done today.

a diagnostic. by changing the username, i am able to confirm that i am connecting to iCloud because when I change the username, i receive this message:

caldav.lib.error.AuthorizationError: AuthorizationError at ‘https://p52-caldav.icloud.com:443/272825453/calendars/’, reason ‘Unauthorized’

My configuration remains as presented above:

#########################################################
# calendar used to drive irrigation dates and times
# the iCloud Irrigation calendar has all of the data
# calendar event location will contain the JSON value group to run
# node-red will parse JSON and queue up each valve and duration
# queued events are sent to esp32 via mqtt
#########################################################
calendar:
  - platform: caldav
    url: https://p52-caldav.icloud.com:443/123456789/calendars
    username: myappleid
    password: icloudapppwd xxxx-xxxx-xxxx-xxxx
    calendars:
      - 'Irrigation'

The log content generated during homeassistant restart:
2018-11-11 12:48:24 ERROR (MainThread) [homeassistant.components.calendar] Error while setting up platform caldav
Traceback (most recent call last):
File “/srv/homeassistant/lib/python3.6/site-packages/homeassistant/helpers/entity_platform.py”, line 128, in _async_setup_platform
SLOW_SETUP_MAX_WAIT, loop=hass.loop)
File “/usr/lib/python3.6/asyncio/tasks.py”, line 358, in wait_for
return fut.result()
File “/usr/lib/python3.6/concurrent/futures/thread.py”, line 56, in run
result = self.fn(*self.args, **self.kwargs)
File “/srv/homeassistant/lib/python3.6/site-packages/homeassistant/components/calendar/caldav.py”, line 98, in setup_platform
WebDavCalendarEventDevice(hass, device_data, calendar)
File “/srv/homeassistant/lib/python3.6/site-packages/homeassistant/components/calendar/caldav.py”, line 111, in init
super().init(hass, device_data)
File “/srv/homeassistant/lib/python3.6/site-packages/homeassistant/components/calendar/init.py”, line 89, in init
self.update()
File “/srv/homeassistant/lib/python3.6/site-packages/homeassistant/components/calendar/init.py”, line 155, in update
if not self.data or not self.data.update():
File “/srv/homeassistant/lib/python3.6/site-packages/homeassistant/util/init.py”, line 324, in wrapper
result = method(*args, **kwargs)
File “/srv/homeassistant/lib/python3.6/site-packages/homeassistant/components/calendar/caldav.py”, line 186, in update
and not self.is_over(event.instance.vevent))), None)
File “/srv/homeassistant/lib/python3.6/site-packages/homeassistant/components/calendar/caldav.py”, line 186, in
and not self.is_over(event.instance.vevent))), None)
File “/srv/homeassistant/lib/python3.6/site-packages/homeassistant/components/calendar/caldav.py”, line 229, in is_over
WebDavCalendarData.get_end_date(vevent)
TypeError: can’t compare offset-naive and offset-aware datetimes

Is Caldav not working with iCloud at all? I have a shared calendar. No I’m using iCloud to google and show the google in HA, but the update time is way to long… 12 hours or something.

Works with 2-Factor Authentification.

  1. Get a app specific password as described here
  2. Configure configurations.yaml like below with
calendar:
  - platform: caldav
    username: [email protected]
    password: xxxx-xxxx-xxxx-xxxx
    url: https://caldav.icloud.com

No need to construct the caldav url (anymore?).

9 Likes

Great , but how to do if i have 2 icloud accounts that i want to merge in my hassio calendar?