Playing a specific source / playlist / song on Sonos

Hi,

I have my Sonos speakers connected to ST Hub. I can start/stop music or make them speak through ST Hub.

But I couldn’t find how to make them play a specific song or playlist from one of my sources (preferably music library or imported playlists)

I can only see the last song title played on the speaker on ST device interface.
How can I get to the previous/next tracks ?

Thanks.

Are you referring directly from the SmartThings Sonos Device App? You can’t…you have to have an app that allows for ‘harvesting’ the last played songs and putting them into a sort of list. There is a SmartThings app called Mood Music that allows you to trigger music based on specific events.

Unfortunately, the Sonos integration is broken…after working with support I got the following note:

"I reached out to our engineering team, and was able to get the following.

We will need to implement some additional functionality into our platform so that we will be able to make full use of Sonos’ API and build out a much better integration. Until then, it’s unlikely that this issue will be resolved. In addition to that, there is no official timeline of when that additional functionality will be put in place."

This is regarding an issue I discovered with the playTrack() API which is at the heart of what you are looking for. I found a workaround using playSoundAndTrack() and implemented that into my Alexa Helper app, so you CAN still change tracks and specify saved channels to play, but that may be temporary if ST decides to change that as well.

2 Likes

I don’t have Echo/Alexa
How can I use your app to just start playing a song/playlist on my Sonos ?

Thanks.

While called Alexa Helper, at its core my app is just an association engine. If you define an Alexa Switch virtual dimmer (via the Alexa Helper parent app) and call it Sonos, that would be the first step. Next Define a momentary button tile…call it Song1

Ensure on the parent app that you have your settings configured to use Sonos speakers. Also set the number of saved stations to 2 or above
Then, create a speaker control scenario.
Associate the Alexa virtual dimmer you defined (Sonos) to your Sonos speaker.
If you have songs saved in your account from recently playing your Sonos (via the Sonos app), you should have the option to set up a saved station. Use the momentary button tile you defined (Song1) and use that as the trigger. Choose a song to play.

Then, you can turn on or off the Sonos (play or pause) using the dimmer, along with controlling the volume. Pressing the Song1 button will initiate the song you associated.

Does that make sense?

1 Like

Thanks. But I couldn’t find your smat app. Where is the code ?
Maybe what you wrote will make sense when I add your app to the hub. Otherwise, I don’t understand.

Thanks.

I can get wordy, but if you like documentation I have some here: http://thingsthataresmart.wiki/index.php?title=Alexa_Helper

That will give you the location of the files:

Alexa Helper-Parent (Main):
Version: 4.4.5
https://github.com/MichaelStruck/SmartThingsPublic/blob/master/smartapps/michaelstruck/alexa-helper.src/alexa-helper.groovy
Alexa Helper-Child (Scenario):
Version: 2.8.7
https://github.com/MichaelStruck/SmartThingsPublic/blob/master/smartapps/michaelstruck/alexa-helper-scenario.src/alexa-helper-scenario.groovy
Alexa Switch:
Version: 2.0.5
https://github.com/MichaelStruck/SmartThingsPublic/blob/master/devicetypes/michaelstruck/alexa-switch.src/alexa-switch.groovy

Don’t hesitate to reach out to me via PM if you need some specific guidance.

1 Like

thanks. it is a little bit complicated for me to start quickly (which I prefer most of the time)
I think I have to read documentation at least twice to understand what I need.

I will have some questions by tomorrow :slight_smile:

Hi,

I was busy for a few days and could not try this.
Just found some time to try and I have 2 problems:

I created the Sonos virtual dimmer and Song1 momentary tile.
But I couldn’t understand how to bind them.
I mean, when I go into the switch named Sonos, I can’t see the Song1 tile.
How shall I do that ?

When creating a scenario I can only see the last song I played on my Sonos speaker from an http source.
But I have played a local (CIFS/SMB shared) file more recently.
I have also played TuneIn radio stations.
But these are not shown on the list. How can I add them and associate withe the Song1 tile ?

edit:
I found how to add the required song to the list. I have to play it through ST once to make it into the list.
But now, when I press the Sonos (switch) on button , nothing happens.
Also, when I press the Song1 (momentary tile) botton , nothing happens.
And, the tile is not seen within the switch. Shouldn’t it be ?

Thanks.

It sounds like you didn’t add the switches to the Echo Smart app…the order of things should be…

Add the switch…
Add the switch to Alexa Helper
Add the switch to the Amazon Echo Smart app
Discover the new switches on the device

