Audio OUT

Audio OUT

An example about how the audio OUT can be used, directly driving the sounds or linking them to different events.

The items configured can be displayed as buttons on:

Classic UI
Basic UI

Or in the Habpanel

OpenHAB audio

how to use the audio output to play alarm and warning sounds

Assign the items to link with the sounds

Switch AirHorn "AirHorn"  (audio) 
Switch ALARMBUS "ALARMBUS"  (audio)
Switch alarmClock "alarmClock"  (audio)
Switch barking "barking"  (audio)
Switch BikeHorn "BikeHorn"  (audio)
Switch dixieHorn "dixieHorn"  (audio)
Switch doorbell "doorbell"  (audio)
Switch trainWhistle "trainWhistle"  (audio)

The sound files must be in the sounds folder

Add the rules to execute when the switches are actuated

rule "AirHorn"
when
    Item AirHorn changed
then
    playSound("AirHorn.mp3")
end

rule "ALARMBUS"
when
    Item ALARMBUS changed
then
    playSound("ALARMBUS.mp3")
end

rule "alarmClock"
when
    Item alarmClock changed
then
    playSound("alarmClock.mp3")
end
......

Setup the buttons to use them in ClassicUI, BasicUI or App

sitemaps/cm3home.sitemap

Frame label="Audio"
    {
    	Text label="Sound" icon=player
    	{
    		Switch item=AirHorn
    		Switch item=ALARMBUS
    		Switch item=barking
    		Switch item=BikeHorn
    		Switch item=dixieHorn
    		Switch item=doorbell
    		Switch item=trainWhistle
    	}
    }
Tips

The internal java player is less flexible than an external mp3-player, omxplayer could be used instead that offers many more features, first off all a better audio volume management.

Install omxplayer

sudo apt-get install omxplayer

Using OpenHAB executeCommandLine in some rules, the external player can be driven:

rules/audio.rules

rule "AirHorn"
when
    Item AirHorn changed
then
	val results = executeCommandLine("sudo@@/usr/bin/omxplayer@@-o@@local@@/etc/openhab2/sounds/AirHorn.mp3",5000)
    logInfo("Exec",results)
end

rule "ALARMBUS"
when
    Item ALARMBUS changed
then
	val results = executeCommandLine("sudo@@/usr/bin/omxplayer@@-o@@local@@/etc/openhab2/sounds/ALARMBUS.mp3",5000)
    logInfo("Exec",results)
end


rule "alarmClock"
when
    Item alarmClock changed
then
	val results = executeCommandLine("sudo@@/usr/bin/omxplayer@@-o@@local@@/etc/openhab2/sounds/alarmClock.mp3",5000)
    logInfo("Exec",results)
end

rule "barking"
when
    Item barking changed
then
	val results = executeCommandLine("sudo@@/usr/bin/omxplayer@@-o@@local@@/etc/openhab2/sounds/barking.mp3",5000)
    logInfo("Exec",results)
end

rule "BikeHorn"
when
    Item BikeHorn changed
then
	val results = executeCommandLine("sudo@@/usr/bin/omxplayer@@-o@@local@@/etc/openhab2/sounds/BikeHorn.mp3",5000)
    logInfo("Exec",results)
end

rule "dixieHorn"
when
    Item dixieHorn changed
then
	val results = executeCommandLine("sudo@@/usr/bin/omxplayer@@-o@@local@@/etc/openhab2/sounds/dixieHorn.mp3",5000)
    logInfo("Exec",results)
end

rule "doorbell"
when
    Item doorbell changed
then
	val results = executeCommandLine("sudo@@/usr/bin/omxplayer@@-o@@local@@/etc/openhab2/sounds/doorbell.mp3",5000)
    logInfo("Exec",results)
end

rule "trainWhistle"
when
    Item trainWhistle changed
then
	val results = executeCommandLine("sudo@@/usr/bin/omxplayer@@-o@@local@@/etc/openhab2/sounds/trainWhistle.mp3",5000)
    logInfo("Exec",results)
end

Because the program is executed with sudo, the openhabian user must be added to the sudoers 

Links

Share