Volume control for System Speaker and playSound

  • Platform information:
    • Hardware: x86-64
    • OS: OpenSuSE Tumbleweed 20200611
    • Java Runtime Environment: java-11-openjdk-11.0.7.0-1.5
    • openHAB version: openhab2-2.5.6~S143-1
  • Issue of the topic: please be detailed explaining your issue

How can I play a sound to the openHAB server’s speakers at a desired volume?

Configuration->System->Audio sink = “System Speaker”.

playSound(“barking.mp3”) in a rule script plays a sound through the server’s speakers, as intended, but at the maximum volume, which is too loud. In contrast with the documentation, playSound() doesn’t accept a second PercentType argument to control sound, e.g.,
playSound(“barking.mp3”, new PercentType(5))
results in the logs showing “The name ‘playSound’ cannot be resolved to an item or type”.

Preceding the playSound() command with setMasterVolume(0.1) still plays the sound at the maximum volume. The log file indicates that ‘test.rules’ was refreshed, and there are no warnings in this case; it silently fails to change the volume.

That’s a problem I have been having for ages, too, on a RPi. Have not heard of any solution, sorry.
(well other than to insert another processing layer outside openHAB such as Pulseaudio).

Thanks.

Did you get something working reliably with PulseAudio? I don’t have it running at system-level, but a particular user will always be logged in and running it. But then I somehow need to give the (different) openhab user access through module-cli-protocol-tcp, right? Do I also need to mess around with the JVM sound configuration file to tell it to use PusleAudio? Then do I need yet another binding to PulseAudio to send volume change commands to it? There must be other people who want to have the computer talk and make sound in response to sensed events. What’s the typical way of doing that?

1 Like

Alexa/Google Home, Google or other TTS, Sonos, Chromecast, …

This is a topic very near and dear to my soul.

yes… YES!!!
I personally think this is a very good way of getting my attention.

Here is a thread about getting the pulse audio to work, and it does finally work on my setup. I can control the volume on my host system (Mint on desktop PC)

here is another thread with some more sound related problems discussed

Markus and Andrew: Thank you very much for the helpful and fast replies!!!

I set up the PulseAudio bindings, created a Thing for the PulseAudio Server and another Thing for the appropriate sink. I also created a dimmer item for the sink. I can set its volume dimmer, and read back the set value. However, I don’t know how to get it to send sound to the desired (PulseAudio) sink.

When I
playSound(“Alsa_output_usb_Focusrite_Scarlett_2i2_USB_00_analog_stereo”, “doorbell.mp3”)
the logs indicate “Failed playing audio stream ‘org.eclipse.smarthome.core.audio.FileAudioStream@5d3463e’ as no audio sink was found.”

Calling it pulseaudio:sink:208d0fe0:alsa_output_usb_Focusrite_Scarlett_2i2_USB_00_analog_stereo results in the same failure.

To find the correct name for the sink, I logged into the CLI
openhab> smarthome:audio sinks

  • System Speaker (enhancedjavasound)
    Web Audio (webaudio)

That seems to indicate that there are no new sinks.

How to I get it to play to the PulseAudio sink for which I can (apparently) set volume?

Solved.

load-module module-cli-protocol-tcp
and
load-module module-native-protocol-tcp auth-ip-acl=127.0.0.1

In the openhab account, set the client.cnf default-server to 127.0.0.1. Now the audio goes through native TCP port and the commands from the PulseAudio bindings in openHAB go through the cli TPC port.

1 Like

I’d like to add that for those using Windows, I found that using foobar2000 available at foobar2000.org with theUpNP renderer, server and control point component as a UpNP renderer controlled by the UpNP binding at the end of thread: DLNA / UPNP binding works great for me.