Have certain rules play audio on different outputs on Pi

I am running Openhabian (Openhab version 2.2 snapshot) on a Raspberry Pi 3. I have a plugable USB audio card, seen here

I was wondering if it is possible to differentiate between the on-board 3.5mm audio output and the USB audio output while making rules. I found some info on audio sinks and from what I can gather it’s pretty close to what I’m looking for. I just see the three basic sinks enhancedjavasound, javasound, and webaudio. I have the enhancedjavasound working and it sends audio to the on board 3.5mm jack.

Based on research I did before I started this thread I think this info might be relevant. The command aplay -l gives me to following

**** List of PLAYBACK Hardware Devices ****
card 0: ALSA [bcm2835 ALSA], device 0: bcm2835 ALSA [bcm2835 ALSA]
Subdevices: 8/8
Subdevice #0: subdevice #0
Subdevice #1: subdevice #1
Subdevice #2: subdevice #2
Subdevice #3: subdevice #3
Subdevice #4: subdevice #4
Subdevice #5: subdevice #5
Subdevice #6: subdevice #6
Subdevice #7: subdevice #7
card 0: ALSA [bcm2835 ALSA], device 1: bcm2835 ALSA [bcm2835 IEC958/HDMI]
Subdevices: 1/1
Subdevice #0: subdevice #0
card 1: Device [USB Audio Device], device 0: USB Audio [USB Audio]
Subdevices: 1/1
Subdevice #0: subdevice #0

So is it possible to have some rules trigger audio to the on-board 3.5mm jack and other rules trigger audio to the USB audio card?

I guess this would depend on the binding you’re using.

I’m not exactly sure which binding would be considered as being used to play the audio file itself. I guess the z-wave binding, although I’m using the GPIO binding as well to activate a relay. In this example a z-wave shock sensor turns on a relay (channel2) and then uses the playSound command to play the audio file in question.

rule "Dining Room Shock"
    Item DiningRoomShock_ShockAlarm changed from OFF to ON or
    Item DiningRoomShock_ShockAlarm changed from NULL to ON


Ok, so not a binding, then. This isn’t something I’ve seen before, but I think from a quick search, this would be calling on the code from the Audio script action.

The code looks like it has a method that would allow for passing the name of the audio sink you want to use:

@ActionDoc(text = "plays a sound from the sounds folder to the given sink(s)")
    public static void playSound(@ParamDoc(name = "sink", text = "the id of the sink") String sink,
            @ParamDoc(name = "filename", text = "the filename with extension") String filename) {

Hmmm, I’ll have to take a closer look at this later but at this point I think it might be more worth while for me to dive into pulseaudio and it’s binding. Coding isn’t my strong suit, my strengths are more with hardware/wireing related stuff. It’s not that I can’t figure it out, it just takes me some time. Pulseaudio seems to be better documented and more flexable so if I’m going to spend the time learning something new it may as well be pulseaudio.

Would I be on the right track by pursuing pulseaudio? From what I gather you can put in what hardware sink you want the audio to play through with that binding. At first glance that much seems to be documented, at least with the legacy binding.

That’s something else I haven’t used. But it certainly sounds reasonable.

following works
say(“Hello world!”)
say(“Hello world!”, 25)
say(“Hello world!”, “voicerss:enGB”)
say(“Hello world!”, “voicerss:enGB”, 25)
say(“Hello world!”, “voicerss:enUS”, “sonos:PLAY5:kitchen”)
say(“Hello world!”, “voicerss:enUS”, “sonos:PLAY5:kitchen”, 25)

With playStream :
How to change ```smarthome:audio sinks using rule @ Item
Or change Sink device listed in

How did you get the different sinks installed? do you know if it is possible to send the audio to something like a raspberryPI (hifiBerry)

I think starting a new thread would be a good idea. You should be able to through the hifiberry thou