USB Audio interface in OH2 vm

Hey all, I’m wondering if someone can give me a hand. I’m running OH2 on Ubuntu 18 in a VM on my QNAP NAS. Everything works great but I’m having audio trouble. I have a generic USB audio interface connected to the NAS and attached to the VM. I have the output of the audio interface connected to my Russound audio system so I can use PollyTTS to do fun stuff. Any audio that plays is very static-y. I’ve tried everything (changing USB ports, changing cords, installed alsa tools) but I can’t shake it. I’ve run across a few post where other people report the same issue with static-y audio using USB interfaces in VM’s. One thing that has worked is to change the sample rate to 44100 from the default of 48000. Does anyone know:

  1. What is the sample rate used by OH/Java?
  2. How to change it?

I feel I’m close and I really want this work. If it doesn’t I’ll have to spin up a dedicated machine and see if it works that way. Not an ideal solution for me but I can pick up a NUC or ZBox and run OH from there.

I tried forcing Java to use ALSA according to the following link:

and setting ALSA to use a sample rate of 44100 but still static. Argh.

Thanks in advance,


Sound is a VERY complex topic, and you have a very specific setup to affect this, so better don’t expect anyone to answer.
I don’t understand what you mean by “audio is static-y” ?
I can play 44.1kHz audio from OH on my Pi3 without a need to resample (so 48k probably needs to be resampled).

Hey Markus, thanks for the reply. What I mean is that the audio plays, it just has static over it. I can execute a ‘voice say’ or ‘audio play’ command from the console and I hear the voice or the doorbell play, it just has pops and crackles while it does.

I found posts from Windows users who had this same issue while using a USB audio interface in a VM. They just went into the audio adapter properties and changed the sample rate to 44100. That’s when I started to see if I could figure out how to do that in Ubuntu server setup. That’s when I installed ALSA to see if I could do it. I found the setting to change but it didin’t make any difference. Searching the forums brought me to the post above about adjusting the file to force Java to use the ALSA drivers. Still no luck.

I don’t have high hopes at this point, posting here was a last ditch effort before I give up and just build a dedicated server and take using a VM out of the equation.




Just food for thought…

I have a simple Google Chromecast Audio with a pair of active (extremely cheap) speakers, this works really well with OpenHab2 for all kinds of Audio Sink applications

Hey Stuart, that’s a good thought! It would let me keep the VM (easy backups and snapshots, no need for another computer running) and just stream the audio instead of using the USB interface.

I’ll check it out!



1 Like

I have two clients that have flooded their new homes with Sonos devices, they use them for all the “normal” Sonos stuff, as well as using the Audio Sink functions in OpenHab2.

I’m tempted to buy another ChromeCast Audio, just to try the Grouping feature :slight_smile:

They’ve also got rules in place to link Velbus events to Sonos actions (which also works for ChromeCast), as well as pushing “now playing” information into the Oled display of some Velbus panels.

Well, my local MicroCenter had one so I ran to pick it up. I configured it using Google Home, OH2 identified it right away, I changed the default audio out to the CCA, updated the callbackURL and tried it out. I see ‘cannot create audio device’ in the log. (Ubuntu server 18, apt install of OH2, openhab user added to audio group.)

I think this will work, just another problem to figure out. Markus was right, trying to get audio working sucks!

The universe is against me on this!


Hey Mark

No one can accuse you of “hanging around” :smile:
I salute your enthusiasm :smile:

I must say that I haven’t had much trouble with anything audio based with OpenHab2, but I have only used WebAudio, Sonos & ChromeCast & Chromecast Audio to date.

I’ll review what you’ve written here, to figure out what you’re trying to achieve, then compare it with my experience.

Hopefully I’ll find something that helps.


I didn’t have any trouble in the early days when I tried getting a CCA to play the doorbell.mp3 or barking.mp3 files that are in the OpenHab2 folders, by using the Play command from a rule.


I did drop an MP3 file of my own in that folder to test with, which worked well.
This inspired me to carry on experimenting.

Good luck.


If it helps, this is the rule I have in place that plays a choice of radio stations when the water flow to our shower gets hot :slight_smile:

To attach it, I’ve renamed it and added .pdf to the end.
bathroom.rules.pdf (2.8 KB)

The following rule relies on -

A PlayURL string for the ChromeCast Audio device.

A Trigger Channel of a Velbus input device

A virtual switch item which holds the state of the house (awake or asleep), this is toggled by our Velbus based Alarm Clock. (This prevents music from being played (automatically) if someone has a shower late at night)

