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

Krishma M
Retired Sonos Staff
July 19, 2020

Hi @pwt, thanks for sharing that with us and greatly appreciate all your efforts. If you need anything just let us know. Thanks!

Help others find useful content by clicking the like button and selecting the best answer to your question.
pwt
pwtAuthor
Virtuoso
July 20, 2020

Hi @pwt, thanks for sharing that with us and greatly appreciate all your efforts. If you need anything just let us know. Thanks!

Thanks. I’ve done substantial additional work on the utility, and it’s in quite good shape now, with several Improvements and new features. I’m finding it fun to use, and useful. There’s good documentation on the GitHub page.

if anyone has any questions or suggestions, please feel free to ask them 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
Belly M
July 20, 2020

I knew you were active with Soco…. this is a very useful extension / alternative method of a quickly executing commands, thank you.

 

Now, just need to think how I can use this beyond what I already do in SoCo

pwt
pwtAuthor
Virtuoso
July 21, 2020

Now, just need to think how I can use this beyond what I already do in SoCo

Great! Please do report any problems or suggest ideas for enhancements.

 

Here’s a handful of quick examples to whet the appetites of others.

1. Group the Bathroom with the Bedroom, play a favourite radio station until a specific time, then stop the stream and ungroup:

C:> sonos Bathroom group Bedroom : Bedroom play_fav “Radio 4” : wait_until 09:00 : Bedroom stop : Bathroom ungroup

2. Set the sleep timer for a specific time:

c:> sonos Bedroom sleep_at 23:45

3. Reset speaker volumes overnight:

C:> sonos wait_until 03:00 : Bedroom vol 25 : Bathroom vol 25

4. Set a speaker to play another’s Line-In, and play for an hour:

C:> sonos Bedroom line_in Lounge : Bedroom play : wait 01:00 : Bedroom stop

 

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
rleeden
Contributor I
July 24, 2020

Great work. I’ve been using soco for a while now, but this makes life a lot easier - thanks!

Only thing I’ve found so far that doesn’t seem to work, and is probably more of a documentation issue, is that the github page suggests you can run:

sonos SPEAKER version

This gives ‘Error: Action 'version' not found’.

Of course sonos --version works fine

1 x Arc | 1 x Sub (Gen 3) | 2 x One | 3 x Play:1 | 2 x Move | 1 x Roam | 2 x One SL
pwt
pwtAuthor
Virtuoso
July 24, 2020

Only thing I’ve found so far that doesn’t seem to work, and is probably more of a documentation issue, is that the github page suggests you can run:
  sonos SPEAKER version
  This gives ‘Error: Action 'version' not found’.

Thank you very much for finding and reporting this. I’ve corrected the documentation now.

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
rleeden
Contributor I
July 26, 2020

I noticed there have been a couple of updates over the last few days, inlcuding the addition of ‘list_playlist_tracks’. This works great, except I’ve got a couple of playlists that include one of more spaces (e.g. ‘Saturday Afternoon Mix’), and I can’t find a way for the sonos command to accept this as a valid playlist name. No matter what quotes I use, or escaping the spaces it errors with:

Error: Action 'list_playlist_tracks' takes 1 parameter(s)

Also, it only seems to show me the first 100 songs in the playlist. Most of my playlists have considerably more than this. I seem to remember that soco displays 100 by default, but it can be increased I think?

1 x Arc | 1 x Sub (Gen 3) | 2 x One | 3 x Play:1 | 2 x Move | 1 x Roam | 2 x One SL
pwt
pwtAuthor
Virtuoso
July 26, 2020

Thanks for testing!

I noticed there have been a couple of updates over the last few days, inlcuding the addition of ‘list_playlist_tracks’. This works great, except I’ve got a couple of playlists that include one of more spaces (e.g. ‘Saturday Afternoon Mix’), and I can’t find a way for the sonos command to accept this as a valid playlist name. No matter what quotes I use, or escaping the spaces it errors with:

Error: Action 'list_playlist_tracks' takes 1 parameter(s)

It should be possible to enclose the playlist name in double quotes, i.e., “Saturday Afternoon Mix”. On Linux and macOS either single or double quotes can be used, but Windows requires doubles.

Also, it’s possible to use fuzzy matching with partial playlist names (without spaces), provided they’re not ambiguous.

Also, it only seems to show me the first 100 songs in the playlist. Most of my playlists have considerably more than this. I seem to remember that soco displays 100 by default, but it can be increased I think?

I’ll include a fix for this (along with some other goodies) in a release later today.

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
rleeden
Contributor I
July 26, 2020

 

It should be possible to enclose the playlist name in double quotes, i.e., “Saturday Afternoon Mix”. On Linux and macOS either single or double quotes can be used, but Windows requires doubles.

Also, it’s possible to use fuzzy matching with partial playlist names (without spaces), provided they’re not ambiguous.

 

 

My mistake - quoting does work, and thanks for the tip regarding fuzzy matching.

1 x Arc | 1 x Sub (Gen 3) | 2 x One | 3 x Play:1 | 2 x Move | 1 x Roam | 2 x One SL
pwt
pwtAuthor
Virtuoso
July 26, 2020

Also, it only seems to show me the first 100 songs in the playlist. Most of my playlists have considerably more than this. I seem to remember that soco displays 100 by default, but it can be increased I think?

Just FYI, v0.1.22_1 is released now, with a fix for the issue above.

There’s also a new ‘wait_stopped_for’ action, and the addition of a simple looping  primitive.

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