Finally, I added Multi Room support for Home Assistant (HA) and it works great with Spotify. Yes, this is the one to use within HA and add Spotify playlists and multi-room support. This is awesome, it also works with a ton of devices. Currently, I am using Raspberry Pi 3+ and my small Linux box to test and it works great! I ordered all the components to make a esp32 version too. That will be the next post.

What is Needed?

  1. Build a Music Assistant server
  2. Add squeezelite to Raspberry Pi and Linux
  3. Configure squeezelite to work with devices and outputs.
  4. Add HACS Music Assistant to HA
  5. Enjoy

1 - Setup Music Assistant Server

So, since I am running docker. I am using docker compose via Portainer. I am actually running on the same docker VM that I use for HA but that is not really that important but it was simple to configure and is related to HA so I figured this made sense. Here is the example docker config for the VM that I am using based on this VM template. Below is the stack:

This is my current HA Docker server
version: "3"
services:
  music-assistant-server:
    image: ghcr.io/music-assistant/server:beta # <<< Desired release version here (change beta to latest once there is a stable release)
    container_name: music-assistant-server
    restart: unless-stopped
    # Network mode must be set to host for MA to work correctly
    network_mode: host
    volumes:
      - /opt/music-assistant-server/data:/data/
    # privileged caps needed to mount smb folders within the container
    cap_add:
      - SYS_ADMIN
      - DAC_READ_SEARCH
    privileged: true
    environment:
      # Provide logging level as environment variable.
      # default=info, possible=(critical, error, warning, info, debug, verbose)
      - LOG_LEVEL=info

So, currently there that sets up the server and it is running on host so no port is need to be setup I may change this in the future but it was good to test this docker-compose. Also. notice that I am currently using /opt/music-assistant-server. This is the dir where music would go. Again, I may change this in the future but for now it is fine as I do not have music anywhere. Spotify is doing good for me.

2 - Add Squeezelite to devices.

This was simple, as all I had to do was this

sudo apt install squeezelite

That worked for both Raspberry Pi and my Debian workstation. Note: remember to check your squeezelite -l as this will output your available output audio devices. The command is also below.

squeezelite -l

Now, I modified the default squeezelite at /etc/default/sqeezelite Below is the current configs for both devices.

Squeezelite Configs

Directly below is the one I use for my Debian Linux workstation as I have the audio via HDMI this worked best for running as a service.

# Defaults for squeezelite initscript
# sourced by /etc/init.d/squeezelite
# installed at /etc/default/squeezelite by the maintainer scripts

# The name for the squeezelite player:
SL_NAME="$(hostname -s)"

# ALSA output device:
SL_SOUNDCARD="plughw:CARD=PCH,DEV=3"

# Squeezebox server (Logitech Media Server):
# Uncomment the next line if you want to point squeezelite at the IP address of
# your squeezebox server. This is usually unnecessary as the server is
# automatically discovered.
#SB_SERVER_IP="192.168.x.y"

# Additional options to pass to squeezelite:
# Please do not include -z to make squeezelite daemonise itself.
#SB_EXTRA_ARGS=""

For Raspberry Pi 3+ with headphones out I am using this config at /etc/default/squeezelite

# Defaults for squeezelite initscript
# sourced by /etc/init.d/squeezelite
# installed at /etc/default/squeezelite by the maintainer scripts

# The name for the squeezelite player:
SL_NAME="$(hostname -s)"

# ALSA output device:
SL_SOUNDCARD="hw:CARD=Headphones,DEV=0"

# Squeezebox server (Logitech Media Server):
# Uncomment the next line if you want to point squeezelite at the IP address of
# your squeezebox server. This is usually unnecessary as the server is
# automatically discovered.
#SB_SERVER_IP="192.168.x.y"

# Additional options to pass to squeezelite:
# Please do not include -z to make squeezelite daemonise itself.
#SB_EXTRA_ARGS=""

Config as Services(Daemon)

This is simple just enabling via systemctl there are other ways I found it here. So look at that source for other options just remember that the config is mentioned as /etc/sysconfig/squeezelite on that post but that seems to have changed or is for another Linux distro.

systemctl enable squeezelite
systemctl start squeezelite

After that I would recommend a reboot of the client device.

Add SqueezeBox devices to Music Assistant Server

