Control Sonos speakers with Ruby
Clone or download
Aaron Gotwalt
Aaron Gotwalt Merge pull request #54 from pfeffed/master
added facility to look up speaker by uid and name
Latest commit a8fed52 Jun 28, 2016



Control Sonos speakers with Ruby.

Huge thanks to Rahim Sonawalla for making SoCo. This gem would not be possible without his work.

Code Climate

Note: Currently discovery is broken in Ruby 2.1


Add this line to your application's Gemfile:

gem 'sonos'

And then execute:

$ bundle

Or install it yourself as:

$ gem install sonos


I'm working on a CLI client. For now, we'll use IRB.

$ gem install sonos
$ irb
require 'rubygems'
require 'sonos'
system = # Auto-discovers your system
speaker = system.speakers.first

Now that we have a reference to the speaker, we can do all kinds of stuff.

speaker.pause # Pause whatever is playing  # Resumes the playlist '' # Stream!
speaker.volume = 70
speaker.volume -= 10
speaker.add_to_queue ''
speaker.save_queue 'Jams'
speaker.set_sleep_timer '00:13:00'

Or go into what the official control from Sonos, Inc. calls "Party Mode": put all speakers into a single group


Topology finds the first speaker it can. We can get all of the Sonos devices (including Bridges, etc) by calling Sonos.system.devices. To get the groups, call Sonos.system.groups.

All of this is based off of the raw Sonos.system.topology.


Currently there is support to queue items from the following services, provided the service accounts are set up:

  • Spotify
    • tracks
    • albums
    • playlists
    • top lists
    • starred
  • Rdio
    • tracks
    • albums

The way to add items differs per service at moment:

For Spotify only the 'Spotify URI' is required:


Whereas for Rdio more information needs to be provided:

  :track => '42083055',
  :album => '3944937',
  :username => 'RDIO_USERNAME_HERE' })


There is a very limited CLI right now. You can run sonos devices to get the IP of all of your devices.

You can also run sonos pause_all to pause all your Sonos groups.

To Do


  • Handle errors better
  • Handle line-in in now_playing
  • Detect fixed volume
  • Detect stereo pair
  • CLI client for everything
  • Nonblocking calls with Celluloid::IO
  • Unified method of adding items from music services


  • Manipulating groups doesn't update System#groups
  • Pause all (there is no play all in the controller, we could loop through and do it though)
  • Party Mode
  • Line-in
  • Search music library
  • Browse music library
  • Skip to song in queue
  • Alarm clock
  • Pandora doesn't use the Queue. I bet things are all jacked up.
  • CONNECT (and possibly PLAY:5) line in settings
    • Source name
    • Level
    • Autoplay room
    • Autoplay include grouped rooms


If we are implementing everything the official Sonos Controller does, here's some more stuff:

  • Set zone name and icon
  • Support for SUB
  • Support for DOCK
  • Support for CONNECT:AMP (not sure if this is any different from CONNECT)
  • Manage services
  • Date and time
  • Wireless channel
  • Audio compression
  • Automatically check for updates (not sure if this is a controller only preference)
  • Local music servers
  • Add component


  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request