Pulse Audio binding

Gee that’s strange, that’s all the permissions OH should need. Are you running AppAmour or SE Linux security checking systems, if not that’s all I can think of.

No SE Linux or AppArmour, just bare bones Debian 9 with simple gnome desktop.
The plot thickens, last night I broke it and then half fixed it again. But openHAB still gets blocked. I plurged then reinstalled pulse as per several threads on the web. Didn’t fix problem. Then I set pulse to system and should no longer use permissions… still OpenHAB blocked
I think I need to dig into the .cfg files.I think the out of the box configuration is set to not allow connections for security

Ok, I remember adding the last line (tcp) to /etc/pulse/default.pa, it was recommended by some docs I read, don’t remember what docs though.

Here’s the section in that file where I appended the tcp line:

### Modules to allow autoloading of filters (such as echo cancellation)
### on demand. module-filter-heuristics tries to determine what filters
### make sense, and module-filter-apply does the heavy-lifting of
### loading modules and rerouting streams.
load-module module-filter-heuristics
load-module module-filter-apply
load-module module-cli-protocol-tcp

EDIT: Found it, it’s in the PA Binding doc, 2nd line under ‘Supported Things’

I’m thinking you are right rastus, I think I did that at one point the first time and then I could enter commands in the terminal for the pa command line tool (pactl)
example:
pactl -s 192.168.7.2 list sinks
At first I could only get them to work as root. That led me to permissions issue which led me to add openhab to all groups
I wan’t sure I had the syntax right for the load-module command so thank you for the example
I will try again tonight.

I GOT IT WORKING!!! with a bluetooth speaker!

I have got the pulseaudio binding working in OpenHAB… yes

I made items for a sink and am using the REST api to control volume and mute on a blue tooth speaker

don’t ask me how, I have no idea. I’ve tried so many things with pulseaudio on my system, I don’t think it was the binding. Once I got the system to play sounds, I opened Paper UI and there were a few items in my inbox.
I got a ton of errors at first and think it may be because the items had a null value.

13:41:26.414 [INFO ] [smarthome.event.InboxRemovedEvent    ] - Discovery Result with UID 'pulseaudio:sink:12cb5aaa:bluez_sink_D8_8D_83_22_B0_1B_a2dp_sink' has been removed.
13:41:26.417 [INFO ] [ome.event.ThingStatusInfoChangedEvent] - 'pulseaudio:sink:12cb5aaa:bluez_sink_D8_8D_83_22_B0_1B_a2dp_sink' changed from UNINITIALIZED to INITIALIZING
13:41:26.422 [INFO ] [ome.event.ThingStatusInfoChangedEvent] - 'pulseaudio:sink:12cb5aaa:bluez_sink_D8_8D_83_22_B0_1B_a2dp_sink' changed from INITIALIZING to OFFLINE
13:41:26.422 [INFO ] [ome.event.ThingStatusInfoChangedEvent] - 'pulseaudio:sink:12cb5aaa:bluez_sink_D8_8D_83_22_B0_1B_a2dp_sink' changed from OFFLINE to ONLINE
13:41:32.959 [INFO ] [smarthome.event.InboxRemovedEvent    ] - Discovery Result with UID 'pulseaudio:sink:12cb5aaa:auto_null' has been removed.
13:41:32.960 [INFO ] [ome.event.ThingStatusInfoChangedEvent] - 'pulseaudio:sink:12cb5aaa:auto_null' changed from UNINITIALIZED to INITIALIZING
13:41:32.961 [INFO ] [ome.event.ThingStatusInfoChangedEvent] - 'pulseaudio:sink:12cb5aaa:auto_null' changed from INITIALIZING to OFFLINE
13:41:49.069 [ERROR] [ernal.handler.PulseaudioBridgeHandler] - An exception occurred while calling the DeviceStatusListener
java.lang.IllegalArgumentException: Value must be between 0 and 100
	at org.eclipse.smarthome.core.library.types.PercentType.validateValue(PercentType.java:58) ~[?:?]
	at org.eclipse.smarthome.core.library.types.PercentType.<init>(PercentType.java:43) ~[?:?]
	at org.openhab.binding.pulseaudio.internal.handler.PulseaudioHandler.onDeviceStateChanged(PulseaudioHandler.java:232) ~[?:?]
	at org.openhab.binding.pulseaudio.internal.handler.PulseaudioBridgeHandler.lambda$0(PulseaudioBridgeHandler.java:67) ~[?:?]
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:?]
	at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308) [?:?]
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180) [?:?]
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294) [?:?]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:?]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:?]
	at java.lang.Thread.run(Thread.java:748) [?:?]
