Multi-room audio with Snapcast, Mopidy, and Home Assistant

Would you like to listen to music in every room in your home, controlled from one source? Then multi-room audio is for you.

Multi-room audio can be achieved by having a computer attached to speakers in every room. On each computer, services run to play and/or control the audio. With this DIY approach, the kind of computer and speakers is very much up to you. It could be your desktop computer with attached powered speakers, your HTPC hooked up to your TV and receiver, a Raspberry Pi with Amp or DAC, or even an Android device.

You’ll need two key software packages, besides Home Assistant. The first is Mopidy, a music server that can play local files, or connect to streaming music services like Spotify. The second is Snapcast, which enables synchronized audio streaming across your network. Both can be integrated into Home Assistant. Each room audio device will run an instance of the Snapcast client, and optionally a Mopidy instance. Your server will run a special instance of Mopidy and the Snapcast server.

Finally, you also need a player to control Mopidy. Any MPD-compatible player will work, and there are several Mopidy-only web-based options available. On Android, Remotedy is particularly nice since you can access multiple Mopidy instances in one place.

Home Assistant will provide device status, and volume control for each room. If you want to play music in all your rooms (on all your clients), access the server instance of Mopidy. If you want to play music only in a specific room, access that specific Mopidy instance. If you’re using a web UI for Mopidy, you can add links to each instance in Home Assistant with the weblink component.

![](upload://cb7TxxvnWMCVR7enT6LN4oAn9Qv.png)

Staging

Configure Mopidy

Mopidy can be run with multiple configuration files, each extending the previous file. This is helpful when we’re running multiple instances with varying functionality.

core.conf

The core configuration is shared between all instances:

[mpd]
hostname = ::
[http]
hostname = ::
[audio]
output = alsasink
[spotify]
username = <redacted>
password = <redacted>

local.conf

Add the local configuration on computers that have local media files:

[local]
media_dir = <your/music/here>

snapcast.conf

Finally, the Mopidy instance that connects with Snapcast needs special configuration. Run on a different port to avoid conflicts if you have a second Mopidy instance running on your computer. The audio output is sent to a named pipe - Snapcast will read from there. Note that you may have to adjust the audio output attribute depending on your system and audio sources.

[mpd]
hostname = ::
port = 6601
[http]
hostname = ::
port = 6681
[audio]
output = audioresample ! audio/x-raw,rate=48000,channels=2,format=S16LE ! audioconvert ! wavenc ! filesink location=/tmp/snapfifo

Run Mopidy

To run a room-specific instance:

$ mopidy --config $CONF_DIR/core.conf

To run a room-specific instance with local media:

$ mopidy --config $CONF_DIR/core.conf:$CONF_DIR/local.conf

To run the special Snapcast-connected instance (with local media):

$ mopidy --config $CONF_DIR/core.conf:$CONF_DIR/local.conf:$CONF_DIR/snapcast.conf

Run Snapcast

Start the snapserver on the same server running Mopidy with the snapcast configuration.

$ snapserver   # or use systemd

Start the snapclient on computers that will be playing audio.

$ snapclient   # or use systemd, add -h <server host> if necessary

Configure Snapcast

There are a number of snapcast configuration options, but the one relevant to Home Assistant is the client names. You can set them in the snapserver configuration file, by default located at ~/.config/Snapcast/settings.json. Only edit this file while the snapserver is not running. Modify the name JSON value to your liking - this is how the client will be named in Home Assistant.

Configure Home Assistant

Use the mpd and snapcast components. Optionally, use weblink to provide easy access to a Mopidy web UI.

media_player:
- platform: snapcast
  host: xxxxx
- platform: mpd
  server: xxxx
  location: Multi-Room Controller
- platform: mpd
  server: xxx
  location: Room 1
weblink:
  entities:
  - name: Multi-Room Player
    url: xxxx

This is a companion discussion topic for the original entry at https://home-assistant.io/blog/2016/02/18/multi-room-audio-with-snapcast/
13 Likes

Thank you so much! I am implementing this just now. As I want to play audio notifications on the same time I had to create a dummy dmix alsa device to mix the audio and prevent problems with sharing the soundcard.

I have a problem with volume control at the moment. Only software mixer works (but too slow!) and I want to have a hardware mixer.

How do you control volume?

Hi,

Thanks for sharing this! I’m implementing this but I would like to know how do you control your snapcast clients from homeassistant?
I would like to control which of my clients are playing audio and I want homeassistant to control that. Because I don’t want music playing in my kids room when they’re playing in their room but when I or my wife is cleaning the bedrooms I would like to play my music on all clients on that floor.

Thanks in advance

Mark

can this work with google home speakers as a client?

Same question here. Would be great if I could mix Chromecast and Snapcast devices. But I think it’s not possible.

+1 for chromecast and google home speaker

Given the original project was created in 2016 I do not think it will work well in Home Assistant now with all the changes to integrations. Looking for any ideas that can do something similar in Home Assistant 0.1xx versions.

I still use this and it works fine.

2 Likes

@Burningstone
Thanks for sharing. Does it still work in YAML or did you have to migrate to Integrations in the UI?

Neither MPD or Snapcast are available a integrations via the UI, so it would be yaml

2 Likes

@aidbish That is actually good news. I like YAML :slight_smile:

Not going to get into that argument. LOL
There has been enough of the YAML v UI config over the last few weeks.

1 Like

Both YAML as @aidbish pointed out already.
Where did you get stuck? The Home Assistant part was the easiest thing of the whole setup in my opinion.

I setup a slightly different process, i used Mopidy still but used Icecast2 to send audio to my Google Home devices.

Works without issue, just a bit of automation in nodered and works a treat
Just make sure to use the Iris addon for mopidy. gives a good experince

Not sure which setup method you have used for HA, but i used plain docker with HA core, and you can get the mopidy docker container already with most addins enabled.

How did you manage to expose port 8000? Do you use the mopide add-on

No i used a seperate mopidy docker container not an addon

Wow that was a fast response. I suppose I need to look up how to map the port so it can be used outside the docker container. Will post it here if I manage. I’ll try with Portainer first.

Is there some way to control this system with voice commands? I’d like to be able to play some music, turn the volume up/down, etc. I’d REALLY like it if Alexa would say (after X minutes of silence), “It’s pretty quiet around here. Would you like me to play some music?” It would be great if the system could somehow detect when I get a phone call and auto lower the volume.

Could a Pi Zero W be used as a client?

1 Like