Sync private iCloud calendar with MagicMirror

posted in: Allgemein | 0

Get app-specific password from iCloud

vdirsyncer needs an app-specific password to connect to iCloud. You can create one in your AppleID settings like descibed in Apple’s support document for using app-specific passwords:

Create one and write it down for later.

Install and set up vdirsyncer

vdirsyncer needs to be installed on the machine that hosts your mirror software. On my raspbian system, vdirsyncer was not available via apt. So I hat to install it via pip.

Installation of vdirsyncer

Now we get vdirsyncer and it’s dependencies:

sudo apt-get install libxml2 libxslt1.1 zlib1g python3
pip3 install --user --ignore-installed vdirsyncer

(This is the quick and easy way, it should suffice for most users. For a more clean way to install it, please refer to

Now, change the first line of your vdirsyncer executable to use only python3:

nano ~/.local/bin/vdirsyncer

And change the first line to #!/usr/bin/python3

I needed to create a symlink to the vdirsyncer executable. So we’re doing this:

sudo ln -s /home/pi/.local/bin/vdirsyncer /usr/bin/vdirsyncer

Now you should be able to use the vdirsyncer command from the command line.

Create a folder for the calendar file

As mentioned in this post, we can put the calendar file into the modules folder to access it via the calendar module. So we create a folder for our calendars:

mkdir /home/pi/MagicMirror/modules/calendars

Configure vdirsyncer

Create a config file in ~/.vdirsyncer/config and open it with nano:

mkdir ~/.vdirsyncer
touch ~/.vdirsyncer/config
nano ~/.vdirsyncer/config

Here’s an example configuration to use with iCloud. Just copy it into your opened file in nano and enter your iCloud credentials.

# vdirsyncer configuration for MagicMirror.
# Move it to ~/.vdirsyncer/config or ~/.config/vdirsyncer/config and edit it.
# Run `vdirsyncer --help` for CLI usage.
# Optional parameters are commented out.
# This file doesn't document all available parameters, see
# for the rest of them.

# A folder where vdirsyncer can store some metadata about each pair.
status_path = "~/.vdirsyncer/status/"

[pair iCloud_to_MagicMirror]
a = "Mirror"
b = "iCloud"

# Calendars also have a color property
metadata = ["displayname", "color"]

[storage Mirror]
# We need a single .ics file for use with the mirror (Attention! This is really slow on big amounts of events.)
type = "singlefile"
# We'll put the calendar file to a readable location for the calendar module
path = "/home/pi/MagicMirror/modules/calendars/%s.ics"

[storage iCloud]
type = "caldav"
url = ""
# Authentication credentials
# We only want to sync in the direction TO the mirror, so we make iCloud readonly
read_only = true
# We only want to sync events
item_types = ["VEVENT"]
# We need to keep the number of events low, so we'll just sync the next month
# Adjust this to your needs
start_date = " - timedelta(days=1)"
end_date = " + timedelta(days=30)"

Make sure, you use the start_date and end_date parameters to keep the number of calendar events low. I tried syncing with 700+ events and it is really really sloooooow! Especially when using the singlefile option for the mirror.

Add your iCloud credentials like shown in the config file.

Running vdirsyncer as a systemd.timer for automatic sync

Install the vdirsyncer.service and vdirsyncer.timer files to /etc/systemd/user:

curl | sudo tee /etc/systemd/user/vdirsyncer.service
curl | sudo tee /etc/systemd/user/vdirsyncer.timer

By default, the syncer is started every 15 minutes. You can change it by configuring the times in the vdirsyncer.timer file:

sudo nano /etc/systemd/user/vdirsyncer.timer

Now we activate the timer in systemd:

systemctl --user enable vdirsyncer.timer

Let vdirsyncer discover the collections and do the inital sync

Now, we have to find out, which collection we want to sync. Let vdirsyncer discover everything:

vdirsyncer discover

You should get an output like this (depending on the number of calendars you have in iCloud):

Discovering collections for pair iCloud_to_MagicMirror
  - "xxxxxxxxxxxx-A1234-B12345-C12345-xxxxxxxxxxxx" ("Calendar 1")
  - "xxxxxxxxxxxx-A1234-B12345-C12345-xxxxxxxxxxxx" ("Calendar 2")
  - "xxxxxxxxxxxx-A1234-B12345-C12345-xxxxxxxxxxxx" ("Calendar 3")
warning: No collection "HERE-GOES-THE-UUID-OF-THE-CALENDAR-YOU-WANT-TO-SYNC" found for storage Mirror.
Should vdirsyncer attempt to create it? [y/N]:

Choose N for now and press return.
Now replace the HERE-GOES-THE-UUID-OF-THE-CALENDAR-YOU-WANT-TO-SYNC in the config with the UUID of the calendar you want to sync.
We assume, we want to sync “Calendar 2”.

So line 19 of your config should look like this:

collections = ["xxxxxxxxxxxx-A1234-B12345-C12345-xxxxxxxxxxxx"] 

Now, we can run the discover again and make the first sync:

vdirsyncer discover

You should get something loke this:

Discovering collections for pair iCloud_to_MagicMirror
  - "xxxxxxxxxxxx-A1234-B12345-C12345-xxxxxxxxxxxx" ("Calendar 1")
  - "xxxxxxxxxxxx-A1234-B12345-C12345-xxxxxxxxxxxx" ("Calendar 2")
  - "xxxxxxxxxxxx-A1234-B12345-C12345-xxxxxxxxxxxx" ("Calendar 3")
warning: No collection "xxxxxxxxxxxx-A1234-B12345-C12345-xxxxxxxxxxxx" found for storage Mirror.
Should vdirsyncer attempt to create it? [y/N]:

Choose y and press enter. Now we can start the sync with:

vdirsyncer sync

You should find a single calendar file in /home/pi/MagicMirror/modules/calendars/ with the UUID of your calendar as filename like 221FEE8-E8B4-4D07-9402-8638529919EC.ics in this example.

Add the calendar file to the calendar module of the mirror

Now, we just have to add the URL to the calendar file to our calendar module of the mirror like this:

    module: 'calendar',
    position: 'top_left',   // This can be any of the regions. Best results in left or right regions.
    config: {
        maximumNumberOfDays: 10,
        maximumEntries: 7,
        calendars: [
                        url: 'http://localhost:8080/modules/calendars/xxxxxxxxxxxx-A1234-B12345-C12345-xxxxxxxxxxxx.ics', symbol: 'calendar' } ] } }, 

If everything went well, your MagicMirror is now automatically syncing your iCloud calendar with it’s calendar module