All of this assumes you have set up the Echo to work with SmartThings.

Finally, if all of the above are correct then you can turn on or off the Sonos with the dimmer, along with adjusting the volume. To play the saved song, you say turn on the momentary switch.

Make sense?

But you know, I don’t have Echo. So I didn’t install any Amazon Echo Smart App.
I hav einstalled the Alexa Helper app (and its environment) just because you suggested that I can make use of it without Amazon echo.
Can’t I use it without Amazon Echo ?

Sorry…my bad…these modified steps should work:

Add the switch(Dimmer)…
Add the switch to Alexa Helper to control the on/off and volume
Add the Momentary tile
Add the switch to Alexa Helper to turn on the saved song

So, those switches can now control the sonos…Does that work for you?

Add the switch(Dimmer)…

I’ve added the switch through the Alexa Helper (parent) app.

Add the switch to Alexa Helper to control the on/off and volume

I didn’t understand that step. Since I’ve already added it through the Alexa Helper , what else shall I need to add it to Helper app ?

Add the Momentary tile

I’ve added it through the IDE. Is that ok ?

Add the switch to Alexa Helper to turn on the saved song

I’ve added a scenario to the Alexa Helper which includes the switch as the controller, and the momentary tile as the song selection button.

So, now I have a scenario named “test” , a switch added to this scenario names Sonos. One of my Sonos speaker is added to this scenario.
And as a selection button to this scenario I’ve added momentary tile named “Song1”

But I can’t see this tile within the switch named “Sonos”
And turning on Sonos does nothing to my Sonos speaker.

I guess I am not understanding what you are trying to accomplish…If you have your phone in your hand, you could just as easily control the Sonos with the Sonos app instead of the added complication of adding a switch, unless you are attempting to add automation to it…

Anyway, for the [quote=“mrmrmrmr, post:13, topic:41987”]
Add the switch to Alexa Helper to control the on/off and volume
[/quote]

This is the first couple lines…in the example below the vSonos virtual switch will control the Master Bedroom Sonos:

For the momentary switch, in this example, when I press the “Sonos Station 1” button in SmartThings, the ‘70’s’ station will play.

The last part of your post “But I can’t see this tile within the switch named “Sonos”” I am not clear on what you are expecting…if you go to the switches in your SmartThings app, pressing the vSonos button (in my example) will turn on the last played station…Adjusting the dimmer percentage changes the volume, and when I press off the Sonos stops playing. When I press the momentary button “Sonos Station 1” the station starts playing…

Does that help at all? As you expecting the momentary switch to appear in the dimmer tile? That is not what happens.

Ok. I understand that I shouldn’t expect the momentary tile to appear imn dimmer tile now.
But controlling the Sonos speaker is also not working (well, completely)

If I press the “off” button it stops what is playing on my Sonos speaker.
But “on” button does not work. And also, percentage does not affect volume.

This is what error I get on my IDE log when I press “on” button:

c896a520-eb45-4212-8cde-384fcb0cf970  8:31:02 PM: error org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'null' with class 'null' to class 'int'. Try 'java.lang.Integer' instead @ line 506
c896a520-eb45-4212-8cde-384fcb0cf970  8:31:02 PM: info Alexa Helper scenario 'Test', 'Speaker on/off' triggered
b3e72520-0ce5-4200-aa1d-b44dc01be24c  8:31:00 PM: info Alexa Switch sent 'On' command

This is what I get when I press the momentary tile:

c896a520-eb45-4212-8cde-384fcb0cf970  8:35:07 PM: error org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'null' with class 'null' to class 'int'. Try 'java.lang.Integer' instead @ line 506
c896a520-eb45-4212-8cde-384fcb0cf970  8:35:07 PM: info Alexa Helper scenario 'Test', 'Speaker Saved Song/Station Trigger: Song1' triggered

this is what we have on line 506 in the scenario app:

  else vDimmerSpeaker.setLevel(speaker.currentValue("level") as int)

well, I want to control it through ST because Sonos is not controllable when I am not connected to the home network.
And the default ST - Sonos controller does not allow selecting predefined stations/songs.

if I remove that line (506) from code, on/off button and song selection button works.
but why doesn’t it work ? (volume)

Do me a favor and set your initial volume to something within the app…I am going to test it without which is the only way line 506 will fire. Standby…

set your initial volume to something within the app

what do you mean ? set initial volume in which app ? your app ?