Sonos - how to play specific track?

Newbie here, so sorry if this has been covered but after searching the forum I haven't found something that describes quite exactly what I am trying to do...

I have created a rule using Rule Machine in which I would like to play a specific track to one of my Sonos speakers at a certain time of day. The track I want to play is a mp3 file and it is local on my network, being served up by a NAS.

When I create the rule and choose "play track" as the action, I see where it asks to "set track name." My question is...what is it looking for here?

I was able to play the track through my Sonos app and then went into Hubitat and saw some info about the speaker while it was playing, and I saw a cifs network path. Is that what I want to put in there? Thanks!

UPDATE - so the cifs network path did not work. What do I need to put in there?

I don't know about all that. However, if you have an RPi (or anything that runs node), you should look into node-sonos-http-api. I use it through Hubitat (using @ogiewon's http-momentary-switch). Works great and I can play designated tracks as needed in my flows.

1 Like

Welcome Maxq10 !
you select in your rule what to play and where the file is located.
as you can see in my example, the file itself is located in a file server, reachable through my network.
the Symfonisk is the sonos speaker made for Ikea
Shouldn't be different in your NAS: there is a local IP and a directory.

But you don't need to "play track". Instead, you need to select "run a custom action"

2 Likes

It should work. I just did this while setting up for Halloween. The trick was to play the track via the Sonos app, then pause it before it’s done.

Go to the state variable in the Sonos driver and find the first file path shown. Here’s one I was using as an example:

x-file-cifs://TimeCapsule/music/iTunes/iTunes%20Music/right%20channel%20laugh.mp3

I used Play track and it worked across several rules, each playing a different track.

I’m sharing my iTunes backup from my Synology via SAMBA

2 Likes

I had trouble with this also and ended up putting the audio files on a local web server (RaspberryPi in my case). Then used Control Music Player > Play Track > http://serverIP/path/soundfile.mp3

1 Like

That's what I did too. Not that I tried the other way.

Any ideas on how to play something from Spotify on Sonos?

also trying to find this, did you ever find out?

I did, but then it stopped working randomly. I found that the logs never actually showed the track info that you are supposed to use. I had to look at the device page itself and it showed it there. No idea though why it worked for a couple days and then just stopped working.

I had set this up on a button (SmartThings Button) that I called the Christmas button. When you press the button, it dims the normal lights, turns on the Christmas Tree lights, and starts playing "All I want for Christmas" on Sonos. Since it is now after Christmas, I haven't looked into why the music part stopped working. Will try again if I find another use or next Christmas at least.

1 Like

I love the idea of this :rofl: shame about the song choice though :face_vomiting:. I tried it from the device page but couldn't get it to run.

Did you figure this out?

I tried you method and works perfect.
But instead of using a string, I want to use a global variable, like %globalvar%, when I use it, does not work. Do you have any Idea why? It looks like it pass the parameters but the sonos do not react..

Do you want to pass in your global variable the entire string (http://serverIP/path/file.mp3) or just the song and concatenate with the defined server/path ?

And which version of the HE are you running ? I could give a try myself, using a global variable and see how it behaves.

My idea is:

An app downloads the URL of different pieces of audio (part of radio programs), like https://IPADDRESS/radio/Metro-20-02-18-07-00.mp3 and put the info a global variable

i Created a RM when detect the change of the global variable triggers the playtrack, as you teach us.

I am running 2.1.8.117

04%20PM

Another alternative is to understand how to playtrack in code ... I am not understanding the parameters to send to make it work...

@SmartHomePrimer How did you get around the TimeCapsule password requirement to access the Disk?

I cannot find a way to turn off password protection.

Thanks

Solved it - Access the music lib on a Mac and use everyone - read only

That worked!!

Thanks

1 Like

Also, mine is a Synology NAS that I named "TimeCapsule" so the family didn't notice the difference, but glad you solved it.

1 Like

Hi, thanks for the tips on this thread, helped me get this working. Here is what I did incase it helps anyone...

I have a Qnap for SMB and NFS but for this connection I used WebDav.

  1. Create a share (or share existing if you wish), I created hubitat (permissions not important yet)
  2. FInd WebDav: Control Panel --> Applications --> Web Server --> WebDav tab
  3. Tick enable, and you must tick "webDAV" (note1)
  4. Tick "used dedicated port for webDav service
  5. Tick "HTTP port number", default is 5000 for me (note2)
  6. Click apply, wait for it to setup the service fully (including the otherwise hidden webDAV user mgmt area)
  7. Navigate to Control Panel --> Privilege --> Shared Folders
  8. For the target share click on the "edit shared folder permissions" icon
  9. Select "webDAV access" from the dropdown box then tick the tick box at the bottom that starts with " Allow guests to have read access...". Then click Apply.
  10. Put a track within your share
  11. Within your Hubitat action select "play track"
  12. Enter command like mine "http://192.168.0.3:5000/hubitat/Alice_Cooper_Be_My_Lover.mp3"

I avoided spaces within the file name so it looks a little neater. If I'm allowed to I'll upload a image of my rule, still new here so might not be allowed yet. So impressed this works!

Good luck! :sunglasses:

Note1: Using "share folder permissions" as you would for windows mounts did not work for me, it always prompted for a password because the guest attribute did not transpose across to the webDAV from the shared folder permissions function. webDAV has a dedicated guests tick box that needs ticking to avoid the password enforcement.

note2: I tried https but I don't think the Sonos integration allows the secure protocol, I'm not bothered about this as it's my internal network with strict firewalls and no external access - and it's used for just one network share.

Here is my test button, dims lights to red then plays the music. Pretty impressive functionality!