Last active
June 9, 2020 15:10
-
-
Save chmouel/dd2d61f09eec2a9ea207a3915c2fc0bc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| WEBURL=yamaha.local | |
| VOLUMESTEP=50 | |
| function enrobe() { | |
| local mode=$1 | |
| local blob=$2 | |
| [[ ${mode} == "PUT" ]] && shut="-o/dev/null" | |
| cat <<EOF | |
| curl -s 'http://${WEBURL}/YamahaRemoteControl/ctrl' -X POST -d \ | |
| '<YAMAHA_AV cmd="${mode}">${blob}</YAMAHA_AV>' ${shut} | |
| EOF | |
| } | |
| function xml_power() { | |
| local status=$1 | |
| enrobe PUT "<System><Power_Control><Power>${status}</Power></Power_Control></System>" | |
| } | |
| function hdmi_change() { | |
| local chan=$1 | |
| enrobe PUT "<Main_Zone><Input><Input_Sel>HDMI${chan}</Input_Sel></Input></Main_Zone>" | |
| } | |
| function volume() { | |
| local mode=$1 volume newvolume | |
| local A=$(eval $(enrobe GET "<Main_Zone><Volume><Lvl>GetParam</Lvl></Volume></Main_Zone>")) | |
| volume=$(echo $A|sed 's/.*<Val..//;s/..Val.*//') | |
| [[ ${mode} == "up" ]] && newvolume=$[volume-${VOLUMESTEP}] | |
| [[ ${mode} == "down" ]] && newvolume=$[volume+${VOLUMESTEP}] | |
| enrobe PUT "<Main_Zone><Volume><Lvl><Val>-${newvolume}</Val><Exp>1</Exp><Unit>dB</Unit></Lvl></Volume></Main_Zone>" | |
| } | |
| function mutetoggle() { | |
| local newmode | |
| local A=$(eval $(enrobe GET "<Main_Zone><Volume><Mute>GetParam</Mute></Volume></Main_Zone>")) | |
| local ismute=$(echo ${A}|sed 's/.*<Mute.//;s/..Mute.*//') | |
| [[ ${ismute} == Off ]] && newmode=On || newmode=Off | |
| enrobe PUT "<Main_Zone><Volume><Mute>${newmode}</Mute></Volume></Main_Zone>" | |
| } | |
| opt=$1 | |
| case $opt in | |
| mt) | |
| eval $(mutetoggle) | |
| ;; | |
| vu) | |
| eval $(volume up) | |
| ;; | |
| vd) | |
| eval $(volume down) | |
| ;; | |
| h*) | |
| [[ $opt =~ h([0-9])$ ]] && number=${BASH_REMATCH[1]} | |
| [[ -z $number ]] && { echo "No chan detected: ${opt}"; exit 1; } | |
| eval $(hdmi_change ${number}) | |
| ;; | |
| [oO]n|1) | |
| eval $(xml_power On) | |
| ;; | |
| [oO]ff|0) | |
| eval $(xml_power Standby) | |
| ;; | |
| *) | |
| cat <<EOF | |
| yamaha-ctl mt|vu|vd|h[17]|on|off | |
| mt - toggle mute on and off | |
| vu - volume up | |
| vd - volume down | |
| h1-7 - switch to hdmi channel (i.e: h1 switch to hdmi 1) | |
| on - switch on | |
| off - switch off | |
| EOF | |
| exit 1 | |
| ;; | |
| esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment