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

If you get it working please post your config. I’ve never been able to get it working with the addons either as you can see if you look back at older posts.

On another topic, I’m also seeing this:

Mopidy-Spotify extension is not running - you will not be able to play any Spotify tracks

So I can’t play any spotify via mopidy, I can see my content (not my liked list though) but I can’t play anything.

Also the only way to connect to snapcast server via my phone using the duckdns domain, I need to forward ports 1704 and 1705 via my router or else it doesn’t work.

EDIT: I can now see all my Spotify and Soundcloud music (added info into the config section of mopidy which fixed that) and play them locally on the PC where my Hassio is located but how do I add other media players?

SnapCast still shows disconnected no matter what I tried.

So the snapcast-server shows the following when I change the Mopidy snapcast port to 1780 and using my duckdns domain in ip:

2021-01-17 13-22-21.963 [Notice] (ControlServer) ControlServer::NewConnection: 192.168.1.1
2021-01-17 13-22-21.963 [Error] (ControlServer) Removing 1 inactive session(s), active sessions: 1
2021-01-17 13-22-21.963 [Error] (ControlSessionHTTP) ControlSessionHttp::on_read error: bad method

Keeps repeating that until I disable the snapcast in Mopidy

Install a reverse proxy like NGINX in order to be able to access your HA instance locally with http and the local IP, saves you all the dangerous port forwarding (except for 443).

May be an issue SSL and self-signed certs.

NGINX allowed me to locally access stuff, but there some issue with port 1780…that is why mopidy can’t connect to my Snapcast.

I can’t even upgrade mopidy, it says I need to upgrade but nothing happens when I click on it.

This is what I see in the snapcast server log:

2021-01-17 16-51-59.630 [Info] (Server) Stream: {"fragment":"","host":"","path":"/share/snapfifo/librespot","query":{"chunk_ms":"20","codec":"flac","name":"SpotifyConnect","sampleformat":"44100:16:2"},"raw":"pipe:////share/snapfifo/librespot?chunk_ms=20&codec=flac&name=SpotifyConnect&sampleformat=44100:16:2","scheme":"pipe"}
2021-01-17 16-51-59.630 [Info] (PcmStream) PcmStream: Mopidy, sampleFormat: 44100:16:2
2021-01-17 16-51-59.630 [Info] (PcmStream) Stream: Mopidy, metadata={
2021-01-17 16-51-59.630 [Info] (PcmStream)     "STREAM": "Mopidy"
2021-01-17 16-51-59.630 [Info] (PcmStream) }
2021-01-17 16-51-59.630 [Info] (Server) onMetaChanged (Mopidy)
2021-01-17 16-51-59.630 [Info] (PipeStream) PipeStream mode: create
2021-01-17 16-51-59.630 [Info] (Server) Stream: {"fragment":"","host":"","path":"/share/snapfifo/mopidy","query":{"chunk_ms":"20","codec":"flac","name":"Mopidy","sampleformat":"44100:16:2"},"raw":"pipe:////share/snapfifo/mopidy?chunk_ms=20&codec=flac&name=Mopidy&sampleformat=44100:16:2","scheme":"pipe"}
2021-01-17 16-51-59.639 [Error] (PosixStream) Exception: end of file
2021-01-17 16-51-59.639 [Error] (PosixStream) Exception: end of file
2021-01-17 16-51-59.640 [Info] (ControlServer) Creating TCP acceptor for address: 0.0.0.0, port: 1705
2021-01-17 16-51-59.640 [Info] (ControlServer) Creating HTTP acceptor for address: 0.0.0.0, port: 1780
2021-01-17 16-51-59.640 [Info] (StreamServer) Creating stream acceptor for address: 0.0.0.0, port: 1704
2021-01-17 16-51-59.640 [Info] (main) number of threads: 4, hw threads: 4

not sure if that can help debug this…

So more debuging…

If I set the port to 1704 in Mopidy I get the following in the snapcast server log:

2021-01-18 10-08-38.260 [Notice] (StreamServer) StreamServer::NewConnection: 192.168.1.xxx
2021-01-18 10-08-38.261 [Error] (StreamSessionTCP) unknown message type received: 790, size: 2477441087
2021-01-18 10-08-38.261 [Info] (StreamServer) onDisconnect: 
2021-01-18 10-08-38.275 [Notice] (StreamServer) StreamServer::NewConnection: 192.168.1.xxx
2021-01-18 10-08-38.275 [Error] (StreamSessionTCP) unknown message type received: 790, size: 1372112756
2021-01-18 10-08-38.275 [Info] (StreamServer) onDisconnect:

If I change it to port 1705 (this crashes snapcast):

2021-01-18 10-12-59.392 [Notice] (ControlServer) ControlServer::NewConnection: 192.168.1.xxx
2021-01-18 10-12-59.393 [Error] (ControlSessionTCP) Error while reading from control socket: End of file
2021-01-18 10-12-59.393 [Error] (ControlSessionTCP) Error in socket shutdown: Socket not connected
2021-01-18 10-12-59.406 [Notice] (ControlServer) ControlServer::NewConnection: 192.168.1.xxx
2021-01-18 10-12-59.407 [Error] (ControlServer) Removing 1 inactive session(s), active sessions: 1
terminate called after throwing an instance of 'nlohmann::detail::type_error'
  what():  [json.exception.type_error.316] invalid UTF-8 byte at index 95: 0xAE
