Automatically switch input in snapcast grup based on playing or idle

Hi, I’ve recently finished creating multiroom audio setup based on mopidy, snapcast, shairport-sync and librespot. On snapserver I’ve 3 options to play music to group of speakers called Home - default which is internet radio, spotify and shairport (airplay) is there any option in HA to switch input to actually playing stream? By default librespot and shairport are idle (not playing). Maybe there is some kind of script?

The way I got this working is to pipe all of my sources to /tmp/snapfifo and only have one snapcast source, that /tmp/snapfifo pipe.

EDIT: Just came across this page: Home Assistant Multi room audio setup | Thomas shares makes which says this:

The Snapcast server has a meta source type that will switch between audio sources based on priority which is very powerfull yet simple concept. I set it up to prefer notifications over Spotify over music

Looks like exactly what we need. Can’t help any further right now, but I’ll come back if I figure out how it works. Please share as well if anyone gets it working!

EDIT2: Should have read the docs first! Meta looks like this is what it’s for!

Read and mix audio from other stream sources
meta:///<name of source#1>/<name of source#2>/…/<name of source#N>?name=

Plays audio from the active source with the highest priority, with source#1 having the highest priority and source#N the lowest.

So, you would add a source to your snapserver.conf that would look something like this:

source = meta:///default/spotify/shairport?name=Mixed&sampleformat=44100:16:2

which corresponds to what you’re other sources are named. You might have to match codecs of the other sources too. If only one source is playing, it should switch to it and if multiple are playing it will switch to whichever is first in the list. Good luck!

1 Like

Whoa! Didnt came across meta source - which seems to solve my issue. But also after many hours of thinking and googling I found this:

After some quick tests it does what it should - so in my case 3 streams - (default, airplay, spotify) and if anyone want to “cast” airplay or spotify its automatically changing to playing stream!

So it looks like we have 2 solutions :slight_smile: for one “problem”

1 Like

The more solutions the better! Thanks!

1 Like