Wake Up with Spotify Alarm Clock for Ubuntu Linux

Hate your boring alarm clock? Here’s how to wake up to your favourite Spotify songs using your Ubuntu Linux laptop, desktop, or home theatre PC.

To get started, you will need a Ubuntu Linux computer (with the common amd64 64-bit or i386 32-bit architecture), some speakers (laptop speakers will do), and a Spotify Free or Premium account. Note that you will need to leave your computer on overnight so that the alarm can activate.

Getting started

Let’s go ahead and install Spotify for Linux…

  1. Add the Spotify repository signing key to be able to verify the download:

    sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys BBEBDCB318AD50EC6865090613B00F1FD2C19886
    
  2. Add the Spotify repository:

    echo deb http://repository.spotify.com stable non-free | sudo tee /etc/apt/sources.list.d/spotify.list
    
  3. Update the list of available packages:

    sudo apt-get update
    
  4. Install Spotify:

    sudo apt-get install spotify-client
    

Start the Spotify app, login or create a Spotify account, test that the audio output is working correctly, and then close it. If your speakers are connected via a USB soundcard, you may need to configure this according to the Ubuntu USB audio guide.

Great! Now to focus on setting up the alarm! Install the alarm scheduler and dependencies:

sudo apt-get install alarm-clock-applet wmctrl xautomation

And install the Spotify Rise plugin that integrates Spotify with the alarm scheduler:

cd ~/Downloads/
wget -O spotify-rise https://raw.githubusercontent.com/gcushen/spotify-rise/master/spotify-rise
sudo install spotify-rise /usr/local/bin/spotify-rise

Spotify Rise works by using the system’s D-Bus message bus to communicate with Spotify. D-Bus provides an easy and reliable way for inter-process communication on Linux. However, Spotify’s implementation of D-Bus is incomplete (and buggy in numerous versions) so we can only control a limited subset of Spotify features via the plugin.

In Spotify, turn on shuffle mode so that the cross-over arrow symbol turns green:

and then locate an energising album that you fancy waking up to, copying the URI of one of it’s tracks by right clicking on a track and choosing Copy Spotify URI:

Open up the alarm scheduler:

alarm-clock-applet

Create a new alarm and configure it to run the command spotify-rise <URI> where <URI> is the Spotify URI that we copied from Spotify above. This process is shown in the screenshot below, although note that the command has been customized using some options that we will discuss next.

You may customize the spotify-rise command with the following options:

Option Function
<URI> The Spotify URI to play (track, album, etc.)
-t Toggle shuffle mode (if not already toggled in Spotify and you want shuffle mode)
-s Expect that shuffle mode is already active
-h Help
-c <cutoff> Override the default 15 minute alarm timeout. Units are minutes. A zero value removes the timeout.

To test out the options, it is recommended that you experiment by running the commands in your Terminal app before deciding which options to use for your alarm. You can use the Ctrl + C keyboard combination to stop a command running.

Now save the alarm, and a tick should be shown in the alarm list to indicate that it is active:

Example commands

Play an album/track, starting with specified track URI:

spotify-rise spotify:track:0I2kwvXCLolYQ4nZQcF6EQ

Play an album in shuffle mode, assuming you keep Spotify in shuffle mode:

spotify-rise -s spotify:track:0I2kwvXCLolYQ4nZQcF6EQ

Play an album in shuffle mode, assuming you do not keep Spotify in shuffle mode:

spotify-rise -ts spotify:track:0I2kwvXCLolYQ4nZQcF6EQ

Stopping the alarm

When the alarm activates in the morning and starts playing your playlist, there are a number of ways to stop the alarm:

  • download the Spotify app on your smart phone, connect to your home WiFi, and hit the pause button in the app
  • click the Stop button directly in the GUI of the alarm app on the computer
  • mute the speaker volume
  • let the Spotify alarm automatically timeout after 15 minutes (i.e. after a few songs have played)

Spotify compatibility

Unfortunately, Spotify’s implementation of D-Bus is incomplete and can be buggy, as discussed above.

Spotify v1 no longer supports playing playlists/albums via D-Bus, but we have worked around the album issue by providing the URI of a (random) track within a desired album to the Spotify Rise plugin, which enables us to play all songs from an album. For playlist support, currently you will need to downgrade to Spotify v0.9 unless Spotify improve their D-Bus support in the near future.

Wrapping up

Before going to bed, remember to ensure that the computer and speakers are powered on. It is recommended that you test your alarm has been setup correctly by setting a test alarm for a few minutes’ time before relying on it to wake you up!

That’s it! Rise and shine in style with Spotify-Rise and your favourite songs! If you found this article helpful, don’t forget to share it with your friends and star or contribute to the project on GitHub. Feel free to leave any comments or questions below!

Written by George Cushen

I’m a data scientist and vision engineer passionate about machine learning, augmented reality, and internet of things. Follow me on twitter or subscribe to the newsletter to be notified of new tutorials.

comments powered by Disqus