A virtual Dimmer Item that holds the radio station selection (as a number), mapped to a selection list in HabPanel.

1=BBC Radio 2,2=BBC Radio 4 Extra,3=Planet Rock FM,4=Absolute Radio,5=BBC 6 Music

It might well be the very last rule here that is of interest to you, as it directs the TTS output to the CCA, which I use to cancel the music playback.

 rule "Bathroom Music"

	Channel 'velbus:vmb7in:c5053467:0B:input#CH1' triggered PRESSED
	 bathradio = (BathroomChromeCastSourceChoice.state as Number).intValue
	//say("Number"+bathradio, "voicerss:enGB", "webaudio")

	if(House_Awake.state === ON){

	// say("Up to temperature while house awake", "voicerss:enGB", "webaudio")
	// say("Number"+BathroomChromeCastSourceChoice.state, "voicerss:enGB", "webaudio")

	// sendBroadcastNotification("Number"+BathroomChromeCastSourceChoice.state)
		if(bathradio == 1) { 
							say("Radio choice is number"+BathroomChromeCastSourceChoice.state+" BBC Radio 2", "voicerss:enGB", "webaudio")
							} // BBC Radio 2
		if(bathradio == 2) { 
							say("Radio choice is number"+BathroomChromeCastSourceChoice.state+" BBC Radio 4 Extra", "voicerss:enGB", "webaudio")
							} // BBC Radio 4 Extra
		if(bathradio == 3) {
							say("Radio choice is number"+BathroomChromeCastSourceChoice.state+" Planet Rock", "voicerss:enGB", "webaudio")
							} // Planet Rock
		if(bathradio == 4) {
							say("Radio choice is number"+BathroomChromeCastSourceChoice.state+" Absolute Radio", "voicerss:enGB", "webaudio")
							}  // Absolute Radio
		if(bathradio == 5) {
							say("Radio choice is number"+BathroomChromeCastSourceChoice.state+" BBC Six Music", "voicerss:enGB", "webaudio")
							}  // BBC 6 Music
	if(House_Awake.state === OFF){	say("Up to temperature while house asleep", "voicerss:enGB", "webaudio")	 }

rule "Bathroom Music OFF"

	Channel 'velbus:vmb7in:c5053467:0B:input#CH1' triggered RELEASED

	if(House_Awake.state === ON){
	say("Cooled while house awake", "voicerss:enGB", "webaudio")
	say("Bye", "voicerss:enGB", "chromecast:audio:3f5b31d2c7d792037ef036c498c40a1c")
	// Bathroom_Control_Chromecast.sendCommand("STOP")
	if (House_Awake.state === OFF){

			say("Bye", "voicerss:enGB", "webaudio")
			say("Bye", "voicerss:enGB", "chromecast:audio:3f5b31d2c7d792037ef036c498c40a1c")

I’ll get there. I think I’m going to roll back my install to before I started messing around with ALSA. I always had audio, just noisy. I thought ALSA was going to fix it. Alas, I was mistaken. (One of the main reasons I want to stay on a VM, snapshot rollbacks are the best.)

Just so I’m clear, the callback IP is my OH2 IP, correct? Same one I use to get to the dashboard?

Thanks for the assist, I’m cautiously optimistic that this will work. Probably. Eventually.


OK, uninstalling the ALSA packages and removing my backup file seemed to do the trick! (I had left my backup properties file in the directory, I wonder if it was still being processed and trying to use ALSA.) I’m not sure which one did it but at this point I’m just happy it’s working.

I have my test rule (turn on zone, change source, adjust volume, say ‘hello’) working! Even the setMasterVolume command is working now. I can see it change the volume of the chromecast in my sitemap when I fire the rule.

Stuart, you saved my bacon! I didn’t know there was ChromeCast audio, it’s such an elegant solution.

I don’t know how many folks run OH in a VM, hopefully this will help someone in the future.

Thanks again Stuart and Markus!


1 Like

Hi Mark

I really glad that you’re up and running :smile:

For ~$35 / £35 you can’t go wrong with a ChromeCast Audio, I particularly like that it has a dual format 3.5mm connector, if you happen to want an optical digital output.

At some point I’m going to test Dolby Atmos playback via ChromeCast / ChromeCast Audio :wink:

If you buy any more ChromeCast Audio devices, can you post a comment on the Grouping & Audio sync features?



I might try that, too. While I’ve already spent a lot of time on getting sound to work locally on my Pi (with active speakers attached to its 3.5mm output), sound is still breaking up at times (probably the Pi CPU is overloaded) and setMasterVolume() never worked.

1 Like