[BETA] - MP3 Event Player - Using Sonos Speakers

OK.. as the Sonos integration has been released it's time for an app :slight_smile:

As I've only had a short time to test this since the integration was released, I'm calling this a BETA
Hopefully, when a few more people test it, if everything is ok then I'll mark it as a release.
PLEASE if you find any bugs or find it doesn't work for you let me know.. I can't fix what I don't know about :slight_smile:

This will allow you to play any mp3 hosted on a website, either locally or on the internet, as a reaction to an event.
(It's fairly basic but seems to work well for me)

Events you can use to play an mp3:

  • Acceleration
  • Appliance Power Monitor - Great for laundry notifications.
  • Contact Open/Closed
  • Carbon Monoxide Detected
  • Presence - Arrival/Departure
  • Leak Detected
  • Mode Change
  • Motion Active
  • Smoke Detected
  • Switch - ON/OFF
  • Time - Schedule a reminder

This is a Parent/Child app setup so you need to install both bits of code for this to work.
I suggest you install both parts and then 'Load New app' (for just the parent) then save it before creating any new events (which will use the child to create new apps within the parent)

OK... Here is the code.. hopefully someone will find it useful

Current Versions:
Parent: 1.0.1
Child: 1.2.3

https://github.com/CobraVmax/Hubitat/tree/master/Apps/MP3%20Event%20Player

I have been using Amazon Polly to create and download a number of MP3s for my events
(Until we get TTS - Then I can do a lot more)

You will need to create a free account to use Polly


Then you can just host them somewhere and use the event player.

For testing purposes…

I have uploaded a test file to one of my websites to confirm everything is working ok.
If you configure an event (e.g. virtual switch to ON) you can use this test file to confirm everything is ok with your Sonos setup…

URI: http://hubitat.xurria.co.uk/mp3/

File: testfile.mp3

I forgot to mention… ALL URI and filenames are case sensitive…

Andy

3 Likes

Does this play the mp3 and resume if something is already playing on the Sonos?
If so, I’ll give it a go.

I don’t think ‘playTrackAndRestore’ or resume has been implemented for the sonos driver yet.
This app uses the ‘playTrack’ command to play the mp3s

I would expect this to just play the track then stop… not tested that though as I only use the speakers for announcements.

Not sure… But I can tell you that the official API for Sonos does not support play another track and then resume previous. Not sure how others are doing it these days.

playText, playTrackAndResume and playTrackAndRestore are not functions provided by the Sonos UPNP API.
playTrackAndResume and playTrackAndRestore are not part of the official music player capability, both of these are defacto standard custom commands.
The three of these commands are slated for release in the Sonos integration after we have platform TTS available.

2 Likes

@mike.maxwell

Thanks for the explanation Mike

Andy

1 Like

@mike.maxwell
Mike, is there a way to record the currently playing track into a state variable so after the announcement it could be resumed?

Andy

Yes, that’s part of the next release

1 Like

Brilliant!

Can it resume a track or will it start the track over?

1 Like

can it, sure, will it now no.
resume is not implemented at the moment,

2 Likes

Can't seem to get any sound to play on the Sonos:one. I've setup a test event using a switch to set it off and using your test file for the mp3. It seems to fire off ok but nothing comes out of the Sonos.

Edit 1: Doing a little more digging...I loaded up the sonos app on my phone and when it tries to play the mp3 it displays a little popup on the screen saying "Unable to play 'testfile.mp3' - the song is not encoded correctly".

Edit 2: Just tried it with another mp3 I used Polly to create and getting the same results. Mp3 is being pushed to the Sonos but getting the same message...the song is not encoded correctly.

Edit 3: Download a Boing sound off the internet and tried the event again. It plays! Seems to be something with the Polly mp3 that it doesn't like.

Edit 4: Well, seems now that I got the Boing.mp3 to play the ones from Polly are playing too. Can't explain it but it's now working. Very weird but very glad to have announcements within HE!

Thanks

@Cobra, any way we good get a ‘Test’ button to play the mp3 once selected? Would be great to know that nothing was fat fingered entering the URL and that the mp3 is valid without waiting for the event to fire.

@bptworld
Bryan
Thanks for testing this.
I’ll investigate
Good idea on the ‘test’ button - I’ll see what I can do.

Andy

Bryan

try this for the URI:

x-rincon-mp3://securendpoint.com

with the same testfile.mp3

If this works for you then I’ll recode it slightly to incorporate the change
Please let me know

Andy

Interesting, I setup a test event to try the new URL. When I fire the event it’s not playing the testfile.mp3 but it is playing the last mp3 that I was playing around with. Keeps telling me the “Dryer is Finished”.

It is makes a difference, my MP3’s are being stored on Dropbox. The link looks like this:
https://dl.dropboxusercontent.com/s/a9osfk94g4uxs05
Sonos-Thedryerisfinished.mp3

Yep!
I just tested and got the same result
Looking now :slight_smile:

1 Like

Bryan
it’s past 1am here (UK) so I can’t really see what’s going on.
I’ll have a look in the morning and get back to you

No problem, thanks

OK… I know it’s late but this was bugging me

try this for the URI:

http://hubitat.xurria.co.uk/mp3/

with the same testfile.mp3

This seems to work as it didn’t like the URL redirection I was using

The problem you might have with dropbox is that it uses https which the sonos api doesn’t seem to like

Download the Hubitat app