Using sonos.playTrack(string)

(Brian) #1

Hey everyone,

I’ve searched the forums and haven’t found a solution for this. I’m trying to send Sonos setTrack() and playTrack() commands in a smart app, but I’m having no luck.

The documentation says that playTrack takes a string, which I assume is the name of the track. So for example I have 3 songs in my track list, one of which is named “Kalimba.mp3”

So I tried the following (both for setTrack and playTrack):

playTrack(C:\Users\Public\Music\Sample Music\Kalimba.mp3)

and tried playing a track hosted online:


and none of these things seem to work. Is there a special way to format the track name so that this will work?

All the other commands I’ve tried work fine (such as play(), pause(), setLevel(), nextTrack(), etc.)



(Eric R) #2

Did you actually set them as strings using quotes?

playTrack(“C:\Users\Public\Music\Sample Music\Kalimba.mp3”)

(Brian) #3

I’m actually using rest endpoints, so I’m not actually writing those commands out. It’s more like:

I have a command like:

command = “setTrack&Kalimba.mp3”

then I have:

def commandArray = command.split("&")
def com = commandArray[0]
def val = commandArray[1]

and I’ve verified that this works by using:

playText&Hello world

which works just fine.

(Brian) #4

And just to be sure I went back and typed the commands out manually in the smartapp:

I tried each of these:

device.playTrack(“C:/Users/Public/Music/Sample Music/Kalimba.mp3”)

No luck.

(Ron S) #5

@bharms can you try one small thing… Can you play that thing thru Sonos directly and then try in ST? I have heard some tracks not being recognized by ST unless played fully once thru Sonos but I may totally be wrong…

(Brian) #6

That’s interesting. You mean just using my sonos controller app and listening to the song? If so, I have definitely listened to the song multiple times all the way through. If I look at my live logging I’ll see notifications like:

info: Sonos is playing such and such by so and so

so it’s definitely capable of accessing the track information. It just doesn’t respond to any of the setTrack or playTrack commands I’m giving it. My first guess was just that I wasn’t formatting the string correctly. Now I’m not sure.

(Ron S) #7

Didn’t mean to confuse you. Search the forums… I use text only for my contacts open, close and mode changes using my own app and it works “mostly”.

(Brian) #8

I found another person using playTrack() with an audio file hosted online.


I did the same and it worked. I’m not sure why the other file I tried calling didn’t work before. Oh well, working fine now!

I’ve just got to host all the tracks I need to play online. So while it’s not incredibly pressing, my new question is: is there a way to use playTrack() to play local files?