Hass remote speakers with MPD - OnHub

August 20, 2023

This is part of a series of posts on using MPD to set up remote speakers controlled by HomeAssistant on various devices. This post covers the Google OnHub, specifically the TP-Link variant (whirlwind) running OpenWRT.

OpenWRT support for the OnHub is still relatively new, available only in release candidates for the 23.x series. I found the installation instructions on the wiki (linked above) to be accurate, although I would describe the series of initial flashes as “yellow, orange, red” rather than “white, yellow, red”. At any rate, I’m going to assume that you’re coming into this post with a working OpenWRT install that you can ssh into.

OpenWRT has MPD available in its package repositories, but actually getting sound out of it, at least on this hardware, has some pitfalls. (Some of this may be applicable to other OpenWRT platforms, but some is definitely the idiosyncracies of the whirlwind platform specifically; be wary of drawing too general conclusions from this.)

First of all, if you just ask it to install MPD, you’ll get a minimalist version of ffmpeg along with it that can’t decode most audio formats. So you need to override that:

# opkg update
# opkg install mpd-full libffmpeg-full alsa-utils nano

Installing mpd also brings in pulseaudio. That can’t save us, so turn it off:

# service pulseaudio stop
# service pulseaudio disable
# service mpd enable

At this point you should be able to aplay -l and see an ipq806xstorm playback device. Notably, however, it has no hardware volume control. MPD has built in software volume control (using mixer_type "software") for these circumstances, but it doesn’t seem to work on this platform. And the default (maximum) volume is also shockingly loud.

So, we kill two birds with one stone by asking ALSA to generate a software volume control instead, which does work, and also lets us bump the maximum (and default) volume down to something more reasonable. Create /etc/asound.conf:

pcm.softvol {
  type softvol
  slave.pcm "default"
  control.name "Volume"
  control.card 0
  max_dB -20.0
}

This creates a new virtual output device, softvol, connected to a virtual volume control Volume which tops out 20dB below the nominal maximum output of the hardware.

Now we need to tell MPD to use it by editing /etc/mpd.conf. We also need to give it a log_file or it will misbehave; I’m not sure why.

bind_to_address "any"
port "6600"
default_permissions "read,add,control"
restore_paused "yes"
log_file "/dev/null"
input {
  plugin "curl"
}
audio_output {
        type            "alsa"
        name            "whirlwind speaker"
        device          "softvol"
        mixer_type      "hardware"
        mixer_control   "Volume"
}

Note that as far as MPD is concerned, this is hardware volume control – it does not know that the volume control presented by ALSA is a polite fiction.

Finally, you need to give MPD permission to talk to the sound hardware, by adding it to the audio group. Edit /etc/group and add mpd:

audio:x:27:mpd

Then reboot and you should be good to go! If everything is working right, mpd will start on boot and be accessible remotely, and your OnHub is now usable as a speaker, in addition to whatever else you want to use it for, like mood lighting or as a wireless access point.