Sonos Command Line Controller Available (Python soco-cli)



Show first post

55 replies

Userlevel 7
Badge +20

Just to note that I’ve added a cue_favourite action in soco-cli v0.1.28.

This silently cues up one of your Sonos Favourites so that it plays next time you press ‘play’ on the speaker. It’s convenient shorthand for the sequence: mute speaker, play_favourite, stop playback, unmute speaker. I found myself repeating this action sequence in several scripts, so decided to encode it in a single action.

Example: If I like to listen to Radio 4 sometime after 7am in the Kitchen. I can cue up the station ready to respond to hitting the play button, with the following script:

sonos wait_until 0700 : Kitchen cue_fav “Radio 4”

 

Badge

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?

Userlevel 7
Badge +20

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.

Badge

 

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.

Userlevel 7
Badge +20

FYI, folks: SoCo-CLI version 0.3.40 introduces the ability to snooze playing alarms, e.g.:

sonos bedroom snooze_alarm 10       <-- Snoozes for 10 mins
sonos bedroom snooze alarm 30m <-- Snoozes for 30 mins
sonos bedroom snooze_alarm 01:20:00 <-- Snoozes for 1hr 20 mins

Support for alarms management is now quite comprehensive: see the documentation at:

https://github.com/avantrec/soco-cli#alarms

Userlevel 7
Badge +20

Hi there! I have never used python and am a complete and absolute beginner. 

Is there a step by step instruction manual for a total idiot anywhere? 

This is a pretty comprehensive guide to installing Python on various platforms:

https://realpython.com/installing-python/

Once you’ve done this, you can install SoCo-CLI and its dependencies using pip install -U soco-cli from a command window (terminal), then run it using all of the various sonos commands.

Userlevel 7
Badge +20

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!

Userlevel 7
Badge +20

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

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

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.

GitHubhttps://github.com/avantrec/soco-cli

PyPihttps://pypi.org/project/soco-cli

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

This is awesome and thanks for sharing! Is there a command to force download and install firmware updates to Sonos speakers?

Userlevel 7
Badge +20

Is there a command to force download and install firmware updates to Sonos speakers?

No, there isn’t, sorry. I think updates are done outside the UPnP control mechanisms that are used by SoCo.

Userlevel 5
Badge +13

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

Userlevel 7
Badge +20

SoCo-CLI version 0.3.43 introduces support for imported local library playlists.

There are new actions to list library playlists, list the tracks in a library playlist, and to add a library playlist to the queue:

  • list_library_playlists or llp
  • list_library_playlist_tracks <playlist_name> or llpt
  • add_library_playlist_to_queue <playlist_name> or alpq

The actions operate in the same way as the existing ones for Sonos playlists.

@pwt Very nice piece of software!

When using the http-api-server, I am not able to add a sharelink (e.g. the one you provided in the docs: https://music.apple.com/dk/album/black-velvet/217502930?i=217503142)

http://api.example.com:8000/Dachgeschoss/sharelink/https%3A%2F%2Fmusic.apple.com%2Fdk%2Falbum%2Fblack-velvet%2F217502930%3Fi%3D217503142

Always returns { "detail": "Not Found" }

What am I doing wrong? Do I need to encode the link or somehow escape it?

Regards
Christian

 

Userlevel 7
Badge +20

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

Userlevel 7
Badge +20

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.

Badge +20

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

Userlevel 7
Badge +20

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

 

What is the best way to find if a speaker is playing something already? I tried sonos -l office info and then grep’ing for PLAYING but grouped speakers return PLAYING even if they are not (?)

Userlevel 7
Badge +20

What is the best way to find if a speaker is playing something already? I tried sonos -l office info and then grep’ing for PLAYING but grouped speakers return PLAYING even if they are not (?)

The most concise way to find a speaker’s current state is to use the state action, i.e.:

sonos -l office state

This will return a short description of the player state, and if directed at a slave speaker in a group it will be redirected to report the state of the group coordinator. The track action also reports playback state, along with details of what’s playing.

The info action isn’t redirected to the group coordinator, so it just dumps the data for the target speaker. When a speaker is a slave in a group, Sonos doesn’t bother to keep the playback state correct.

Userlevel 7
Badge +20

The info action isn’t redirected to the group coordinator, so it just dumps the data for the target speaker. When a speaker is a slave in a group, Sonos doesn’t bother to keep the playback state correct.

In the next SoCo-CLI release, I’ll modify the info and sysinfo actions so they correctly report the state of slave speakers.

Userlevel 7
Badge +20

@pwt Very nice piece of software!

When using the http-api-server, I am not able to add a sharelink (e.g. the one you provided in the docs: https://music.apple.com/dk/album/black-velvet/217502930?i=217503142)

http://api.example.com:8000/Dachgeschoss/sharelink/https%3A%2F%2Fmusic.apple.com%2Fdk%2Falbum%2Fblack-velvet%2F217502930%3Fi%3D217503142

Always returns { "detail": "Not Found" }

Defect raised at: https://github.com/avantrec/soco-cli/issues/38

Userlevel 7
Badge +20

Version 0.1.40 of soco-cli improves seek functionality by adding new seek_forward and seek_back actions, alongside the existing seek (seek_to) option.

The seek_forward (sf) and seek_back (sb) actions allow one to skip ahead or skip backwards within a track: useful for jumping through podcast ads, or re-listening to a section of audio. Skipping can be by an arbitrary duration, within the length of the audio track being played.

Examples:

sonos Study skip_forward 30s
sonos Study skip_back 2m
sonos Study seek_to 00:03:32

As always, let me know if there are features you’d like to see, or if you encounter any problems.

Userlevel 7
Badge +20

The most concise way to find a speaker’s current state is to use the state action, i.e.:

sonos -l office state

I’ve now moved the details of the state action to a more sensible section of the documentation:

https://github.com/avantrec/soco-cli/blob/v0.3.37/README.md#speaker-and-sonos-system-information

  • state (or statusplayback): Returns the current playback state for the speaker, one of: PAUSED_PLAYBACKPLAYINGSTOPPED, or TRANSITIONING.

In the next SoCo-CLI release, I’ll modify the info and sysinfo actions so they correctly report the state of slave speakers.

This change is now released in SoCo-CLI v0.3.37.

I am getting a 

Error: 1: list index out of range | 2: list index out of range 

when I run

sonos -l office play_favourite_number 28

The number is valid - I run 

sonos -l office list_favs

to verify and I get back 40 items.

 

 

 

Userlevel 7
Badge +20

I am getting a 

Error: 1: list index out of range | 2: list index out of range 

when I run

sonos -l office play_favourite_number 28

The number is valid - I run 

sonos -l office list_favs

to verify and I get back 40 items.

You may want to take this discussion over to GitHub (https://github.com/avantrec/soco-cli/issues), where it’s generally easier to work on issues.

Either way, (A) could you provide the output of the following:

  1. sonos -v
  2. sonos -l office play_favourite number 28 --log=info

(B) Could you try ‘play_favourite’ using the favourite name instead of its number, and report whether this works.

(C) What type of favourite are you trying to play?

(D) Is it only #28 that fails, or is it a problem across all favourite numbers.

(It may be worth noting that not all Sonos Favourites are playable using SoCo-CLI; e.g., single tracks from Spotify will work, but not albums. That’s not the problem you’re seeing, however.)

Thanks!

Reply