13:42:20.081 [ERROR] [ernal.handler.PulseaudioBridgeHandler] - An exception occurred while calling the DeviceStatusListener
java.lang.IllegalArgumentException: Value must be between 0 and 100
	at org.eclipse.smarthome.core.library.types.PercentType.validateValue(PercentType.java:58) ~[?:?]
	at org.eclipse.smarthome.core.library.types.PercentType.<init>(PercentType.java:43) ~[?:?]
	at org.openhab.binding.pulseaudio.internal.handler.PulseaudioHandler.onDeviceStateChanged(PulseaudioHandler.java:232) ~[?:?]
	at org.openhab.binding.pulseaudio.internal.handler.PulseaudioBridgeHandler.lambda$0(PulseaudioBridgeHandler.java:67) ~[?:?]
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:?]
	at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308) [?:?]
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180) [?:?]
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294) [?:?]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:?]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:?]
	at java.lang.Thread.run(Thread.java:748) [?:?]
13:42:51.092 [ERROR] [ernal.handler.PulseaudioBridgeHandler] - An exception occurred while calling the DeviceStatusListener
java.lang.IllegalArgumentException: Value must be between 0 and 100
	at org.eclipse.smarthome.core.library.types.PercentType.validateValue(PercentType.java:58) ~[?:?]
	at org.eclipse.smarthome.core.library.types.PercentType.<init>(PercentType.java:43) ~[?:?]
	at org.openhab.binding.pulseaudio.internal.handler.PulseaudioHandler.onDeviceStateChanged(PulseaudioHandler.java:232) ~[?:?]
	at org.openhab.binding.pulseaudio.internal.handler.PulseaudioBridgeHandler.lambda$0(PulseaudioBridgeHandler.java:67) ~[?:?]
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:?]
	at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308) [?:?]
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180) [?:?]
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294) [?:?]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:?]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:?]
	at java.lang.Thread.run(Thread.java:748) [?:?]
13:43:22.102 [ERROR] [ernal.handler.PulseaudioBridgeHandler] - An exception occurred while calling the DeviceStatusListener
java.lang.IllegalArgumentException: Value must be between 0 and 100
	at org.eclipse.smarthome.core.library.types.PercentType.validateValue(PercentType.java:58) ~[?:?]
	at org.eclipse.smarthome.core.library.types.PercentType.<init>(PercentType.java:43) ~[?:?]
	at org.openhab.binding.pulseaudio.internal.handler.PulseaudioHandler.onDeviceStateChanged(PulseaudioHandler.java:232) ~[?:?]
	at org.openhab.binding.pulseaudio.internal.handler.PulseaudioBridgeHandler.lambda$0(PulseaudioBridgeHandler.java:67) ~[?:?]
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:?]
	at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308) [?:?]
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180) [?:?]
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294) [?:?]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:?]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:?]
	at java.lang.Thread.run(Thread.java:748) [?:?]
13:43:53.112 [ERROR] [ernal.handler.PulseaudioBridgeHandler] - An exception occurred while calling the DeviceStatusListener
java.lang.IllegalArgumentException: Value must be between 0 and 100
	at org.eclipse.smarthome.core.library.types.PercentType.validateValue(PercentType.java:58) ~[?:?]
	at org.eclipse.smarthome.core.library.types.PercentType.<init>(PercentType.java:43) ~[?:?]
	at org.openhab.binding.pulseaudio.internal.handler.PulseaudioHandler.onDeviceStateChanged(PulseaudioHandler.java:232) ~[?:?]
	at org.openhab.binding.pulseaudio.internal.handler.PulseaudioBridgeHandler.lambda$0(PulseaudioBridgeHandler.java:67) ~[?:?]
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:?]
	at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308) [?:?]
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180) [?:?]
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294) [?:?]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:?]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:?]
	at java.lang.Thread.run(Thread.java:748) [?:?]
13:44:24.117 [ERROR] [ernal.handler.PulseaudioBridgeHandler] - An exception occurred while calling the DeviceStatusListener
java.lang.IllegalArgumentException: Value must be between 0 and 100
	at org.eclipse.smarthome.core.library.types.PercentType.validateValue(PercentType.java:58) ~[?:?]
	at org.eclipse.smarthome.core.library.types.PercentType.<init>(PercentType.java:43) ~[?:?]
	at org.openhab.binding.pulseaudio.internal.handler.PulseaudioHandler.onDeviceStateChanged(PulseaudioHandler.java:232) ~[?:?]
	at org.openhab.binding.pulseaudio.internal.handler.PulseaudioBridgeHandler.lambda$0(PulseaudioBridgeHandler.java:67) ~[?:?]
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:?]
	at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308) [?:?]
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180) [?:?]
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294) [?:?]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:?]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:?]
	at java.lang.Thread.run(Thread.java:748) [?:?]
