BUTTONS - Toddler DJ: Streamdeck + Raspberry Pi + Sonos
'The Buttons' - The Backstory
Kids are awesome and my kids are no exception, but let's be honest -- kids have their moments, too. Often those moments may be entirely unavoidable while other times, you may walk yourself directly into a meltdown that was otherwise avoidable.
'The Buttons' were born from the ilk of the latter. We have a number of Sonos speakers around our house & our yard and we found that the kids love to have music playing while they're outside swinging on the playground. So far, so good!
That worked very well for a while, maybe even a week or two, until the point came when there was a near-constant "change to this song" followed by a "no I don't want that song!!!" -- sometimes you could sort through the song requests (most often requested by lyric), other times it could quickly devolve into a moderate-to-severe tantrum. All the while, the DJ (me) may have been trying to finish up a code review, catch up on tech news, or even just handle some chores around the house.
Solution: 'The Buttons'
So simple, and in hindsight I feel slightly dumb for writing about it because it really is simple -- but I'm pretty proud of it and it's been a true blessing in the level of evening enjoyment (and peace) that it brings to the household, adults & children alike. It's also uniquely rewarding when our children have a friend over to play: they will run over to the playground with their friend in tow and proudly request/exclaim, "look at our buttons!" -- quite gratifying.
It's relatively simple, here's the quick rundown:
Hardware
- Streamdeck - The main ingredient.
- Raspberry Pi 4B - Runs the USB server software so that you can control/'program' the StreamDeck from that computer.
- Waterproof Box - I used the one linked because I already had it, but it was a tight fit, I'd suggesting buying something slightly bigger.
- PoE to USB-C Power Adapter - Optional, but great if you want to get both power and LAN from a single cable, which is exactly what I wanted.
- Spraypaint - Optional, but makes things look a bit nicer.
Software
- Node Sonos HTTP API Library (GH Repo) - You will install this on a desktop computer, a server on your LAN, or even directly on the RPi. This is used to control the Sonos system.
- VirtualHere - USB client/server - You will install the server on the Raspberry Pi. Install the client on the desktop machine (macOS or Windows) that will be 'controlling' the StreamDeck. The free version works to get going but the software is very reliable and useful (so buy a license if you like it!).
- Streamdeck Desktop Software - Install this on the desktop.
Building It
- Paint your box, if desired. Trace the outside of the StreamDeck on the front of your waterproof box. Grab a rotary tool (Dremel, etc) and carve it out until it fits nicely. Strongly suggest doing the cutting in a well-ventilated area.
- Setup the RPi with your favorite *nix distro (make sure it's supported by VirtualHere!) and establish SSH access.
- Mount the RPi inside of the box, get the power supply in there, and drill a hole for power and/or ethernet cable.
- Install the VirtualHere USB server on the client device - just copy the self-contained binary, chmod it, and create a system service for it so that it will restart itself if the RPi reboots.
- Go to the desktop that will be "controlling" the StreamDeck. Download the VirtualHere USB client software & run it; you'll see your LAN-based USB device automatically, right click and select "Auto-use Device".
- Install and run the 'node-sonos-http-api' library -- I run it on my desktop.
- Almost done! Fire up the StreamDeck control software on your desktop. Drag a 'visit website' action onto any button you want.
- To configure a button just click on it, ensure the 'Send request in background' checkbox is checked, then set the URL like below -- replacing the replace the hostname/IP your node-sonos-http-api host/IP and the 'SONOS-FAVORITE-NAME' with the name of any item in your 'Sonos Favorites' list.
- Grab a beer and start brainstorming playlist ideas with your kids!
Few Extra Notes
- The StreamDeck buttons will render animated GIFs, so you can do all kinds of funny things with that.
- I'd recommend setting (lowering) the Sonos 'max volume' for the zone which you can do from the iOS or Android apps (but not the desktop app, grr).
- The 'node-sonos-http-api' library had been semi-abandoned for a while but has recently been receiving some attention. That said, sometimes the 'node-sonos-http-api' server will need restarted (if speakers ever change IPs, or other edge cases) -- of course, I just put it on a cron & have it restart every 5 minutes, problem ! =D
New Button Requests - Currently ~ Weekly
We take "requests" -- we let our kids request new buttons each week and on Fridays we generally will add them. It only takes a few minutes to search for a playlist, add it as a new Sonos 'Favorite', and find an icon for it -- and it teaches them to be patient as they wait throughout the week for their button requests to be fulfilled. Not to mention the near-instant gratification for the adult adding it, when they get to go try it out immediately.
One thing I'm not sure of: One of our kids recently asked, "please add a PIZZA button!" -- I'm just not sure exactly how I'm going to be able to code my way out of that one, but I'm thinking on it (approval queue + throttling + local pizza delivery place API, perhaps?). =D