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.
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.
The core configuration is shared between all instances:
[mpd] hostname = :: [http] hostname = :: [audio] output = alsasink [spotify] username = <redacted> password = <redacted>
Add the local configuration on computers that have local media files:
[local] media_dir = <your/music/here>
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
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
snapserver on the same server running Mopidy with the snapcast configuration.
$ snapserver # or use systemd
snapclient on computers that will be playing audio.
$ snapclient # or use systemd, add -h <server host> if necessary
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.
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