13:44:55.130 [ERROR] [ernal.handler.PulseaudioBridgeHandler] - An exception occurred while calling the DeviceStatusListener
java.lang.IllegalArgumentException: Value must be between 0 and 100
	at org.eclipse.smarthome.core.library.types.PercentType.validateValue(PercentType.java:58) ~[?:?]
	at org.eclipse.smarthome.core.library.types.PercentType.<init>(PercentType.java:43) ~[?:?]
	at org.openhab.binding.pulseaudio.internal.handler.PulseaudioHandler.onDeviceStateChanged(PulseaudioHandler.java:232) ~[?:?]
	at org.openhab.binding.pulseaudio.internal.handler.PulseaudioBridgeHandler.lambda$0(PulseaudioBridgeHandler.java:67) ~[?:?]
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:?]
	at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308) [?:?]
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180) [?:?]
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294) [?:?]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:?]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:?]
	at java.lang.Thread.run(Thread.java:748) [?:?]
13:45:26.141 [ERROR] [ernal.handler.PulseaudioBridgeHandler] - An exception occurred while calling the DeviceStatusListener
java.lang.IllegalArgumentException: Value must be between 0 and 100
	at org.eclipse.smarthome.core.library.types.PercentType.validateValue(PercentType.java:58) ~[?:?]
	at org.eclipse.smarthome.core.library.types.PercentType.<init>(PercentType.java:43) ~[?:?]
	at org.openhab.binding.pulseaudio.internal.handler.PulseaudioHandler.onDeviceStateChanged(PulseaudioHandler.java:232) ~[?:?]
	at org.openhab.binding.pulseaudio.internal.handler.PulseaudioBridgeHandler.lambda$0(PulseaudioBridgeHandler.java:67) ~[?:?]
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:?]
	at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308) [?:?]
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180) [?:?]
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294) [?:?]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:?]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:?]
	at java.lang.Thread.run(Thread.java:748) [?:?]
13:45:57.152 [ERROR] [ernal.handler.PulseaudioBridgeHandler] - An exception occurred while calling the DeviceStatusListener
java.lang.IllegalArgumentException: Value must be between 0 and 100
	at org.eclipse.smarthome.core.library.types.PercentType.validateValue(PercentType.java:58) ~[?:?]
	at org.eclipse.smarthome.core.library.types.PercentType.<init>(PercentType.java:43) ~[?:?]
	at org.openhab.binding.pulseaudio.internal.handler.PulseaudioHandler.onDeviceStateChanged(PulseaudioHandler.java:232) ~[?:?]
	at org.openhab.binding.pulseaudio.internal.handler.PulseaudioBridgeHandler.lambda$0(PulseaudioBridgeHandler.java:67) ~[?:?]
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:?]
	at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308) [?:?]
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180) [?:?]
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294) [?:?]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:?]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:?]
	at java.lang.Thread.run(Thread.java:748) [?:?]

There are more if anybody is interested in trying to figure out what is going on there. This is when I first click on the items in my inbox and it makes things

1 Like

the following does not work

smarthome:audio play doorbell.mp3

the default sink is set to

System Speaker (with mp3 support)
in Paper UI
any hints?

Edit: I got this working but still having problems with it working reliably
see thread

I wanted to add that the default port in the documentation is wrong,
pulseaudio, by default opens port 4713, not 4712, so that’s where some errors might arise

Thank you for the clue and welcome to the community Robert. Most of my problems with audio in OpenHAB were cured by switching from plain vanilla Debian to Mint Linux but I’ve still yet to get the pulse binding to do anything. If the documentation for the binding is incorrect I will make a pull request and fix it.

Thanks Andrew, i spent some time reading the sources. i was wrong: 4712 is the port to be used for the cli protocol. You can test this with “echo -e ‘list-sinks\n’ | nc 4712”
For this to work the module-cli-protocol-{tcp,unix} has to be loaded first.

alright, i’ve had success doing this.
I have an online sink now.
I fixed the Regex patterns used in the binding to match given sink names against the output from pulseaudio. I’ll open a pull-request on the binding

1 Like

Adding this line to the file /etc/pulse/default.pa and a restart of the host system seems to have gotten pulseaudio binding working for me. I can now control the volume of the system audio from OpenHAB
thanks everyone for help

1 Like

This worked for me!!! Great thanks you saved me XD. Worked hours on geting pi to output sound…

How were you able to get a sink to output the playsound(doorbell.mp3)? I only have the system speaker sink…which is not working

It’s been so long since I done this I barely remember now. It could be a permissions issue, they’re common in Linux. Also if you’re using a Pi, make sure it’s a powered speaker and config.txt is setup to output to audio jack.

Hello,

I made a PR which allow the binding to expose an audio sink Thing as an audio sink in openHAB terminology (allowing sound action to play directly against the sink). This send raw audio data to a pulseaudio server. Could also be a remote one the network (this is the main use case I think).

