Updating the vol level and source input via http

Tags: #<Tag:0x00007f617323d558> #<Tag:0x00007f617323d440> #<Tag:0x00007f617323d378>
  • Platform information:
    • Hardware: Raspberry Pi 3 Model B Rev 1.2
    • OS: Raspbian GNU/Linux 8 (jessie)
    • openHAB version: 2.3.0~20180113162733-1 (Build #1181)
  • Topic Summary:
    • I have a Yamaha stereo that cannot be managed via the Yamaha binding (other than Power). I used proxy items per @rlkoshak assistance and sendHttpGetRequest and sendHttpPostRequest commands in the rules files for fixed settings and python scripts to automate a number of use cases. Below is an example of my current configuration
Switch YamahaPwr "Kitchen Radio" [ "Switchable" ]
  Frame label="Kitchen Radio" {Switch item=YamahaPwr}
var String URLCRXN560 = "http://192.168.128.199/YamahaRemoteControl/ctrl"
var String xmlheader = '{?xml version="1.0" encoding="utf-8"?}'
var String PowerOn = '{<YAMAHA_AV cmd="PUT"><System><Power_Control><Power>On</Power></Power_Control></System></YAMAHA_AV>}'
var String PowerOff = '{<YAMAHA_AV cmd="PUT"><System><Power_Control><Power>Standby</Power></Power_Control></System></YAMAHA_AV>}'


/*  Yamaha Reciever Power */
rule "YamahaPwr"
when
	Item YamahaPwr received update
then
	if(YamahaPwr.state==ON){sendHttpPostRequest(URLCRXN560,xmlheader,PowerOn)}
else if(YamahaPwr.state==OFF){sendHttpPostRequest(URLCRXN560,xmlheader,PowerOff)}
end

Here is an example how one can adjust power level or source inputs via Http… First is to get the http payload. In this case it is xml. I need insert a variable where the nine is located in this string.

var String VolLvlAM = '{<YAMAHA_AV cmd="PUT"><System><Volume><Lvl>9</Lvl></Volume></System></YAMAHA_AV>}' //Fixed Example

Instead of formatting and doing transformations, I ended up with splitting the string and concatenating the item.state value in the rule section.

var String VollvlPre = '{<YAMAHA_AV cmd="PUT"><System><Volume><Lvl>'
var String VollvlSuf = '</Lvl></Volume></System></YAMAHA_AV>}'

I’m thinking that that item entry would be

Dimmer Volyamaha "Kitchen Radio Volume" [ "Switchable" ]
  Frame label="Kitchen Radio" {
     Switch item=YamahaPwr
     Slider item=Volyamaha  label="Volume" icon="none" }

Make sure the item.sate is converted to a string. In my case it was “Volyamaha.state.toString”

/*  Yamaha Change Volume */
rule "Vol4Yamaha"
when
	Item Volyamaha received update
then
	value = Volyamaha.state.toString
	VollvlVar = VollvlPre + value + VollvlSuf
	sendHttpPostRequest(URLCRXN560,xmlheader,VollvlVar)
end

Solved