• Recent
  • Tags
  • Unsolved
  • Solved
  • MagicMirror² Repository
  • Documentation
  • 3rd-Party-Modules
  • Donate
  • Discord
  • Register
  • Login
MagicMirror Forum
  • Recent
  • Tags
  • Unsolved
  • Solved
  • MagicMirror² Repository
  • Documentation
  • 3rd-Party-Modules
  • Donate
  • Discord
  • Register
  • Login
A New Chapter for MagicMirror: The Community Takes the Lead
Read the statement by Michael Teeuw here.

Sync private iCloud calendar with MagicMirror

Scheduled Pinned Locked Moved Tutorials
160 Posts 57 Posters 282.6k Views 64 Watching
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    Beh
    last edited by Beh Apr 14, 2019, 11:48 PM Oct 21, 2017, 3:31 PM

    A while ago, I posted a thread for syncing an iCloud calendar with MagicMirror. Unfortunately this solution was just a workaround and you needed to use a Mac which is also synced with your calendar. It was far from being a nice solution.

    I just found out that the tool I was using (vdirsyncer) also supports syncing with iCloud. I wrote a detailed walkthrough for this.

    I’ll re-post this part from the original post:

    Why doing it this way?

    I don’t want my calendar to be available via a public URL like mentioned in the iCloud calendar thread. Even though the public sharing address is quite long, web crawlers can still find them and your private life is publicly available. I just don’t like that scenario. So I wanted a solution that uses encryption and authentication against all services.


    So here’s a really nice solution to sync the mirror with iCloud (privately):

    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: https://support.apple.com/en-us/HT204397

    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 https://vdirsyncer.pimutils.org/en/stable/installation.html#the-clean-hard-way)

    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
    # http://vdirsyncer.pimutils.org/ for the rest of them.
    
    [general]
    # A folder where vdirsyncer can store some metadata about each pair.
    status_path = "~/.vdirsyncer/status/"
    
    # CALDAV Sync
    [pair iCloud_to_MagicMirror]
    a = "Mirror"
    b = "iCloud"
    collections = ["HERE-GOES-THE-UUID-OF-THE-CALENDAR-YOU-WANT-TO-SYNC"]
    
    # 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 = "https://caldav.icloud.com/"
    # Authentication credentials
    username = "YOUR-ICLOUD-EMAIL-ADDRESS"
    password = "HERE-GOES-YOUR-APP-SPECIFIC-ICLOUD-PASSWORD"
    # 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 = "datetime.now() - timedelta(days=1)"
    end_date = "datetime.now() + 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 https://raw.githubusercontent.com/pimutils/vdirsyncer/master/contrib/vdirsyncer.service | sudo tee /etc/systemd/user/vdirsyncer.service
    curl https://raw.githubusercontent.com/pimutils/vdirsyncer/master/contrib/vdirsyncer.timer | 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
    Mirror:
    iCloud:
      - "25CB285C-E163-4E0E-B420-C3FB469B7C00" ("Calendar 1")
      - "9221FEE8-E8B4-4D07-9402-8638529919EC" ("Calendar 2")
      - "953A5477-E405-4ED6-A5C3-473444EACC95" ("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 = ["9221FEE8-E8B4-4D07-9402-8638529919EC"]
    

    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
    Mirror:
    iCloud:
      - "25CB285C-E163-4E0E-B420-C3FB469B7C00" ("Calendar 1")
      - "9221FEE8-E8B4-4D07-9402-8638529919EC" ("Calendar 2")
      - "953A5477-E405-4ED6-A5C3-473444EACC95" ("Calendar 3")
    warning: No collection "9221FEE8-E8B4-4D07-9402-8638529919EC" 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/221FEE8-E8B4-4D07-9402-8638529919EC.ics',
                            symbol: 'calendar'
                    }
            ]
        }
    },
    

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

    S G S K 4 Replies Last reply Dec 26, 2017, 5:41 AM Reply Quote 7
    • S Offline
      spesh
      last edited by Oct 21, 2017, 9:26 PM

      Does this allow the option for different icons for different calenders? I’m just starting to build mine and would like to sync two seperate iCloud calenders and have them display with different icons/colours

      B 1 Reply Last reply Oct 22, 2017, 12:52 AM Reply Quote 0
      • B Offline
        Beh @spesh
        last edited by Oct 22, 2017, 12:52 AM

        @spesh

        Yes, this should allow multiple coloured calendars.
        You just have to add the UUIDs for each calendar you want to sync to the collections array in your vdirsyncer config.
        This should create multiple .ics files. One for each calendar. Then you could add each calendar to your MagicMirror config and use the color option described in the default calendar module for your calendars. Just add the colored option to your “global” module config and add a color option to each calendar.

        A calendar config could look like this then (for “Calendar 1” and “Calendar 2” as described above):

        {
            module: 'calendar',
            position: 'top_left',   // This can be any of the regions. Best results in left or right regions.
            config: {
                colored: true,   // Activate coloring
                maximumNumberOfDays: 10,
                maximumEntries: 7,
                calendars: [
                        // "Calendar 1"
                        {
                                url: 'http://localhost:8080/modules/calendars/25CB285C-E163-4E0E-B420-C3FB469B7C00.ics',
                                symbol: 'calendar'
                                color: '#123456'   // Assign color
                        },
                        // "Calendar 2"
                        {
                                url: 'http://localhost:8080/modules/calendars/221FEE8-E8B4-4D07-9402-8638529919EC.ics',
                                symbol: 'calendar'
                                color: '#ABCDEF1'  // Assign color
                        }
                ]
            }
        },
        
        G A 2 Replies Last reply Jan 17, 2018, 7:25 PM Reply Quote 0
        • D Offline
          Doubleve
          last edited by Oct 22, 2017, 1:36 PM

          hello how do we get the links calendars icloud thank you

          B 1 Reply Last reply Oct 22, 2017, 1:40 PM Reply Quote 0
          • B Offline
            Beh @Doubleve
            last edited by Oct 22, 2017, 1:40 PM

            @Doubleve What do you mean?

            1 Reply Last reply Reply Quote 0
            • D Offline
              Doubleve
              last edited by Doubleve Oct 22, 2017, 1:54 PM Oct 22, 2017, 1:47 PM

              I will like my 3 calendars icloud but I do not see the links of the style
              https://p02calendars.icloud.com/published/2/xxxxxxxxxxxxxxxxxxxxxQhtoAvoFiIwGI1
              To have UUID

              B 1 Reply Last reply Oct 22, 2017, 1:52 PM Reply Quote 0
              • B Offline
                Beh @Doubleve
                last edited by Oct 22, 2017, 1:52 PM

                @Doubleve You don’t need these links, since vdircsyncer discovers your calendars automatically on iCloud and identifies them by their IDs.

                It is explained in the “Let vdirsyncer discover the collections and do the inital sync” section of the walkthrough.

                You mirror accesses the calendar saved to a file on your mirror.

                D 1 Reply Last reply Oct 22, 2017, 2:15 PM Reply Quote 0
                • D Offline
                  Doubleve @Beh
                  last edited by Oct 22, 2017, 2:15 PM

                  @Beh error for discover

                  Traceback (most recent call last):
                  File “/usr/bin/vdirsyncer”, line 7, in
                  from vdirsyncer.cli import main
                  ImportError: No module named ‘vdirsyncer’

                  B F 2 Replies Last reply Oct 22, 2017, 2:22 PM Reply Quote 0
                  • B Offline
                    Beh @Doubleve
                    last edited by Oct 22, 2017, 2:22 PM

                    @Doubleve Did you change the first line of the file to #!/usr/bin/python3 ?

                    1 Reply Last reply Reply Quote 0
                    • D Offline
                      Doubleve
                      last edited by Doubleve Oct 22, 2017, 3:41 PM Oct 22, 2017, 2:24 PM

                      everything is good

                      B 1 Reply Last reply Oct 22, 2017, 3:42 PM Reply Quote 0
                      • 1
                      • 2
                      • 3
                      • 4
                      • 5
                      • 15
                      • 16
                      • 1 / 16
                      1 / 16
                      • First post
                        2/160
                        Last post
                      Enjoying MagicMirror? Please consider a donation!
                      MagicMirror created by Michael Teeuw.
                      Forum managed by Sam, technical setup by Karsten.
                      This forum is using NodeBB as its core | Contributors
                      Contact | Privacy Policy