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
    162 Posts 58 Posters 346.7k Views 65 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.
    • Feedy88F Offline
      Feedy88
      last edited by

      @elliot1996 @duxnobis not sure if anyone is still following, but I was able to get the automated sync with a work around through cronjob. Step-by-step guide below:

      1. Create Shell script

      First we need to create the script which is actually executed by the cronjob. To do this we open a terminal and type

      nano ~/MagicMirror/modules/calendars/vdirsyncer.sh

      Within the editor we just write a one-liner:

      vdirsyncer -vinfo sync
      

      Close by CTRL+X and save by confirming with Y

      1. Make script executable.

      Within terminal type

      chmod +x ~/MagicMirror/modules/calendars/vdirsyncer.sh

      1. Test the script

      Run a test if your script works. Within terminal type

      bash ~/MagicMirror/modules/calendars/vdirsyncer.sh

      If working as intended you should receive the feedback

      Syncing iCloud_to_MagicMirror/YOUR-CALENDAR-UUID

      1. Checking/Changing the Version of vdirsyncer

      This was actually my biggest issue. I could sync successfully when running the script manually but the actual cronjob failed. Looking into Debug-Logs I found that the manual run used Version 0.16.8 of vdirsyncer while the cronjob used 0.16.7. After manually chaning the versioning if worked as inteded. To ensue you are not running into that issue, let’s check the versioning from the get-go. Within Terminal type

      sudo nano /usr/bin/vdirsyncer

      An editor will show you the following code:

      #!/usr/bin/python3
      # EASY-INSTALL-ENTRY-SCRIPT: 'vdirsyncer==0.16.7','console_scripts','vdirsyncer'
      __requires__ = 'vdirsyncer==0.16.7'
      import re
      import sys
      from pkg_resources import load_entry_point
      
      if __name__ == '__main__':
          sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
          sys.exit(
              load_entry_point('vdirsyncer= q=0.16.7', 'console_scripts', 'vdirsyncer')()
          )
      

      Change all three instances of 0.16.7to 0.16.8, close via CTRL+X and save with Y.

      1. Create the Cronjob

      Cronjobs are a great thing. It is pre-installed with UNIX based systems, therefore also with our Raspberry Pi. More information about Cronjobs can be found here. To set up a new cronjob, within Terminal type

      crontab -e

      The result will be the following code:

      # Edit this file to introduce tasks to be run by cron.
      #
      # Each task to run has to be defined through a single line
      # indicating with different fields when the task will be run
      # and what command to run for the task
      # 
      # To define the time you can provide concrete values for
      # minute (m), hour (h), day of month (dom), month (mon),
      # and day of week (dow) or use '*' in these fields (for 'any').
      # 
      # Notice that tasks will be started based on the cron's system
      # daemon's notion of time and timezones.
      # 
      # Output of the crontab jobs (including errors) is sent through
      # email to the user the crontab file belongs to (unless redirected).
      # 
      # For example, you can run a backup of all your user accounts
      # at 5 a.m every week with:
      # 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
      # 
      # For more information see the manual pages of crontab(5) and cron(8)
      # 
      # m h  dom mon dow   command
      

      Type a new line at the bottom with the cron syntax. Here is an overview for the timings:

      # ┌───────────── minute (0 - 59)
      # │ ┌───────────── hour (0 - 23)
      # │ │ ┌───────────── day of the month (1 - 31)
      # │ │ │ ┌───────────── month (1 - 12)
      # │ │ │ │ ┌───────────── day of the week (0 - 6) (Sunday to Saturday;
      # │ │ │ │ │                                   7 is also Sunday on some systems)
      # │ │ │ │ │
      # │ │ │ │ │
      # * * * * * <command to execute>
      

      As for us it makes senst to run vdirsyncer every X minutes (I am going with 5 minutes in my case) the syntax looks as follows:

      */5 * * * *
      

      followed by the script to execute:

      bash ~/MagicMirror/modules/calendars/vdirsyncer.sh >> ~/vdirsyncer.log 2>&1

      The first part should be familiar to you. What follows after the >> is a log we are creating. This will be helpful in case anything does not work as inteded. The full cronjob should look as follows:

      # Edit this file to introduce tasks to be run by cron.
      #
      # Each task to run has to be defined through a single line
      # indicating with different fields when the task will be run
      # and what command to run for the task
      # 
      # To define the time you can provide concrete values for
      # minute (m), hour (h), day of month (dom), month (mon),
      # and day of week (dow) or use '*' in these fields (for 'any').
      # 
      # Notice that tasks will be started based on the cron's system
      # daemon's notion of time and timezones.
      # 
      # Output of the crontab jobs (including errors) is sent through
      # email to the user the crontab file belongs to (unless redirected).
      # 
      # For example, you can run a backup of all your user accounts
      # at 5 a.m every week with:
      # 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
      # 
      # For more information see the manual pages of crontab(5) and cron(8)
      # 
      # m h  dom mon dow   command
      */5 * * * * bash ~/MagicMirror/modules/calendars/vdirsyncer.sh >> ~/vdirsyncer.log 2>&1
      

      Close again by CTRL+X. You are now ready and have everything set up. The cronjob will start automatically on every startup and run the sync in the interval you have set it up.

      S 1 Reply Last reply Reply Quote 0
      • S Offline
        sdetweil @Feedy88
        last edited by sdetweil

        @Feedy88 and if u edit your script and make the 1st line
        #!/bin/bash

        when the script is invoked it will launch the script using bash so all the bash symbols, redirection etc can be moved into the script, and you just use the script and to.launch it

        /home/pi/MagicMirror/modules/calendars/vdirsyncer.sh

        also, cron typically executes commands as root, so ~/filename will try to write to /root/filename, but not where u intended. so use the full path

        /home/pi/MagicMirror/modules/calendars/vdirsyncer.sh

        Sam

        How to add modules

        learning how to use browser developers window for css changes

        Feedy88F 1 Reply Last reply Reply Quote 0
        • Feedy88F Offline
          Feedy88 @sdetweil
          last edited by Feedy88

          @sdetweil Thanks for the notes, but can you explain a bit more into detail. You mean, if I add

          #!/bin/bash as first line to the script, I can also add the logging part and remove it from the cron?

          To be honest, I’m quite a noob to Linux based systems and scripts. Nonetheless, hope my answer will help some people to get the sync going who have issues with the timer service from vdirsyncer.

          S 1 Reply Last reply Reply Quote 0
          • S Offline
            sdetweil @Feedy88
            last edited by

            @Feedy88 yes, if you use the exec command in the script you can capture stdout & stderr and pipe them to a file

            LOG_FILE=filename

            Open standard out at $LOG_FILE for write.

            This has the effect

            exec 1>$LOG_FILE

            Redirect standard error to standard out such that

            standard error ends up going to wherever standard

            out goes (the file).

            exec 2>&1

            normal rest of your script

            Sam

            How to add modules

            learning how to use browser developers window for css changes

            1 Reply Last reply Reply Quote 0
            • J Offline
              jlnxaer
              last edited by

              Hello Guys,

              I’m fairly new to the whole Raspberry Pi Thing.
              I got the whole Calendar up and running. My only problem is, that it is not syncing automatically…
              Do you guys know any fix for this problem?

              The fix from @Feedy88 didn’t work for me unfortunately.

              Cheers!

              S T 2 Replies Last reply Reply Quote 0
              • S Offline
                sdetweil @jlnxaer
                last edited by

                @jlnxaer did u create a cron job entry?

                Sam

                How to add modules

                learning how to use browser developers window for css changes

                1 Reply Last reply Reply Quote 0
                • T Offline
                  Tribun @jlnxaer
                  last edited by

                  @jlnxaer what does the pm2 log show? Are error messages displayed at the log?

                  I also had this phenomenon recently, as the calendar did not syncronize automatically. I had an error message in the log. I no longer know the exact wording of the report.
                  For me it helped to delete and recreate the files under /home/pi/.vdirsyncer/status and the created * .ics files. after creating the data again with “vdirsyncer sync”, everything now runs automatically as described in the instructions.

                  1 Reply Last reply Reply Quote 0
                  • J Offline
                    jlnxaer
                    last edited by jlnxaer

                    @sdetweil You refer to this, right?

                    # ┌───────────── minute (0 - 59)
                    # │ ┌───────────── hour (0 - 23)
                    # │ │ ┌───────────── day of the month (1 - 31)
                    # │ │ │ ┌───────────── month (1 - 12)
                    # │ │ │ │ ┌───────────── day of the week (0 - 6) (Sunday to Saturday;
                    # │ │ │ │ │                                   7 is also Sunday on some systems)
                    # │ │ │ │ │
                    # │ │ │ │ │
                    # * * * * * 
                    */5 * * * *
                    

                    @Tribun The command for the pm2 log is just “pm2 logs” isn’t it? If yes there seems to be everything fine except for a “EADDRINUSE” Error…

                    EDIT: I just figured out, that I was missing a command after the Timings… I added that and now it seems to work just fine! Thank you very much guys :D

                    T 1 Reply Last reply Reply Quote 0
                    • T Offline
                      Tribun @jlnxaer
                      last edited by

                      @jlnxaer
                      (/home/pi/.vdirsyncer/status) is a hidden folder in /home/pi

                      you can also find the pm2 log in /home/pi/.pm2/logs this is also hidden.

                      1 Reply Last reply Reply Quote 0
                      • BehB Offline
                        Beh
                        last edited by

                        Hi,

                        I have another hint related to the systemd timer that was originally described in my tutorial.
                        It is advised to download the vdirsyncer.service and vdirsyncer.timer directly from the web.

                        You need to adjust the path to the executable in the vdirsyncer.service file!
                        It defaults to ExecStart=/usr/bin/vdirsyncer sync, which can be wrong.

                        But probably it is in ~/.local/bin. (Can be different depending on your installation. Just check location with which vdirsyncer.

                        This should make the initially described automatic sync work again.

                        1 Reply Last reply Reply Quote 0
                        • 1
                        • 2
                        • 10
                        • 11
                        • 12
                        • 13
                        • 14
                        • 15
                        • 16
                        • 17
                        • 12 / 17
                        • First post
                          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