Yamaha Receiver Integration and Custom Rule Solution

I recently encountered an issue with my Yamaha receiver where the selected preset wasn’t being reported correctly. After some research and troubleshooting, I found a workaround by creating a custom rule. Here’s how I did it:

Items File Setup:
markdown
Number Yamaha_Preset “Preset [%d]”

Rules File Implementation:
markdown
rule “Yamaha Receiver - Get Tuner Preset”
when Item Get_Yamaha_Preset changed
then
logInfo(“Rules.YamahaReceiver.InputChange”, “Set input settings for {}.”, Yamaha_Input.state)
val String urlString = “http://xxx.xxx.xxx.xxx:80/YamahaRemoteControl/ctrl
val String contentType = “text/xml”
val String contentString = “<?xml version=\"1.0\" encoding=\"utf-8\"?><YAMAHA_AV cmd="GET"><Play_Info>GetParam</Play_Info></YAMAHA_AV>”
val String result = sendHttpPostRequest(urlString, contentType, contentString)

val Number startIndex = result.indexOf("<Preset_Sel>")
val Number endIndex = result.indexOf("</Preset_Sel>")
startIndex = startIndex + 12

val Number presetNumber = new Integer( result.substring(startIndex.intValue, endIndex.intValue) ) as Integer
Yamaha_Preset.postUpdate(presetNumber)

end

This solution allows me to accurately track the preset selections on my Yamaha receiver, which wasn’t functioning properly out of the box. I hope this helps others facing similar issues until the official binding is updated. Happy tinkering! :headphones: