ESParagus Media Center

ESP32-based, Home Assistant compatible streaming audio player

Limited items in stock

View Purchasing Options
Jun 05, 2024

Project update 6 of 7

Integrating Esparagus Into an Existing Setup

by Andriy

For this week’s update, I’d like to share my own story of integrating Esparagus boards into my audio setup. I have had it for years now and it is really hard for me to change my habits. Also, it is a fun technical challenge, so why not?

To be more specific, I’m currently using Mopidy media center software, that runs on one of my Raspberry Pis and connects internet radio, Youtube audio, podcasts, my local music library (and many more, you name it) to the stereo system. The nice thing about Mopidy is that family members can control it with the app and, with a few tricks, even children can control it with Alexa.

The weak point in this setup is the hard binding between the Raspberry Pi and the stereo system, which makes extending this setup very hard. This is what I’m about to break:

Snapserver

I’ve mentioned Snapcast before and how it can be used with Home Assistant. Unfortunately, although Mopidy can work with Snapcast, Music Assistant does not allow external sources, so I need another instance that I can configure and control myself.

Configuring Snapserver

For most distros, this will be as simple as running a single command:

sudo apt install snapserver -y

This gives you several capabilities:

  1. A system service that starts automatically with the system
  2. The possibility for any client in the network to connect and play audio as soon as it is available
  3. A web UI for controlling audio sources and speakers
  4. An RPC interface to control Snapserver remotely.

However, what you don’t get is auto-discovery, so we need to fix that:

## only if you don't have it already
sudo apt install avahi-daemon -y

This file will configure specific settings for the Snapcast service when placed under /etc/avahi/services/snapcast.service:

<?xml version="1.0" standalone='no'?><!--*-nxml-*-->
<!DOCTYPE service-group SYSTEM "avahi-service.dtd">
<service-group>
  <name replace-wildcards="yes">%h</name>
  <service>
    <type>_snapcast._tcp</type>
    <port>1704</port>
  </service>
</service-group>

The last step is to create a source for Mopidy to push audio to. The below line goes into the /etc/snapserver.conf file, [stream] section. It will create a named source that will work over the network on port 1706 (You may choose any other port, this one is my lucky number).

source = tcp://0.0.0.0:1706?name=mopidy

Configuring Snapclient

On the Esparagus side, things are quite simple. Autodiscovery still works beautifully. It will connect automatically and you can use Snapserver’s Web UI to configure speakers along with other clients you may have. (After all, why would you need Snapcast if not for multi-room config?)

Configuring Mopidy

The last piece of the puzzle is to teach Mopidy to push audio to Snapserver, where it will find a way into every dark corner of your home. For that, you need to add this line to the Mopidy config at /etc/mopidy.conf section [audio]:

output = "audioresample ! audioconvert ! audio/x-raw,rate=48000,channels=2,format=S16LE ! wavenc ! tcpclientsink host=192.168.1.41 port=1706"

This rather cryptic line is a gstreamer pipeline that will convert audio into a PCM datastream and push it to the Snapserver’s open port over TCP.

After you restart Mopidy, try it out. Don’t forget to adjust your speaker settings (and connect them to Mopidy as necessary) in the Snapserver UI.

Bonus: Connecting Music Assistant

Since the purpose of this exercise was to adopt other sources, we left Music Assistant on the side of the road. All we need to do is connect it to the external Snapserver and we can use it along with Mopidy if we want to.

End result

It may look scary, but now we have as many speakers as we like, using both Esparagus and Raspberry-based speaker ends. On the source side, I can keep my Mopidy, and use Home Assistant for voice notifications and bunch of automations I have already.


Sign up to receive future updates for ESParagus Media Center.

Subscribe to the Crowd Supply newsletter, highlighting the latest creators and projects