/run.sh: line 43:   236 Aborted                 (core dumped) /usr/bin/snapserver -c /etc/snapserver.conf
[cmd] /run.sh exited 134
[cont-finish.d] executing container finish scripts...
[cont-finish.d] done.
[s6-finish] waiting for services.
[s6-finish] sending all processes the TERM signal.

If I change it back to port 1780, I get:

2021-01-18 11-00-58.556 [Notice] (ControlServer) ControlServer::NewConnection: 192.168.1.xxx
2021-01-18 11-00-58.557 [Error] (ControlSessionHTTP) ControlSessionHttp::on_read error: bad method
2021-01-18 11-00-58.571 [Notice] (ControlServer) ControlServer::NewConnection: 192.168.1.xxx
2021-01-18 11-00-58.571 [Error] (ControlServer) Removing 1 inactive session(s), active sessions: 1
2021-01-18 11-00-58.571 [Error] (ControlSessionHTTP) ControlSessionHttp::on_read error: bad method

Port 1704 and 1705 will not work, 1780 is the correct port.

What issue is there with port 1780 in nginx?

You can’t upgrade mopidy like this, because you are running it in a docker container.

And the snapclient on the phone lets you connect to the snapserver with local ip and port 1780? Can you also connect to the snapserver from a computer with local IP and port 1780?

When using my PC’s browser and using 192.168.1.XXX:1780 I get:

The resource ‘/’ was not found.
2021-01-18_13-23-33

On my phone it uses:
stream port: 1704
control port: 1705

which one should I change to 1780 for testing?

I noticed this may be the issue:
your [http] doc_root in /etc/snapserver.conf should point to your snapweb directory (default /usr/share/snapserver/snapweb ).

Where do I find all the conf files within Hassio?

Ok, just checked my settings and I realized now that the snapcast section in Mopidy settings is only used to enable control of the snapclient volumes from mopidy, but not to get the mopidy stream to be available in snapserver as a stream.

When I go to ip-of-snapserver:1780, I get the snapcast control interface.

Can you please show the config of the mopidy add-on? Do you see the spotify connect stream from the snapserver on your phone? When you open the snapcast app on the phone can you choose Mopidy as a source?

this is my modipy config:

system_packages: []
python_packages: []
settings:
  - name: soundcloud/auth_token
    value: xxxxxxx
  - name: spotify/username
    value: xxxxx
  - name: spotify/password
    value: xxxxx
  - name: spotify/client_id
    value: xxxxx
  - name: spotify/client_secret
    value: xxxxxxx
  - name: youtube/enabled
    value: 'true'
  - name: youtube/playlist_max_videos
    value: '300'
  - name: file/enabled
    value: 'true'
  - name: file/media_dirs
    value: /share/mopidy/media
  - name: audio/output
    value: >-
      audioresample ! audio/x-raw,rate=44100,channels=2,format=S16LE !
      audioconvert ! wavenc ! filesink location=/share/snapfifo/mopidy

In my Snapcast mobile app I see my phone and I can switch between mopidy and spotifyconnect, but I don’t see much on there…

2021-01-18_13-51-25

ok, that looks good so far.

Next test, on your phone in the spotify app connect to the snapserver spotify connect and play a track. Then in the snapcast start the app by pressing the play button in the top right and change the source to “SpotifyConnect”, do you hear music?

Next play something on mopidy, then again on your phone change the source to Mopidy in the snapcast app, do you hear music?

OK so SpotifyConnect played the song flawlessly
Mopidy didn’t play the song I was playing in Mopidy but a loop of another song, was jittery too and stuck in a loop.

Try stopping mopidy and then snapserver, then start mopidy first and snapserver afterwards and see if the issue persists.

it’s still stuck at that same looped song…cached somewhere
Did several stops/start, rebooted my phone, hassio, nothing helps.

In snapserver it shows tons of similar lines:

2021-01-18 14-24-36.003 [Info] (PosixStream) next read < 0 (Mopidy): -2.035 ms
2021-01-18 14-24-36.163 [Info] (PosixStream) next read < 0 (Mopidy): -2.333 ms
2021-01-18 14-24-36.260 [Info] (PosixStream) next read < 0 (Mopidy): -19.32 ms
2021-01-18 14-24-36.344 [Info] (PosixStream) next read < 0 (Mopidy): -3.9 ms
2021-01-18 14-24-36.405 [Info] (PosixStream) next read < 0 (Mopidy): -4.826 ms
2021-01-18 14-24-36.765 [Info] (PosixStream) next read < 0 (Mopidy): -4.382 ms
2021-01-18 14-24-36.969 [Info] (PosixStream) next read < 0 (Mopidy): -28.625 ms
2021-01-18 14-24-36.969 [Info] (PosixStream) next read < 0 (Mopidy): -8.938 ms
2021-01-18 14-24-37.650 [Info] (PosixStream) next read < 0 (Mopidy): -9.803 ms
2021-01-18 14-24-37.741 [Info] (PosixStream) next read < 0 (Mopidy): -0.474 ms

try removing the files in share/snapfifo/mopidy

ok that finally stopped the looped music :slight_smile:

Also now did the Mopidy test and it works over the mobile phone. So I can hear the song playing from Mopidy on my phone.

BTW will I be able to add Amazon Echo as players on this?

1 Like