OK, so this is needed for Music Assistant to find SqueezeBox (squeezelite) devices.

Adding Slimproto to Media Assistant

As shown above 1, need to click on config gear then 2, Add Player Provider button. Finally 3, select Slimproto from this dropdown. Note: the above image is what it looks like after you have added. I did not capture the options in the Add Player Provider button. It is not that complex but comment if you need me to make a image of that option. For now, I am going to be lazy and not add that picture unless someone requests it.

3 - Add Music Assistant HACS

This is simple if you have HACS installed in HA. If you do not then check this article out. Once that is done find Media Assistant in HACS and download and then restart HA. It should find Media Assistant in devices but if it does not then you can add it via Add Integration.

Enjoy.

Issues

So on my Debian workstation I am having troubles using HDMI audio for both squeezebox and the desktop audio. It seemed to be working and then it just seemed to fail. However, I cannot say that I ever tested both web audio via chrome and also the squeezelite service running together. Now, for sure I have and it is not working. So, I even attempted to run as a use modifying the sh script for starting squeezelite and the actual service config. I have attached them below.

This file is /etc/systemd/user/squeezelite.sh

sudo nano /etc/systemd/user/squeezelite.sh
#!/usr/bin/env bash
### BEGIN INIT INFO
# Provides:          squeezelite
# Required-Start:    $network $remote_fs
# Required-Stop:     $remote_fs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Lightweight headless Squeezebox emulator
# Description:       Lightweight headless streaming audio player for Logitech's
#                    Squeezebox audio server
### END INIT INFO

# Author: Chris Boot <bootc@debian.org>

PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC="Squeezebox client"
NAME=squeezelite
DAEMON=/usr/bin/$NAME
PIDDIR=/run/user/1000/${NAME}
PIDFILE=${PIDDIR}/${NAME}.pid
SCRIPTNAME=/etc/systemd/user/${NAME}.sh

# Exit if the package is not installed
[ -x "$DAEMON" ] || exit 0

# Read configuration variable file if it is present
[ -r /etc/default/$NAME ] && . /etc/default/$NAME

# Load the VERBOSE setting and other rcS variables
. /lib/init/vars.sh

# Define LSB log_* functions.
. /lib/lsb/init-functions

#
# Function that starts the daemon/service
#
do_start()
{
        DAEMON_ARGS=""
        if [ ! -d "${PIDDIR}" ]; then
                mkdir -p "${PIDDIR}"
        #       chown pi:pi /var/run/power/
        fi

        # add squeezelite name if set
        if [ -n "$SL_NAME" ]; then
                DAEMON_ARGS="${DAEMON_ARGS} -n ${SL_NAME}"
        fi

        # add souncard setting if set
        if [ -n "$SL_SOUNDCARD" ]; then
                DAEMON_ARGS="${DAEMON_ARGS} -o ${SL_SOUNDCARD}"
        fi

        # add squeezebox server ip address if set
        if [ -n "$SB_SERVER_IP" ]; then
                DAEMON_ARGS="${DAEMON_ARGS} -s ${SB_SERVER_IP}"
        fi

        # add any other options given by the user
        if [ -n "$SB_EXTRA_ARGS" ]; then
                DAEMON_ARGS="${DAEMON_ARGS} ${SB_EXTRA_ARGS}"
        fi

        # Return
        #   0 if daemon has been started
        #   1 if daemon was already running
        #   2 if daemon could not be started
        start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON \
                --test > /dev/null || return 1

This is the service config used by systemctl --user

sudo nano /etc/systemd/user/squeezelite.service 
[Unit]
Description=Squeezelite LMS player
After=network.target


[Service]
Type=forking
ExecStart=/etc/systemd/user/squeezelite.sh start
ExecStop=/etc/systemd/user/squeezelite.sh stop
PIDFile=/run/user/1000/squeezelite/squeezelite.pid

[Install]
WantedBy=multi-user.target

Starting it should be possible with something like this but it is not currently starting and I can run start again once in the desktop then it will respond accordingly.

systemctl --user enable squeezelite
systemctl --user start squeezelite

Notice that this is designed to be ran without sudo so you do not need to add sudo to it as it is running as a specific user.

For now like mentioned above I have to run start again on reboot.

systemctl --user start squeezelite

Leave a Reply

Your email address will not be published. Required fields are marked *