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

https://hub.docker.com/r/jaedb/iris

although the lastest images have removed the icecast integration, had to stick at a certain version
this also includes the iris interface

1 Like

Mine includes Iris as well, should be no problem to add icecast, let me know if you are interested.

@Burningstone Thankyou for the offer
i think the iris integration has dropped the icecast integration in its code so im not sure adding it into the image would help. my icecast is actually a seperate container and no way now to link them in new version of iris

Hello!

Let me share with you my weekend project.

Once you wrap your head around how the system works and what a Media Player Daemon (MPD) is, it’s trivial to script it out for clients.

After you set up Mopidy and snapserver with your clients, the home assistant part is easily done with the media player MPD platform component in config.yaml

I found that this Multi-room audio with Snapcast, Mopidy, and Home Assistant - Home Assistant is a really good source however, the network diagram is misleading. Really it doesn’t matter as long as you point to the server in the configurations.

I have Home Assistant with supervisor running in containers on a NUC, with various Pi interfaces to switch lights and whatnot.

So my weekend project was to convert all of the speakers I’ve collected over time into smart speakers. I plugged in the speakers to the ras-pis and dedicated one as the host. This is my host pi:

Then Installed snapclient, snapserver, and mopidy on the host pi, you can find tutorials on how to do this, here is the one I used: Smart Home Whole Audio Part 1 - YouTube.

After I created the dedicated host pi I was able to connect it to Spotify by following the instructions and viola:

FYI It was a royal pain to get this up and running with my network configurations, but I managed and I hope it is easier for you.

Anyhow, then I created the client Mopidy Pi’s. I’m not going to include pictures the process and result is nearly identical, you just don’t install snapserver and point the snapclient to the snapserver’s IP

All of this was independent of Home Assistant. Connecting Home Assistant was much easier than I was expecting, you need to make sure that the Mopidy MPD python library is installed on each of the Mopidy clients as well as the host.

The cool developers for Home Assistant made it easy, it’s literally a config entry:

media_player:
  - platform: mpd
    host: xx.xx.xx.xx
    name: multiroom_controller
  - platform: mpd
    host: xx.xx.xx.xx
    name: office_pi
  - platform: mpd
    host: xx.xx.xx.xx
    name: living_pi

Here are the features you’ll get:

  1.  Independent client control (except for the host)
    
  2.  TTS on all of your speakers, individually addressable (except for the host)
    
  3.  Programmable automations for media
    
  4.  Full house synchronized audio
    
  5.  Turn any speaker into a smart home speaker
    

Unfortunately you can’t play individual songs from Home Assistant but you can with your handy dandy mopidy webapp.

11/10 Project, the reward when you get all of your speakers synchronized is out of this world.

For those of you who are wondering here is my mopidy network map I hope this helps

Should also open a chat in the mopidy forms for this as well since 95% of this is mopidy set up an home assistant barely plays a part other than the integrated mpd features.

Feel free to DM or reply if you have any questions on the setup.

Cheers!

Chase

1 Like

Thanks for sharing @ChaseGregoryCS your setup looks pretty awesome.

A few questions for you

  • What web and mobile clients are you using for mopidy?
  • How do you control the clients independently? My understanding is mopidy output feeds into snapcast server directly which is fed to each client. How do you choose one thing to play in room A and another to play in room B, and then how do you choose the same thing in rooms A and B but not C?
  • Does Spotify Connect work?
  • Does TTS interrupt the currently playing track/stream ? If so does it resume after the TTS is finished?

I am have a working Squeezelit/LMS setup that just works all the time, but I am missing TTS. There’s no seamless way to play TTS to the squeeze clients without interrupting the current playing track.

You’re very welcome, I’ll do my best to answer these for you.

So, there is a mopidy webserver called mopify that you can install with each mopidy instance. Each device that is running the mopidy daemon is a client and the only instance that is the Host is the one with snapserver. So, if you install the same libraries on each of the clients, you can have independently addressable audio clients. Just an FYI if you do install the mopify webserver it doesn’t work well on chrome, you have to use firefox.

You can also control it through home assistant with the MPD integration, if you tie in each of the clients to the integration, you can individually control each client that way as well with the correct tile.

Spotify Connect works, the caviot is that, only liked songs and playlist songs will move into mopidy. So build your playlist on spotify and play them on your audio system.

And TTS Does interrupt the current playback IF you use TTS on the snapserver instance. You can bypass it by using TTS on all of the other mopidy instances.

I hope that helps!

You shoud check out the custom component here:

This allows media browser integration with mopidy in HA.
I was never able to get this to work all inside HA due to reasons mentioned above in this thread, but did it in a ubuntu lxc.
Two issues with TTS that I’ve had.

  1. If you have SSL then you can’t use a different internal URL. I haven’t had time to figure this out yet. Basically if internet is out…no TTS.
  2. For whatever reason I miss the very beginning of the TTS if one hasn’t been sent in a while.
    Spotify connect does not work with this for me. I have to use some mopidy frontend (usually Iris).
    The custom mini media player card does a nice job of making a card that will integrate your snapcast and mopidy media players so you can choose what plays where and independently control volume.
    TTS will stop music, but the component I posted above will allow you to pause and resume with an automation.
    I’ve read of a way to have TTS play over the top of the music, but that involves using pulse audio and I don’t have the time to mess with that so can’t give advice on that.
