OpenHAB PlaySound

Hi!

I’m now trying to set up rule that play same mp3 when an event happened. Openhab runs on the Raspberry Pi 2. The rule looks as follows:

rule "Test_ON"
when
Item Flag_1 changed from OFF to ON
then
sendCommand(Flag_2, ON)
end

rule "Test_OFF"
when
Item Flag_1 changed from ON to OFF
then
sendCommand(Flag_2, OFF)
playSound(“FireAlarm.mp3”)
end

It’s works fine but sound not play. At first I was getting an error - “Cannot play sound FireAlarm.mp3: Cannot create AudioDevice” .

Then I found this tip:

JeroenJeroen van Bussel:

1> /etc/default/openhab - change to root (USER_AND_GROUP=root:root)
2> /usr/lib/systemd/system/openhab.service

  • change user and group inside the file
    User=root
    Group=root
  • systemctl daemon-reload
  • systemctl start openhab

and after that the error does not appear, but the file still does not sound. Which way to look?

Thanks!

You first will need to set up an audio sink. It’s fairly easy and well explained here:
http://docs.openhab.org/configuration/multimedia.html
HTH,
-OLI

Thanks, Oli!

I use RP2 for OpenHAB and there are already installed audio sinks:

openhab> smarthome:audio sinks
enhancedjavasound
javasound
webaudio

and it’s play sound by command on the console to the server sound interface:

openhab> smarthome:audio play doorbell.mp3

Then I defined the default audio sink to use in conf/services/runtime.cfg

org.eclipse.smarthome.audio:defaultSink=webaudio

My rules file here:

rule "corLightOn"
when
Item Flag_1 changed from OFF to ON
then
sendCommand(Flag_2, ON)
end

rule "corLightOff"
when
Item Flag_1 changed from ON to OFF
then
sendCommand(Flag_2, OFF)
playSound(“firealarm.mp3”)
end

The available options for org.eclipse.smarthome.audio:defaultSource=

I could not find.

But I do not get sound on mobile devices nor on the web interface.

Ok, so you want to play the sound on the Webbrowser/the app(Android/iOS).
If your test playing on the server itself was OK, maybe you should check if your remote devices can play sound in general?

Comment
Obviously, the browser needs to be opened and have a compatible openHAB UI running. Currently, this feature is supported by Paper UI and HABPanel.

from
http://docs.openhab.org/configuration/multimedia.html

Thanks, rossko57!

You’re right, when I used the classic web interface and on Windows PC Firefox browser I had a sound. But in Firefox or Safary on the iPad or Android tablet, there is no sound (of course, the sound volume on the tablets is enabled), but in this case, the sound appears in parallel on the on the Win PC.

Hi @vismart

just a suggestion regarding your upper post: do not put root as User and Group in your service file. It’s not necessary to run OpenHAB as root, and you actually do not want to.

Try to limit processes to a minimum, that run as root. A bug or harmful code could have much impact to your system otherwise.

supported by Paper UI

maybe you mean Basic UI ? which based on googles paper material design web interface ?

Hi

I’ve a problem with playSound and webaudio. My Openhab is running on a Raspi 3. Only when I use Chrome on a Win10 PC I can hear the sound, with all other browsers ( Edge, Firefox and Safari on Ipad) I can’t hear it.
Anyone any idea?
Thanks

Same problem here, with chrome it also works on a tablet with android, if that maybe helps.

Has anyone found a solution which works with other browsers?

Hi again. Currently I have the same issue and I have not been able to find a solution.

Has anyone found how to play a sound from the server on safari, in an iPad with Habpanel? It only works in a windows 10 computer with Chrome.

Thanks.