Sunday, July 05, 2015

Openhab alsa/amplifier link

A simple openhab script that monitors the ALSA sound device and switches on an amplifier if there is something playing. If there isn't anything playing, wait 10 minutes and then turn off.
.items
Switch WemoAmp "Amplifier" { wemo="WemoAmplifier" }


.rules


rule "Switch off amplifier if alsa not playing for 10min"
when
    Item Alsa_State changed or
    System started
then
     logInfo("alsaMonitor", "state changed: " + Alsa_State.state)

    if(Alsa_State.state=='STOPPED') {
       logInfo("alsaMonitor", "Start timer for amp switch off")
        timer = createTimer(now.plusMinutes(10)) [|
              logInfo("alsaMonitor", "Switch off amp")
              sendCommand(WemoAmp,OFF)
        ]   
    } else if(Alsa_State.state=='RUNNING') {
    if(timer!=null) {
        logInfo("alsaMonitor", "Cancel amp switch off")
        timer.cancel
        timer = null
        }   
    logInfo("alsaMonitor", "Turn on amp")
    sendCommand(WemoAmp,ON)
    }   
end


Post a Comment