Playing sounds on openhab clients

Here is another newbie question.

The multimedia doc page states the following:

playSound(String sink, String filename)` : plays a sound from the sounds folder to the given sink(s)

As I understand it, the sink “webaudio” is supposed to reside with any active openhab web clients, rather than on the machine where the server is running.

I have an openhab client running on an Android phone. Since the documentation explains that the openhab client will route the sound file using the web browser, I make sure that Chrome is also running on the Android phone.

I then defined the following rule:

rule "Pierre_est_la" when Item Presence_mobile_Pierre changed from OFF to ON then playSound("webaudio","doorbell.mp3") end

In practice, that rule does fire whenever its condition is met. However, the soundfile continues to be played on the server machine and the client machine remains silent.

In the event log, every time the rule is fired the following lines are printed:

2019-03-16 15:51:25.537 [ome.event.ItemCommandEvent] - Item 'Presence_mobile_Pierre' received command ON 2019-03-16 15:51:25.552 [nt.ItemStatePredictedEvent] - Presence_mobile_Pierre predicted to become ON 2019-03-16 15:51:25.552 [vent.ItemStateChangedEvent] - Presence_mobile_Pierre changed from OFF to ON 2019-03-16 15:51:25.621 [arthome.event.PlayURLEvent] - Play URL '/audio/aedeecbb-bbf8-4e74-9999-6f6d1029e484'.

Any help would be greatly appreciated.

I now realize that my original question was most likely based on a wrong assumption. From what I now understand, it is not the OH app that needs to be running on the client machine but rather a browser that includes an OH extension.

There is indeed an existing OH extension for the Chrome browser. However, as far as I can see it is not supported on the Chrome versions running on Android phones.

Can anyone confirm that this indeed the current situation?

Many thanks.

Another update on this.

I now have the OH Chrome extension running on a different Windows PC. The extension is now connected to the OH server (on the other PC) and I see my defaut sitemap in a small Chrome popup. Unfortunately, I still have the same problem: whenever the rule shown is my original message is fired, the sound continues to be played on the server machine and the PC with the Chrome OH extension remains silent. I still get the following line in the event log:

2019-03-16 16:52:15.582 [arthome.event.PlayURLEvent] - Play URL '/audio/ad66d23a-f061-4496-972d-671eec652596'.

Don’t think you need extensions. Have you tried visiting the “plain ordinary webpage” of BasicUI?

1 Like

The problem is that I want the sounds to play on the client machine. Something is needed to direct the sound to the client rather than play it on the server machine. I believe that this is what the following piece of code is supposed to do:

playSound("webaudio","doorbell.mp3")

But thus far I have not managed to get it to work.

I’m completely lost by your question.

I use the playsound & say commands in rules a lot and I haven’t installed an extension anywhere.
(I route the sound events to webaudio or specific audio sinks like my Chromecast devices)

The ONLY thing that needs to be setup / running for webaudio to work is a web browser page on a (one or many) client machines, that is looking at your openHAB2 server, via…

BasicUI
ClassicUI
PaperUI
HabPanel

(I only use PaperUI and HabPanel (Inc HabPanelViewer app))

When you say “the sound continues to play on the server”, do you mean you can hear the sound? Or that you see it being triggered in a log?

If you can hear it, you must have a web browser running with an openHAB2 UI open?

I hope this helps you.

Regards,
Stuart

update

Don’t forget that the openHAB2 app or browser must be running (not sleeping) on your client machine.

My windows laptop will play audio if the browser is simply running, whereas my Android devices will put the browser to sleep if it’s not in the foreground.

I think the same logic applies to the openHAB2 app.

Ok, let me try again:

I have the following rule in my current setup:

rule “Pierre_est_la”

when

Item Presence_mobile_Pierre changed from OFF to ON

then

playSound(“webaudio”,“doorbell.mp3”)

end

Whenever the trigger condition is met, the audio file get played through the loudspeaker attached to the OH server machine.

However, the audio file is not played through the loudspeaker of a client machine on which the basic UI is running in a browser pointing to the address of the OH server. I can indeed produce the relevant condition through the basic UI of the client machine, but the file will anyway only be heard to play on the speaker of server machine.

I hope this is clearer. Thanks for you patience!

Le lun. 18 mars 2019 à 11:51, Stuart Hanlon via openHAB Community bot@community.openhab.org a écrit :

1 Like

Webaudio never worked for me.
Does it only work when you interactively trigger a rule by clicking some UI element ?
@MDAR how is the server supposed to know which webaudio client to send to ?
UIs are stateless, aren’t they, so how is the server supposed to know who’s “ON” ?
And if it does not know, it’ll likely play to default sink which is what I guess happens to @isabellep .
(note the rule trigger - there’s no UI involved).

It sends it to all… Every single one.

Okay Pierre,

I do now understand that what you are documenting is EXACTLY what you’re experiencing, rather than what you intend.

So…

(Please excuse my approach)

Have you checked the basics?

Have you got a PaperUI running on a device that you are happy plays sounds from other sources? (By which I mean, have you played some music on your phone, then opened PaperUI in a web browser on that device)

Which UI are you running on the clients that aren’t responding?

Which flavour of web browser are you using (good tip @mstormi)

Is the volume turned up for that device / or for that bit of software in the audio mixer on that device.
(I know for example that Windows machines allow different volumes for different applications)

Just got that to work on my Windows machine for the first time.
Had to start Internet Explorer though, it did not work with Firefox.

@isabellep do you happen to run a browser on your OH server ?
Would at least explain the sound there.
And on clients it seems to be browser dependent at least.
Also check the output of smarthome:audio sinks to see if the webaudio sink is there.

1 Like

I’ll confess that I’ve only ever used Google Chrome (or Chromium)

The sound comes out fine through Chrome running on the Windows 10 machine which is hosting the OH server.

I tried to get the sound as well on two different client machines.

  • a Windows 10 machine pointing either Chrome or IE to the paper UI on the server machine. I can interact with the paper UI allright but it does not get any of the sounds sent when my rule triggers playSound(“webaudio”,“doorbell.mp3”).

  • an Android phone running Chrome and accessing the paper UI in the same, with the same unfortunate result. I also tried without success using the OH app on the same phone (I suppose this was to be expected as this is not a web browser).

For good measure, I also tried using the OH console on the server machine:

smarthome:audio play doorbell.mp3

The result was the same.

Perhaps there is a bug in the Windows 10 implemantation?

@MDAR @mstormi

Somehow, just a minute ago it started working after I restarted the system. I have no idea what is going on, but for the time being it does work. Thanks.

1 Like

This is very strange.

It really should just work now.

Update

Okay, so now it works it should keep on working.

I’ll keep my fingers crossed for you

@MDAR

Thanks alot!

You mentioned that you have also been able to send sounds to “specific audio sinks like my Chromecast devices”. Can you point me to some info about hos such specific sinks can be defined?

No worries :slight_smile:

Other audio sinks are easy…

You just need to identify how your copy of openHAB2 names them.

Just replace webaudio with the full name of the audio sink.

Thanks for the tip but unfortunately I am not expert at all on such issues. Could you give me of how to find the right name for a given sink, given that my server is running on Windows 10?

Le lun. 18 mars 2019 à 15:29, Stuart Hanlon via openHAB Community bot@community.openhab.org a écrit :

Sorry about my last post: the answer to my question is obviously the command ‘smarthome:audio sinks’.

The more relevant question I had in mind was how can one add new sinks? Is this a matter to be raised only at the OS level (in my case Windows10). I just paired and connected a bluetooth speaker to my Windows server machine. After restarting the OH server, the list of available audio sinks does not include that new Bluetooth sink.

Le lun. 18 mars 2019 à 15:29, Stuart Hanlon via openHAB Community bot@community.openhab.org a écrit :

Now there’s a question.

I’ve no idea how to send audio to a Bluetooth speaker, I assumed a simple one would only stream audio from its paired audio source.
Unlike a device that has a player built in and is instructed “what to play”, rather than just fed a stream.

So would JavaSound or AdvancedJavaSound work?

Just for reference,

When I run the smarthome:audio sinks command in a Karaf console on one of my machines, I get this response

openhab> smarthome:audio sinks
    * Bathroom (chromecast:audio:3f5b31d2c7d792037ef036c498c40a1c)
    Cabin (chromecast:chromecast:dc1c3cdca7c119edda07b157b89213ed)
    Lounge ChromeCast (chromecast:chromecast:9fcd8320e1763a302be40c2accd5decf)
    System Speaker (javasound)
    System Speaker (with mp3 support) (enhancedjavasound)
    TV Room ChromeCast (chromecast:chromecast:aa06742fcb32f738f264f256ad1540c7)
    Web Audio (webaudio)
openhab>

So a playSound command for me might look like this

playSound ("chromecast:audio:3f5b31d2c7d792037ef036c498c40a1c", "doorbell.mp3")