DEV Community

Cover image for Spotify Connect, Raspberry Pi, AirPlay & HomePod - because simple audio setups are boring
Piotr Ładoński
Piotr Ładoński

Posted on

Spotify Connect, Raspberry Pi, AirPlay & HomePod - because simple audio setups are boring

I could write a whole long introduction of why I needed to stream Spotify from my Raspberry Pi to HomePod Mini speaker, how I arrived at the final idea, how I was hitting constant problems with other solutions... but if you're reading this, I guess you are way more interested in the actual setup 🙂 So let's just put it very briefly:

My problem:

  • AirPlay drains phone battery fast, but it's the only option for playing Spotify on HomePod Mini. How can I AirPlay music to HomePod, but not from the phone... and still control it from the phone?

Solution:

  • Raspberry Pi & Spotify Connect to the rescue! Make the Raspberry Pi the playing device and control it from the phone via Spotify Connect

The tricky part... was the actual execution. It took me a significant amount of time, caused quite some frustration with solutions that didn't work, and, finally, I had to take bits from several of them to make things work. In the end, if you know what to do, it's not hard, but... you must know what to do 🙂 I'll do my best to explain the process as clearly as possible, so here we go!

General idea for Raspberry setup

Basics: I'm using Raspberry Pi 5 and the newest Raspbian based on Debian 13 (Trixie).

There are two main things that RPi must do

  1. become a Spotify Connect device and
  2. stream audio via AirPlay to the HomePod

Luckily, it's nothing innovative, and there are already plenty of existing solutions for both things. However, there are actually so many that you can spend a lot of time trying to combine them and get nowhere. My silver bullets turned out to be

  • Raspotify - turning RPi into a Spotify Connect device
  • Owntone - AirPlay-ing to the speaker

And, one secret ingredient that glues them together - Linux named pipes.

Oh, and a very important detail - Spotify Premium. Raspotify doesn't work with free accounts.

Installing things

That's probably optional, but I'd start with a good old package upgrade:

sudo apt update && sudo apt upgrade
Enter fullscreen mode Exit fullscreen mode

Why probably? Because I've run it and haven't checked if things would work without the system-wide package upgrade 🙂

Raspotify

That's super easy. As the docs mention, just run

sudo apt-get -y install curl && curl -sL https://dtcooper.github.io/raspotify/install.sh | sh
Enter fullscreen mode Exit fullscreen mode

and that's it. Raspotify will be installed & started. You can verify it with

systemctl status raspotify
Enter fullscreen mode Exit fullscreen mode

It should also already appear as a Spotify Connect device.
Remember, your phone, Raspberry, and HomePod need to be on the same network!

Owntone

You can follow the steps from the forum post, or just trust me that I copied everything correctly and run

wget -q -O - https://raw.githubusercontent.com/owntone/owntone-apt/refs/heads/master/repo/rpi/owntone.gpg | sudo gpg --dearmor --output /usr/share/keyrings/owntone-archive-keyring.gpg && sudo wget -q -O /etc/apt/sources.list.d/owntone.list https://raw.githubusercontent.com/owntone/owntone-apt/refs/heads/master/repo/rpi/owntone-trixie.list && sudo apt update && sudo apt install owntone -y
Enter fullscreen mode Exit fullscreen mode

After that, go to http://owntone.local:3689 (or http://localhost:3689) and check if the web UI loads correctly.

Pipes

Long story short, we'll create pipe files to enable communication between Raspotify and Owntune. Raspotify will be writing to them, OwnTune reading and playing that via AirPlay.
Just run

sudo mkdir /srv/music && sudo mkfifo /srv/music/raspotify-pipe && sudo mkfifo /srv/music/raspotify-pipe.metadata
Enter fullscreen mode Exit fullscreen mode

to create two pipes. You can use different names without any issue, but if you want to put them in a different directory, you'll need to update library.directories option in Owntone configuration.
Also, .metadata pipe won't be actually used, as Raspotify is not currently able to process metadata. We created it simply to have one less error from Owntone - it just needs the file to exist.

Configuration

Raspotify

All the Raspotify options are listed on the wiki. We'll need to change only 2 of them.
Let's open the configuration file with nano to edit it:

sudo nano /etc/raspotify/conf
Enter fullscreen mode Exit fullscreen mode

and set LIBRESPOT_BACKEND and LIBRESPOT_DEVICE as follows:

LIBRESPOT_BACKEND=pipe
LIBRESPOT_DEVICE=/var/run/raspotify-pipe
Enter fullscreen mode Exit fullscreen mode

Remember to uncomment them!
If you want, you can also change the name under which Raspberry will appear on Spotify Connect devices list. To do this, modify LIBRESPOT_NAME, for example

LIBRESPOT_NAME="Raspotify"
Enter fullscreen mode Exit fullscreen mode

Save and close the file (Ctrl + X, Y, Enter).

Owntone

In the bottom right of the web UI, you should see an arrow to expand the simplified output control panel. One of the devices there should be the AirPlay speaker (HomePod) that you want to use - click its icon to enable it.

You can also adjust the volume here. It's quite important - at the end, I had everything working correctly, but the slider here was too low, and I thought something was still broken 🙃 The "final volume" on the HomePod is a product of the volume you set in Owntone and the value picked for the Spotify Connect device on the phone. Keep that in mind when things are too quiet/loud.

To make sure all the config changes in both Raspotify and Owntune are applied, restart the services:

sudo systemctl restart raspotify && sudo systemctl restart owntone
Enter fullscreen mode Exit fullscreen mode

Running everything

We're basically there. Now get your phone, open Spotify, and you should be able to select Raspberry as the Spotify Connect device 🎶
Remember that Raspberry and your phone must be on the same Wi-Fi network!
Here are also some details about Spotify Connect on the Spotify support page if you're not familiar with the feature itself: https://support.spotify.com/article/spotify-connect/

General troubleshooting

If things are not working, journalctl is your best friend in debugging. Simply open a terminal and run

journalctl -u owntone -f
Enter fullscreen mode Exit fullscreen mode

(or raspotify instead of owntone)
and you'll see some system logs from the services. Hopefully, you'll see some "error" lines that will help you fix the problem.

Summary

As I've written at the beginning, if you know the steps, the setup should be straightforward. It's just about running two services and connecting them. Knowing the Raspberry/Linux ecosystem, the above steps will become outdated sooner than later, but I hope they will be useful for at least a moment 😄

If you hit any problems, write a comment. While my Linux-fu is not high, I'll do my best to help.

Happy streaming! 🎵


Top comments (0)