For this, I used the simple protocol (sending raw audio to a port linked to a sink).
So you have to use the pulseaudio module-simple-protocol-tcp server side, which will, once loaded, listen on a port and forward everything to the sink you have configured when loading the module.

pactl load-module module-simple-protocol-tcp sink=<sink_name> port=4711
(The binding now auto load the relevant module on the pulseaudio server)

The binding use the existing Thing “Audio Sink” and extends it by allowing it to connect to the simple protocol port and broadcast raw audio (you need to activate the function in the thing configuration)

I made a test release, testing welcome. The JAR seems OK for 3.1.0 and 3.0.1.

1 Like

Ok, so, Here I am :slight_smile:

The plugin is installed, the previous thing definition are deleted, but I’m not able to make sure I removed the previous version of the bundle, as I’m running OH in Docker, I didn’t find the folder where are placed the different bindings… So, quick help to remove the old one might be appreciate :wink: )

With the new bundle, I succesfully created the bridge which is now “Online”

Meanwhile, after creating the Sink, It’s still “offline”. I’m suspecting the “port” definition to be wrong

I basically re-used the same as the PA Bridge, but I’m maybe wrong there…

For the Sink definition, NOTHING appeared in the logs of KARAF. Seems strange…

Voilà, I’m getting the following logs : (strange as I can use the server from another server)

18:58:38.851 [DEBUG] [.pulseaudio.internal.PulseaudioClient] - reading sinks
18:58:39.355 [DEBUG] [.pulseaudio.internal.PulseaudioClient] - Pulseaudio server 192.168.1.7: 0 modules and 0 items updated

Hello (again) :slight_smile: ,

The “Simple Protocol Port” option is just a “preference”. It means that the binding will try to load the “module-simple-protocol-tcp”, on the destination pulse audio server, on this port first (it will not even bother to try if it found it running on another port). And if it’s not OK (ports already taken, etc), it will try another port (3 attempts)
Besides, the openhab audio sink functionality with simple-protocol, working or not, doesn’t change the status “ONLINE” or “OFFLINE” of the sink thing.
So the issue is somewhere else, the sink thing is not configured properly.
For the sink to be ONLINE, the bridge must find a sink on the pulse audio server with the exact same name.

Could you please check the result of the following command on your rapsberry pi :

pactl list sinks

And this is the same command, but it uses the cli-protocol on port 4712 to get the sink information. This way we check the proper configuration of the module-cli-protocol-tcp :

echo “list-sinks” | netcat localhost 4712

These two commands should return the same output, and you should see the sink(s) available on the rasbperry. The “name: <sink_name>” is the relevant information here

Then, you have to check if, on openhab, you defined the sink thing with the EXACT same name

Hey Gwen, all,

I put in the following section some infos to resume my setup, that will give you a better understanding where I am.

Environment

Everything runs in EsxI, why you’ll maybe notice “full computer” for only “a capability”.

  • Linux machine on Debian 9, running docker, let’s call this machine Server*
    ** In this machine, several containers running, between them, OpenHab 3, let’s call it DockOH

  • Linux machine on Debian 10, running pulseaudio only, serves as PA, let’s call it PulseAudioServer

The Server connects natively via PulseAudio, as a client to PulseAudioServer, sound is working fine, and played to the PA

The DockOH, as a container, does not have access to the soundcard, why I’m trying to get access to a decentralized PulseAudio, in order to backup and maintain my setup more easily, without cheating the docker environment (like mapping /dev/snd, giving privileges,…)
The DockOH has your new binding running in it, launching connection to PulseAudioServer

On PulseAudioServer, I tried the following :

  • Tried the "echo “list-sinks, …”, the command opens something and don’t close – nothing in the logs

  • Netcat localhost and send raw data manually, typing “list-sinks” manually in the terminal. The connection closes after sending 18 characters, regardless the way I enter it (in bulk, or one by one). The logs of PulseAudio sends me the following :
    *pstream.c: Received SHM frame on a socket where SHM is disabled.*
    and then closes the connection with the following
    [pulseaudio] client.c: Freed 63 "Native client (TCP/IP client from 127.0.0.1:55758)"
    [pulseaudio] protocol-native.c: Connection died.

(salme behavior with Telnet on port 4712)

I found this : PulseAudio discussion on Narkive Forum, but this didn’t help to go further.

I don’t think the error is coming from the lack of SHM (Shared Memory), this error comes as the command is too large for the buffer, and it request Share memory space to just receive it properly. I don’t understand why the client can connect perfectly from a “regular” pulseaudio client (Server) but that I can’t access it with another one. The connection dies everytime…

For now, still searching, will update the post if I find something else.

could you please share your /etc/pulse/* files ?
Really wondering what I did wrong here

For info, I also tried to sniff the TCP traffic while trying the echo “list-sinks” | netcat…
Here it is : tcpdump for PulseAudio | netcat connection - Pastebin.com