Skip to main content
pwt
Virtuoso
July 10, 2020

Sonos Command Line Controller Available (Python soco-cli)

  • July 10, 2020
  • 55 replies
  • 6970 views

I’ve created a simple command line control program for Sonos, implemented in Python. I find it very useful for creating a variety of Sonos control scripts (e.g., using cron to run scripts at specific times), and sometimes just for quickly controlling my Sonos systems when I don’t want to start the app.

It works with S1, S2, and split Sonos systems, and it should run on any OS that supports Python 3.

If you’re comfortable using Python and the command line, you may find it useful, too. It’s quite powerful, with a wide range of control actions, yet simple to install and use.

GitHub: https://github.com/avantrec/soco-cli

PyPi: https://pypi.org/project/soco-cli

This is an early release, so expect some bugs and limitations. I’d welcome your feedback and suggestions.

This topic has been closed for further comments. You can use the search bar to find a similar topic, or create a new one by clicking Create Topic at the top of the page.

55 replies

pwt
pwtAuthor
Virtuoso
June 23, 2021

SoCo-CLI version 0.4.0 introduces an HTTP REST API server mode.

This means that SoCo-CLI can be run as an HTTP server, responding to HTTP GET requests by performing actions on your Sonos system. This is useful for some automation scenarios; the functionality is similar to that offered by the node-sonos-http-api application.

More details at: https://github.com/avantrec/soco-cli/blob/v0.4.0/README.md#the-soco-cli-http-api

4 x P:5 | Sub | 4 x P:1 | 3 x Connect | 2 x Boost | Connect:Amp | 2 x One | Amp | Move | Port | Era 300
Lyricist I
June 26, 2021

Fantastic,

used it to stereo pair a Five with a Play:5 gen2. 

Works great!

pwt
pwtAuthor
Virtuoso
July 24, 2021

SoCo-CLI v0.4.4 introduces the ability to play share links from Spotify and Tidal. This feature is considered experimental for the time being, and feedback on your experience is welcome.

Example:

sonos Kitchen sharelink "https://open.spotify.com/track/6cpcorzV5cmVjBsuAXq4wD"
sonos Kitchen play_from_queue

Documentation: https://github.com/avantrec/soco-cli#spotify-and-tidal-share-links

4 x P:5 | Sub | 4 x P:1 | 3 x Connect | 2 x Boost | Connect:Amp | 2 x One | Amp | Move | Port | Era 300
pwt
pwtAuthor
Virtuoso
August 7, 2021

SoCo-CLI v0.4.10 does a more comprehensive job of listing information when using the track, track_follow and track_follow_compact actions.

For example, radio streams will now show the Channel and Radio Show metadata (where present), Audio Books will show Author, Chapter, etc., and Podcasts will show the Podcast Series Title and Release Date.

Suggestions and feedback welcome, as always!

4 x P:5 | Sub | 4 x P:1 | 3 x Connect | 2 x Boost | Connect:Amp | 2 x One | Amp | Move | Port | Era 300
pwt
pwtAuthor
Virtuoso
September 1, 2021

SoCo-CLI v0.4.18 adds the ability to play share links from Deezer. Share links can refer to tracks, albums or playlists, which are added to the Sonos queue. This feature is considered experimental and feedback is welcome.

Example:

> sonos Kitchen sharelink “https://www.deezer.com/en/playlist/5390258182”
> sonos Kitchen play_from_queue

Documentation: https://github.com/avantrec/soco-cli#spotify-tidal-and-deezer-share-links 

4 x P:5 | Sub | 4 x P:1 | 3 x Connect | 2 x Boost | Connect:Amp | 2 x One | Amp | Move | Port | Era 300
pwt
pwtAuthor
Virtuoso
December 8, 2021

FYI: SoCo-CLI v0.4.26 adds the ability to enable/disable subs and surround speakers.

Note to those upgrading: upgrade SoCo as well, to v0.25.0. (I forgot to update the version dependency before I made the release).

I’m currently working on a nice Plex integration, now that SoCo has a Plex plugin. More details once it’s released.

4 x P:5 | Sub | 4 x P:1 | 3 x Connect | 2 x Boost | Connect:Amp | 2 x One | Amp | Move | Port | Era 300
Lyricist I
January 12, 2022

First let me say great work @pwt on putting this all together.  It’s been very helpful.  

So I have 99% of this figured out, but am stuck on the last step of running a script from on the webserver I hope someone can help with a recommendation / advice.

Background:  I have configured a doorbell to chime the sonos speakers that is called via the API webserver.  I do all this using Container on my QNAP NAS and running the sonos-http-api-server.  That way I have a dedicated machine always waiting for a command.

A sample call would look something like this:

http://192.168.xx.xx:8000/Pool/play_file/Law-and-order-sound.mp3

So this is the same as sonos Pool play_file Law-and-order-sound.mp3 in Python.   

Pretty cool, it plays the Law and Order sound on my Sonos Speaker called Pool.  The problem i have is that I need to play the sound on all the speakers in the house.

So example would be:

sonos Pool group Garage : sp2 group Garage : Garage play_File Law-and-order-sound.mp3 : Garage ungroup

 

I just need to know how to call something like that from the Web Server.  Should I do a bash command to run a script?  Should I execute a python script to get it to work?   

Any advice or help would be appreciated.

 

pwt
pwtAuthor
Virtuoso
January 12, 2022

I’m glad you’re finding SoCo-CLI useful. Thanks for the feedback.

The HTTP server doesn’t currently accept sequential actions. I’ll have a think about how to add this, but it’s not particularly simple.

So, as you’ve noted, three separate calls to the web server are required (as below).

http://192.168.xx.xx:8000/Pool/party_mode
http://192.168.xx.xx:8000/Pool/play_file/Law-and-order-sound.mp3
http://192.168.xx.xx:8000/Pool/ungroup_all

Right now, to perform this in one go via an HTTP call, you’d need to run your own simple web server with one or more GET paths that invoke the sonos sequential action lists that you require. This is not particularly hard to do, but does require a bit of know-how.

4 x P:5 | Sub | 4 x P:1 | 3 x Connect | 2 x Boost | Connect:Amp | 2 x One | Amp | Move | Port | Era 300
pwt
pwtAuthor
Virtuoso
January 14, 2022

The HTTP server doesn’t currently accept sequential actions. I’ll have a think about how to add this, but it’s not particularly simple.

I’ve now added a ‘macros’ feature that allows one to define custom actions and sequences of actions to be executed by the HTTP API server. For example, for this use case one might define a ‘doorbell’ macro:

http://192.168.xx.xx:8000/macro/doorbell

This would invoke the necessary sequence of actions, defined in a local macros file at the server end.

I’ve implemented the feature and I’ll release it later today once it’s documented.

4 x P:5 | Sub | 4 x P:1 | 3 x Connect | 2 x Boost | Connect:Amp | 2 x One | Amp | Move | Port | Era 300
pwt
pwtAuthor
Virtuoso
January 14, 2022

The HTTP API Server macro feature is now released as part of SoCo-CLI v0.4.34. @FlipLewis , this should satisfy your doorbell use case.

Documentation is at:

https://github.com/avantrec/soco-cli/blob/master/README.md#macros-defining-custom-http-api-server-actions

Feedback welcome, and let me know of any issues (ideally over at the GitHub site, not here).

4 x P:5 | Sub | 4 x P:1 | 3 x Connect | 2 x Boost | Connect:Amp | 2 x One | Amp | Move | Port | Era 300