1 Like

Thanks for the information!

I think I am going to go this route, but in my LMS/Squeezelite ecosystem. I find mopidy/volumio/snapcast to be too disconnected/separate and hard to control for my family members. The apps in the LMS ecosystem are ugly as sin, but they work. You can also have multi-account Spotify Connect which is a bonus.

I’m going to setup a simple mpd/snapcast setup, retrofit it into picoreplayer using pulseaudio so that snapclient and squeezelite can use the sound card at the same time. That’s my plan at least.

Please document and post somewhere if you’re successful!

1 Like

I doubt if this is the right location to post this question but I have searched the forum and other sources for an answer to this and I am either missing something fundamental or am not searching for the right things.
I currently have a desktop computer running debian. Traditionally this computer has had the audio output jack on the sound card physically connected to an amplifier that drives some speakers in my house, all music (online and local) passes through this soundcard then to the amplifier and I have whole house audio. My goal is to migrate this to snapcast and achieve the following.

  • Redirect (all) the desktop audio to a snapserver that I have running on a second machine in docker.
    This will provide me the benefit of adding snapclients to various locations and devices in my house while maintaining the same desktop computer system for audio. This will make things more or less transparent to the other members of the household as they can continue do do what they have always done. So basically I want to change the physical audio output of my sound card that goes to my amplifier to a named pipe that the snapserver handles. Can this be done?

I think this is what you are asking about:

So it looks like the answer is yes, but this is just a theoretical yes. No clue on how to help you with it.

1 Like

The alsa and pulseaudio sections look like they may have what I need. I will play and see if I can get it to work.
I really appreciate you digging this out for me.

For those who are interested I thought I would update this thread with my setup and solution based on @danbutter providing the rabbit hole for me to venture into. My end goal was to push all the audio that is played on a desktop computer to a snapcast server. I attempted to do this various ways but then discovered the TCP connection option. Here is my final configuration for those who may be interested.

2 Likes

Whether what will work? This a longish thread.

Hi, all, very promising results above. I only wonder what is the best followup step for my current situation to get the “Sync” option available within Home Assistant.

I currently have the following installation:
HA running on a VM
Logitech Media Server (Squeezebox) running on another VM
Different HifiBerry’s with Max2play connected to speakers in different rooms, and connected to the Logitech Media Server VM.

I control the multi room speakers through the Logitech Media Server web interface and its app.

The reason for me using LMS, is the sync function that allows me to easily select multiple rooms to play the same music. But as I am trying to integrate all into HA, I am stuck on the LMS integration.

I am able to connect HA to LMS and control the music for the different rooms, but I cant find anyway how to use the Sync option in the Lovelace UI so to select multiple rooms to play the same music.

So, now I am wondering what do I need to install/configure so that I can quickly select in the Lovelace UI the devices to play the same musix. Just in a similar way as using Sync in LMS.

Any feedback appreciated. :slight_smile:

2 Likes

I’m in the process of writing a series of blogs around multi-room audio with Snapcast documenting moving away from proprietary solutions like Google Home / Sonos to open source solutions like Snapcast. I’ve only written the introduction so far but I plan to also detail how I have integrated Chromecast, AirPlay, Music Player Daemon and my turntable for a complete multi-room solution all with Home Assistant as the main control interface.

https://scoot-technology.github.io/

2 Likes

Sorry I missed this. Sync is dealt with easily in the mini-media-player card. GitHub - kalkih/mini-media-player: Minimalistic media card for Home Assistant Lovelace UI

For building your own ui, see the service calls join and unjoin here Media Player - Home Assistant

1 Like

Thanks! I will have a look at this.

Those of you that run snapcast…do you try to bring it into home assistant?
I tried this in the past and it seemed that every time anything rebooted it would rediscover and make a new entity. I ended up with tons of dead snapcast entities and gave up.

Just wondering if I did something wrong.

There are two things:
1: Snapcast groups are dynamic and thus in my opinion pretty useless: When you add a client to a group, the original group of that client will be deleted. If you then remove that client from that group a new group for this one client only will be created with a new ID.
2. The snapcast integration is/was really outdated and buggy. It did not handle any updates from the server like added/removed clients/groups. State updates had issues as well. Some of this improved last fall and this spring (HA2023.5), but the biggest issue still persists.

I have added a PR for this: Fix Snapcast connection issues by luar123 · Pull Request #93010 · home-assistant/core · GitHub
And in the meantime you can use this custom component with HACS: GitHub - luar123/snapcast_custom_component: Testing repo for the snapcast integration

1 Like