[SOLVED] Unable to play audio in rule when using docker

  • Platform information:
    • Hardware: Raspberry Pi 4
    • OS: Raspbian
    • Java Runtime Environment: openjdk 1.8.0_222 is installed in the openhab docker image
    • openHAB version: openhab:milestone docker image
  • Issue of the topic:

I have created a rule to play a sound when my contact sensor changes:

    rule "rule test"
        Item AqaraContact changed
        logDebug("test", "blah test")

Whenever the rule is executed, I see this error in my logs:

2019-08-17 22:16:54.768 [WARN ] [ab.io.javasound.internal.AudioPlayer] - No line found: No line matching interface SourceDataLine supporting format PCM_SIGNED 44100.0 Hz, 16 bit, mono, 2 bytes/frame, 22050.0 frames/second, little-endian is supported.
2019-08-17 22:16:54.770 [INFO ] [ab.io.javasound.internal.AudioPlayer] - Available lines are:

I am able to play the same sound file from the command line on the pi and from the command line if I go into the docker container itself (using docker exec -it container_id /bin/bash).

Openhab runs under root in my docker container. I couldn’t get the docker container to run as openhab with the openhab group for some reason, so I found an option to run as root in the documentation for the openhab docker image.

Here is my docker-compose file:

    version: '3'

            container_name: openhab
            image: "openhab/openhab:milestone"
            restart: always
            network_mode: host
                - NET_ADMIN
                - NET_RAW
                - "/etc/localtime:/etc/localtime:ro"
                - "/etc/timezone:/etc/timezone:ro"
                - "/home/pi/openhab/volumes/conf:/openhab/conf"
                - "/home/pi/openhab/volumes/userdata:/openhab/userdata"
                - "/home/pi/openhab/volumes/addons:/openhab/addons"
                - "/dev/snd:/dev/snd"
                - "/dev/ttyAMA0:/dev/ttyAMA0"
                - "/dev/ttyACM0:/dev/ttyACM0"
                - USER_ID=110
                - GROUP_ID=115
            command: "tini -s ./start.sh server"

I’m leaving the question here in case it is useful to anyone else. I resolved it immediately after posting, even though I’ve been fighting with this for hours (typical).

My compose file originally had version: 2.2, per the example at https://hub.docker.com/r/openhab/openhab/#running-from-compose-fileyml. I switched it to version: 3 because I thought I might as well upgrade it. That did it. My sound works.

Wouldn’t the real solution have been to use the official documentation?

I did use the official openhab documentation. It includes a link and recommendation to refer to the documentation on docker hub as well.

I experienced two problems when using only the documentation at openhab.org (before I tried the compose config example on docker hub).

  1. Systemd was giving me trouble. I never figured out why, and it didn’t seem important enough at the time. I still had the option of starting the container manually, or using compose. I ran it manually for a while and then switched to compose.

  2. Audio playback through the rule didn’t work. I did stumble across errors different from what I posted, which led me to posts in this community about permissions errors. All of the posts I found were not working with docker, but I still tried treating this as a permissions problem. I re-did the user/group parameters in the docker run command (should be equivalent to my compose file) and host config multiple times, thinking I must have missed a step. I was unable to get audio working until I found the blurb about running as root in the docker hub documentation.

Do you have a step in mind that I might have missed in the documentation? I would like to have my setup as close as possible to the standard recommendation, without the container using root by default.

Since I’m using docker, it’s very easy for me to retry this process. I’m happy to walk through things with people here for my own benefit and for the sake of anyone else that experiences the same problem.


Hi I have exaxtcly the same problem…I get the following logs:

2021-03-02 13:38:40.726 [WARN ] [nternal.javasound.JavaSoundAudioSink] - Cannot determine master volume level - assuming 100%
2021-03-02 13:38:40.807 [ERROR] [nternal.javasound.JavaSoundAudioSink] - An exception occurred while playing audio : 'Cannot create AudioDevice'

I’ve tried every community-solution provided, but cannot run sound through the haedphonejack of the pi…I’m running on 3.0.1 with compose…can you show me how you got it to work? I use hypriot-os so maybe I have to load some modules…can you point me which?

I have OH3 running in Docker container on RP4 with Ubuntu. Going to try to get the audio to work and will update with my results.


Having exactly the same issue, unable to play any sound, I’m now looking at setting up a pulse audio server on the host and pass that stream over the “virtual” network, but well, I don’t know if it’s the right way to go… More stable for the next releases I guess…

forget about pulseaudio, it’s “only” a “control binding”, you can"t play any sound on the sink with this binding :frowning:

I have the same problem. I can play the same mp3 file with command line in RP 4 running Ubuntu 20.04

mpg123 sound.mp3

But inside the container, play the same file but got no sound.

Hello, I have the same problem, I’m using OH 3.2.0 with docker (as user “openhab”, not root) running from command line, I also added “–device=/dev/snd:/dev/snd” to docker run command, and I also added “opnehab” user to audio group with “sudo adduser openhab audio”. I’m still not able to play sound, the error is: " An exception occurred while playing audio : ‘Cannot create AudioDevice’. Any help will be very appreciated. Thanks.

Where can I find version 3? Sorry for the question but at this link a can find just version 2.2 ). Many thanks.