What are the options for playing audio from OH?


I am trying to find the best solution for playing audio from OH. I want to trigger the playing of an .mp3.

I was thinking of setting up another raspberry pi running KODI/XBMC and then use the add to trigger the playback of the audio hosted from a URL.

I don’t think this is the best idea as I would like near instantaneous playback and I don’t think this will deliver what i need, there is a delay for sure.

I wanted to use the OH playStream action but i’m not sure it will playback a .mp3 hosted online.

I don’t want to place the .mp3 on the rpi in the sounds folder as I want to host the .mp3 on the net somewhere.

I did look into placing the sounds on the adafruit soundboard and then using MQTT to send a message to it to playback a sound, but this is more hardware and for sure a short delay.

Any advice or support would be much appreciated.

I don’t know how the soundboard performes, but I can say that MQTT is pretty responsive. I haven’t set it up yet, but looking at mosquitto_sub with a dimmer UI element, I would feel comfortable to control the dimmer via MQTT.

Besides that, I have controlled Kodi not via OpenHAB, but via Yatse, which certainly gives you a better UI than anything you can set up in OpenHAB. Still, I did experience problems that could basically just be solved by looking at the Kodi-GUI (which is annoying, since it is only connected to a projector). So I would not be too optimistic about using solely OpenHAB, if direct interaction when needed causes any inconvenience.

You might want to look at a console based player like MPD. There actually seems to be a binding for that: https://github.com/openhab/openhab/wiki/Mpd-Binding
Since MPD is explicitly designed also for multiroom audio, it should allow reasonable timing.

If this solution has major drawbacks, perhaps you can set something up with MOC, which also features client-server architecture.

I would defenitely recommend taking a look at Max2Play with SqueezServer. A Few good details in this post here:

Hi, thank you for your response, what i was hoping was to play a .,mp3 file hosted on my website. So i would have a URL to the .mp3 file hosted on my website like www.website.com/files/track1.mp3 and i would be able to play this somehow via the raspberry pi via OH.

Would you solution solve this scenario? Ideally i would like to run OH and another media server on the same raspeberry pi


Thank you for your comment.

What i was hoping was to play a .mp3 file hosted on my website. So i would have a URL to the .mp3 file hosted on my website like www.website.com/files/track1.mp3 and i would be able to play this somehow via the raspberry pi via OH.

Would you solution solve this scenario? Ideally i would like to run OH and another media server on the same raspeberry pi

Yes. If you run a squeeze client you can tell it to play an audio file from a URL.

Thank you, i am new to OH and squeezebox, so tell me if I am wrong. OH commands the server to play a url and then the server communicates with a client device to play the file?

Of does the server play the track and there is no use for a client?

Many Thanks

@shep I have found a way around this all.

I thought i would share here so others can benefit from this solution.

I create a node.js program (that will run on the same rpi as OH) that will listen to a mqtt channel for a track Url. The program will the play the track using the player plugin (https://www.npmjs.com/package/player)

The OH rule will be the ‘controller’ publishing track url’s and commands (i.e. play and pause) to the mqtt channel.
The Node.js program will be subscribed to the mqtt channel and will respond accordingly.

Since MQTT is quick there should be no delay in the node.js responding asynchronously. There will no need to delete the track as it is streamed via the player plugin for node.js.

I hope this helps the community.

yes, it does help, thanks.

I use piCorePlayer (a Raspberry Pi image) in our OH2 environment. I setup a separate RPi via wifi as a player with a small wired speaker. This is our central announcement device. I have used one of the Text to MP3 engines out on the net to generate audio files that are played using time based rules.

I use this to prompt our young children no different than the bell at school. These announcements keep my wife and I sane in the morning. We even have a name for our friendly reminder voice, “Charles”.

Children you need to be eating breakfast.
Children we will be leaving for school in 15 minutes.
Children do you have your shoes and jackets on? We are leaving in 5 minutes.
Children it’s time to leave, let’s get in the car.
Has anybody fed the dog?
My personal favorite… Children you smell, please go take a shower!

It really is quite amazing that they respond so well to the announcements.

Hi Tony, Your implementation sounds almost exactly what I need… I’m building an announcement system with several output locations, all wireless, and all picore player driven from openhab 2… Any chance you’d be willing to share the syntax of your rules? I’m having trouble getting the audio files to play (Log shows this error:- 018-07-18 16:41:38.669 [WARN ] [smarthome.model.script.actions.Audio] - Failed playing audio file: File ‘Entrance:HAZMAt1-female-es.mp3’ not found!"

@gregcan - Most of my rules are very simple and cron initiated. Because many are used to prompt my children on a school day, I use a School Day Switch.

I think your File not found might not be rule related. You can definitely test through the OH Console to verify. All of my mp3 files are in the sounds folder. There are a couple of troubleshooting threads on the site, here is one I tested my configuration, Squeezebox Configuration

I will also add that I have switched to almost all Chromecast Audio players now. The RPi Squeezebox effort was another thing that I had to manage.

Rule example
The following rule is easy to follow, but here are the basics. Using cron, this rule executes at 6:45pm every Sunday through Thursday. The first action is to test if the School Day switch is set to ON. This state is set in another rule that executes every evening to determine if tomorrow is a school day. Next a simple Info log that Bedtime is being Announced. Then the playSound command for the mp3 file. Done.

rule "Bed Time"
       Time cron "0 45 20 ? * SUN-THU"
    if (SchoolState.state==ON) {

Has anybody fed the Dog Announcement. Even the dog knows that this is her call to dinner, and you will find her sitting at her bowl in the kitchen. This rule executes every evening at 7:15pm.

rule "Feed Harper"
        Time cron "0 15 19 ? * *"
        logInfo("AnnounceLogger","Feed Harper")

@TonyC, Thanks for the response (and sorry I have taken a while to get back to you). I follow the workings of the rule no problem… My confusion is that your “playsound” commands don’t seem to include any information on (A), the name / IP address of the 2nd pi, nor (B) the path to the specified sound file. I obviously am, but still have to ask… Am I missing something?


Hello Again,

All is well, I found what I was missing! And yes, it was very simple once I opened my eyes! I neglected to assign a variable to the player, and I had the “Sounds” directory on the wrong device … Thanks again for the help.