Playing local MP3 on Sonos

I thought I’d share how I got the playback of local .mp3 files working through Sonos. I added some .mp3 files to /etc/openhab/sounds and then created a new Samba share:

[openHAB-sounds]
  comment=openHAB sound files
  path=/etc/openhab/sounds
  writeable=yes
  public=no
  create mask=0664
  directory mask=0775
  guest ok = yes
  veto files = /Thumbs.db/.DS_Store/._.DS_Store/.apdisk/._*/
  delete veto files = yes

The crucial bit seems to be guest ok = yes. That’s what stopped the “access denied” message in Sonos. The format of the URI in my case is:

x-file-cifs:///openHAB-sounds/mysound.mp3

For Sonos, it’s important that the hostname be in capitals, apparently, and the filenames and directories need to be URL-encoded if they contain spaces or what have you.

You may want to create a separate directory with more restricted permissions for this purpose.

1 Like

nice thank you, is there a simplier way to achieve this? or this must be done usiung samba ? i am thinking about direct stream to the speaker?

1 Like

Sorry, it’s the only way I know…

I don’t have a Sonos device, but every Sonos thing should have a corresponding audio sink in openHAB for the “play sound” action. openHAB then acts as a http proxy to serve sound to the Sonos device.
You shouldn’t need to do complex share. Maybe I didn’t get something, but why don’t you use this functionality ?

I don’t know anything about that functionality. This is the way I did it on my previous home automation system, so it was the easiest way to migrate my rules.

OK, indeed it’s not easy to know everything that openHAB can do.
So here is the documentation, if any of you is interested.

Just add a Sonos Thing with the help of the Sonos binding. And then you can use the play sound / play stream action with any sound in the openHAB sound directory (or any sound available on the network/internet with http). The play sound action is available in the GUI, in blockly, in the DSL, and in every JSR223 langage.

1 Like

Thanks, I’ll play with it at some point.

You can also play mp3 as overlay, so what is currently being played is not interrupted.
This is done by connecting to a local websocket end point for the local speaker.

1 Like

Oh, now that would be very useful. Now I really have to investigate.

I use JSR223. I presume I’d have to implement something similar myself. I also see now that it requires S2. Currently mine are on S1.