September 19, 2013 · alarm api calendar google hacks learnpython raspberrypi raspi rpi sleep sound tricks

Raspberry Pi as a Google Calendar Alarm Clock

Version 1 is here! Simple Google Alarm Clock

This is a repost with some changes including libraries links of original post by Devon from esologic. I've decided to refresh it, as it's a really interesting and fun project. Not only because it lets you sleep in a distance from your harmful mobile phone, but it also enables you to start your day in a different way. Devon developed an alarm clock that is easy to set and will play a random song to wake you up! It's useful, especially if you use Google Calendar all the time. In my case that's true, so I've decided to give it a try.

Here is Devon's presentation of the program:

Before you wake yourself up

Before we start, you need some speakers to play the songs from your Raspberry. Any speakers will do, but make sure you get good quality ones not to disturb your sleep by any hissing or noise.

We also need to do few things to make the script run. First of all, it needs few dependencies that are not installed by default: APScheduler, PyFeed, XE (the two are used by the script), MPG321 (to play mp3s from command line) and, most of all, Google Data Library. If you click on a name above, you will be pointed to a website where you can download the libraries. If you're using desktop client, there is no need to explain how to do it. If you use headless Pi, do as follows:


sudo pip install apscheduler


tar -zxvf pyfeed-0.7.4.tar.gz
cd pyfeed-0.7.4
sudo python install


tar -zxvf xe-0.7.4.tar.gz
cd xe-0.7.4.tar.gz
sudo python install


sudo apt-get install -y mpg321

NOTE: If you've never used sound playback on your Raspberry, head HERE for instructions.

Google Data Library:

To download the latest version, look for the latest version on the Python project's downloads page. After downloading the library, unpack it using unzip or tar zxvf depending on the type of download you chose. Enter the library directory (cd gdata-2.0.xx) and run the script:

sudo python install

Then run the tests/ to see if it all works:


If something goes wrong, go through this guide written by google to get yourself up and running.

The Script

Once everything is set up properly, we can try the script! The program code with my amendments can be found on GitHub: SimpleGoogleAlarmClock.

To make the code work with you, just change line 24 & 25 with your gmail address and password (if you're using 2-step verification, you first need to generate an application-specific password, and put it in line 25 instead of your regular password. You'll also have to adjust the path to your mp3 files on lines 42 & 44 to point to your mp3 directory. Save the script under name you want to (eg. and that's it! Now we can start setting up alarms on Google Calendar.

Set up an Alarm on Google Calendar

The program uses the word wake by default to search through your Calendar events. You can change it on line 29 of the code to any word the program will be responding to. To set up an alarm, simply create an event with the word wake as a title. The duration is not important. Once the time on your Pi hits the event time, it will start playing a song. Of course, you'd need to run the program first!

To run the program from the command line, type:


The program should display something like this:

Full text query for events on Primary Calendar: 'wake'
wake Number: 0 Event Time: 19-09-2013 15:00 Current Time: 19-09-2013 15:04

Don't worry about the Comparison:Fail part, it's just for the program. When the time gets to your set alarm time, it will start playing a song from your song bank.

To run it in background add & after the command: nohup python &.

And that's basically it! You can enjoy original alarm clock!

A follow up:

Simple Google Alarm Clock v1.0

  • LinkedIn
  • Tumblr
  • Reddit
  • Google+
  • Pinterest
  • Pocket