I have written previously about my SONOS speakers and my family’s frustration with the app that controls them. See SONOS Speaker API Overcomes App Limitations In that blog post, I resolved my wife’s biggest issue with the SONOS app. She now has a two-button device that plays and stops her favorite playlist on the speakers in the basement.
But my biggest pet peeve remained unresolved until recently. Each speaker has its own, independent volume control. This is a double-edged sword. It’s great because my wife can blast her playlist in the basement while I’m upstairs playing my classical playlist at a much subdued volume. On the other hand, if we want to play a party mix over all the speakers in the house, I have to set the volume on each speaker individually.
For my wife’s solution, I implemented an MQTT broker, subscriber and publisher.

A Raspberry Pi Zero W runs a Broker program and a Subscriber program at boot.
Both apps are written in Python. The Broker listens on the network for any MQTT traffic and forwards that information to all Subscribers that have expressed an interest in the data. When the Subscriber starts, it tells the Broker what traffic it’s interested in.
The two-button device is the Publisher. When the PLAY button is pressed, the device sends a sonos/play message to the Broker. The Broker forwards this message to the Subscriber. The Subscriber responds by calling the SONOS library (soho) to control the speakers. The Subscriber runs on the Raspberry Pi Zero because the SONOS Library is beefy and needs the power and a lot of dependencies. As long as I had a Pi Zero in the mix, I decided to also use that for the Broker as well. The Broker and Subscriber are just two processes that happen to be running on the same hardware.
I was able to use this existing infrastructure to solve the volume control problem. I just had to write a Publisher app to cause the existing Subscriber to set speaker volumes in addition to launching my wife’s playlist. I decided to write a SwiftUI app for my iPhone for Publisher. Here’s what the new architecture looks:

The iPhone app has a slider and a Volume button that sends a message to the Broker which passes it along to the Subscriber. With this button, I can set the volume of all the speakers to the same specific value.
The Minimize Volume button tells the Subscriber to scan the volume levels of all the speakers, find the minimum value, and adjust the volume on all the speakers to that minimum level. The Maximize Volume button sets the volume to the same value as the loudest speaker.
Finally, Whisper sets the volumes to a level that is just barely audible — you can tell the speakers are on, but they don’t interfere with phone calls or people at the door.








































































































