SonosCLI

Control Sonos speakers — discover, status, play, volume, group management, favorites, and Spotify search.

SonosCLI is a modern Go CLI by Peter Steinberger (steipete) for controlling Sonos speakers over your local network via UPnP/SOAP protocols. It provides comprehensive speaker management — discovery, playback control, grouping, queue management, favorites, Spotify integration, and live event monitoring — all from your terminal. The tool's architecture is built for reliability. Speaker discovery uses SSDP (Simple Service Discovery Protocol) with topology-aware fallback via ZoneGroupTopology, plus subnet scanning as a last resort. It's coordinator-aware: when you target a room that's part of a group, commands automatically route to the group coordinator. This means 'pause the kitchen' works correctly even when the kitchen is grouped with the living room. Playback controls cover the full spectrum: play, pause, stop, next, previous, seek, plus specialized modes like play-uri (play any URL), linein (external audio input), and tv (TV audio passthrough). The queue system lets you list, play, remove, and clear queue entries. Favorites integration means you can browse and play your Sonos Favorites by index or title. The Spotify integration is particularly impressive. It works at two levels: direct playback (enqueue Spotify share links or canonical spotify: URIs without Spotify credentials — it uses Sonos's existing linked service), and search via SMAPI (Sonos Music API). For advanced users, optional Spotify Web API search is available with client credentials. Grouping commands let you inspect groups, join/unjoin rooms, create party mode (all speakers), dissolve groups, and solo a room. Scenes save and restore presets including grouping configuration and per-room volume/mute settings. The live events feature (`sonos watch`) subscribes to AVTransport and RenderingControl events, printing real-time changes — track changes, volume adjustments, play/pause state. This is invaluable for building reactive automations. For OpenClaw users, SonosCLI turns voice commands and chat messages into music control. 'Play my morning playlist in the kitchen' or 'Group all speakers and set volume to 40%' become real actions. Combined with cron, you can build automated routines: morning music at 7 AM, quiet mode at 10 PM. Best suited for: Sonos owners wanting terminal/AI speaker control, smart home enthusiasts building audio automation, developers scripting multi-room audio, anyone who wants to control Sonos without the app.

Tags: sonos, audio, smart-home, music, speakers

Category: Smart Home

Use Cases

  • AI-controlled music: 'Play jazz in the living room' via chat
  • Automated routines: morning music, dinner ambience, bedtime silence via cron
  • Party mode: group all speakers with one command
  • Spotify integration: search and play tracks, albums, playlists
  • Volume management: set per-room volumes for different times of day
  • Live monitoring: track what's playing across all rooms
  • Scene management: save and restore speaker configurations

Tips

  • Run `sonos status` first to verify discovery and see all your rooms
  • Use `sonos play-uri` to play any URL: internet radio, local HTTP server, or podcast feeds
  • Save scenes for common configurations: `sonos scene save 'Morning'` (grouping + volumes)
  • Use `--format json` for all automation workflows — pipe to jq for filtering
  • The `watch` command is great for building reactive automations: track changes → trigger actions
  • Use `sonos favorites` to list and play Sonos Favorites without knowing the exact URI
  • Combine with OpenClaw cron for automated routines: morning music, dinner ambience, bedtime wind-down
  • For Spotify, just paste share links: `sonos play-uri 'https://open.spotify.com/album/...'`

Known Issues & Gotchas

  • Your machine must be on the same network as your Sonos system — no remote control
  • Speakers must be reachable on TCP port 1400 — firewall rules or VLAN isolation will break discovery
  • Spotify must already be linked in the Sonos app — the CLI doesn't authenticate with Spotify directly
  • SMAPI search may require a one-time DeviceLink/AppLink flow: `sonos auth smapi begin|complete`
  • Sonos S1 (legacy) systems may not support all UPnP features — S2 recommended
  • Discovery can take a few seconds on large networks — use `--timeout` to adjust
  • Volume changes are per-room, not per-group by default — be explicit about targeting
  • The `watch` command runs indefinitely — it subscribes to events and prints changes until killed

Alternatives

  • soco-cli (Python)
  • Sonos App
  • Home Assistant (Sonos integration)
  • node-sonos (npm)
  • AirPlay from Mac

Community Feedback

sonoscli is a modern Go CLI to control Sonos speakers over your local network. Reliable discovery, coordinator-aware control, grouping, favorites, Spotify integration, and live events.

— GitHub

I love Soco-Cli — being able to control Sonos from the terminal is incredibly useful for automation. The Go-based alternatives like sonoscli are even faster.

— Reddit r/sonos

SonosCLI ships with steipete's OpenClaw skill collection. Control Sonos speakers — discover, status, play, volume, group management, favorites, and Spotify search.

— LobeHub Skills Marketplace

Command line Sonos control has been a long-requested feature. Tools like soco-cli and sonoscli make it possible to script and automate your entire multi-room setup.

— Sonos Community Forum

Configuration Examples

Install and discover

# Install via Homebrew
brew install steipete/tap/sonoscli

# Discover speakers and show status
sonos status

# List all rooms
sonos rooms

Playback and volume control

# Play/pause
sonos play --room 'Living Room'
sonos pause --room 'Kitchen'

# Set volume
sonos volume --room 'Bedroom' 30

# Play a Spotify album
sonos play-uri 'https://open.spotify.com/album/abc123' --room 'Office'

# Play a favorite
sonos favorites play 'Chill Vibes'

Grouping and scenes

# Group speakers
sonos group join --room 'Kitchen' --coordinator 'Living Room'

# Party mode (all speakers)
sonos group party

# Save a scene
sonos scene save 'Movie Night'

# Restore a scene
sonos scene apply 'Movie Night'

# Watch for real-time events
sonos watch --format json

Installation

go install github.com/steipete/sonoscli/cmd/sonos@latest

Homepage: https://sonoscli.sh

Source: bundled