SmartThings Community

[RELEASE] Yamaha Network Receiver Basic Integration

smartapp_av
dth_av
zone

#102

I simply added the following capability to the device handler…

capability "Switch Level" 

After doing this you should be able to say “Alexa, set #DeviceName to 70%” and the volume will change (note: I enabled the logic in the device handler so my volume can is set between 1 and 100).


(James) #103

So just under line 26?

Lost me at the logic part.

Sorry, not a programmer but I try to follow.


#104

Yes, insert at line 26. Save and publish.


(Ben McGarry) #105

Thanks for coming up with this. I can control one of my Yamaha receivers but can’t figure out how to add my other one.
Do I have to change and reinstall the device handler and smart app for a 2nd receiver?
Thanks


#106

I managed to get Alexa to turn up or turn down the volume i.e. without having to set a specific level. I did this as follows:

I added the following code to the Device Handler to allow for the volumeUp and volumeDown commands:

command "volumeUp"
command "volumeDown"


def volumeUp() {
  def zone = getZone()
  def cmd = (zone != "Zone_B") ?
    "<YAMAHA_AV cmd=\"PUT\"><${zone}><Volume><Lvl><Val>Up 5 dB</Val><Exp></Exp><Unit></Unit></Lvl></Volume></${zone}></YAMAHA_AV>" :
    "<YAMAHA_AV cmd=\"PUT\"><Main_Zone><Volume><Lvl><Val>Up 5 dB</Val><Exp></Exp><Unit></Unit></Lvl></Volume></Main_Zone></YAMAHA_AV>"
  sendCommand(cmd)
}
def volumeDown() {
  def zone = getZone()
  def cmd = (zone != "Zone_B") ?
    "<YAMAHA_AV cmd=\"PUT\"><${zone}><Volume><Lvl><Val>Down 5 dB</Val><Exp></Exp><Unit></Unit></Lvl></Volume></${zone}></YAMAHA_AV>" :
    "<YAMAHA_AV cmd=\"PUT\"><Main_Zone><Volume><Lvl><Val>Down 5 dB</Val><Exp></Exp><Unit></Unit></Lvl></Volume></Main_Zone></YAMAHA_AV>"
  sendCommand(cmd)
}

Using Alexa Helper I have created two virtual momentary buttons, one for volumeUp and one for volumeDown. When each is “pushed” they invoke the corresponding command on the Device Handler.

I then defined a third virtual dimmer and used CoRE rules so that when the dimmer goes up, it pushes the volumeUp button and when it goes down it pushes the volumeDown button.

I allowed Alexa to discover the virtual dimmer and put it in an Alexa group called “television”.

I now say “Alexa, turn up the television” and the volume goes up. or “Alexa, turn down the television” and the volume goes down.


#107

@bmcgarry67 current setup will only support one receiver but could be modified to support multiple receivers.


#108

@farnigus yeah that would require a complete rewrite to support MusicCast… have actually thought about building a good, generic DLNA controller but haven’t gotten around to it.


(Ben McGarry) #109

OK. I saw someone in like the 3rd post said it was working on 2 receivers so I assumed I was missing something.
Thanks


#110

You should be able to just create another SmartApp with the same code… just change the name to “Yamaha Receiver 2” on line 21 and give it a try.


(Ben McGarry) #111

I made the change to line 21 and I thought it was good. I entered the info into the newly created SmartApp, when I pressed done, I got “Error Saving Page.” I edited the code again and still got the same message. Any ideas?
Thanks


#112

So I would like to use this with GH in a similar fashion as you. I’ve been trying to figure out how to change the volume from being displayed in +/- DB and into a 0…100 range. I can’t figure out which lines of code to adjust/replace. I’ve been using the latest code provided by @redloro. and this is what I currently see for the volume section.

def setLevel(value) {
  def zone = getZone()
  //def int volLevel = (Math.round(value * 9 / 5) * 5 - 800).intValue()
  def int volLevel = (value * 10).intValue()
  def cmd = (zone != "Zone_B") ?
    "<YAMAHA_AV cmd=\"PUT\"><${zone}><Volume><Lvl><Val>${volLevel}</Val><Exp>1</Exp><Unit>dB</Unit></Lvl></Volume></${zone}></YAMAHA_AV>" :
    "<YAMAHA_AV cmd=\"PUT\"><Main_Zone><Volume><Zone_B><Lvl><Val>${volLevel}</Val><Exp>1</Exp><Unit>dB</Unit></Lvl></Zone_B></Volume></Main_Zone></YAMAHA_AV>"
  sendCommand(cmd)
  sendEvent(name: "volume", value: value)

}

It looks a bit different from what you have posted and I’m not sure what needs to stay vs. what needs to be replaced. I use 2 zones: main and 2 (don’t use a “zone b”) Could someone help me out? Also, does anything need to change in the SmartApp? or just the DH? I tried replacing some lines, but then I was getting errors when trying to install the app.


#113

This is great app. Has given new life to my receiver. Just a question on how to change the volume scale to 0…100. Could you provide some instructions on which 3 lines need to be swapped out? and with what to replace them with?


#114

Below are the three areas that needs to change. You can copy paste the below code in their respective places and it should work. The change is the comment (forward slashes) on a different line.
Note: In Change two, I added three lines

      if (value > 50){
      value = 50
    }

This sets the volume to 50% if the receiver gets a command for a value greater than 50% for any reason (intended or by mistake). You can delete those three lines if you do not need the limit but my recommendation is to keep it and change the limit to your needs.

Change One - Code from Line 69

// row
controlTile("volume", "device.volume", "slider", height: 1, width: 6, range:"(0..100)") {
//controlTile("volume", "device.volume", "slider", height: 1, width: 6, range:"(-80..16)") {
  state "volume", label: "Volume", action:"music Player.setLevel", backgroundColor:"#ffffff"
}

Change Two - Code from Line 161

    def setLevel(value) {
      def zone = getZone()
      
      if (value > 50){
      value = 50
    }
      def int volLevel = (Math.round(value * 9 / 5) * 5 - 800).intValue()
      //def int volLevel = (value * 10).intValue()
      def cmd = (zone != "Zone_B") ?
    "<YAMAHA_AV cmd=\"PUT\"><${zone}><Volume><Lvl><Val>${volLevel}</Val><Exp>1</Exp><Unit>dB</Unit></Lvl></Volume></${zone}></YAMAHA_AV>" :
    "<YAMAHA_AV cmd=\"PUT\"><Main_Zone><Volume><Zone_B><Lvl><Val>${volLevel}</Val><Exp>1</Exp><Unit>dB</Unit></Lvl></Zone_B></Volume></Main_Zone></YAMAHA_AV>"
      sendCommand(cmd)
      sendEvent(name: "volume", value: value)
    }

Change Three - Code from 266 or 269

      * Zone Volume
      */
      val = (zone != "Zone_B") ?
    evt.Basic_Status.Volume.Lvl.Val.text() :
    evt.Basic_Status.Volume.Zone_B.Lvl.Val.text()
      if (val) {
    def int volLevel = val.toInteger() ?: -250
    sendEvent(name: "volume", value: ((volLevel + 800) / 9).intValue())
    //sendEvent(name: "volume", value: (volLevel / 10).intValue())
      }

#115

This has been really interesting getting my Yamaha and Smartthings Hub and Google Home working together and many thanks to everyone on here for educating me.
So far I can use Google Home to turn on and off my Zone 1 and Zone 2 using the following voice commands:
"Ok google turn on Zone1"
"Ok google turn off Zone1"
"Ok google turn on Zone2"
"Ok google turn off Zone2"
But I haven’t been able to figure out hot to get Google Home to do the following:

  • Change Source
  • Change Volume
    Is anyone using Google Home to perform these functions and, if so, what are the actual voice commands that you use?

#116

@bmcgarry67 updated the SmartApp and Device Handler to support multiple receivers… if you update the app and handler, you should be able to add as many SmartApps as you have Yamaha receivers… just give it a unique name and it should work.


#117

Thanks @StuartW… added this to the default device handler…


#118

@langer refer to the post from @StuartW

Easiest is to probably create a virtual switch for each source and then turn the switch “on” to set the source…


#119

I just updated to the latest app and DH and while I get no errors in the iOS app I am getting this in Live Logging and my receiver is not responding to any commands. The Thing is responding to Alexa though.

error java.lang.NullPointerException: Cannot invoke method children() on null object @ line 67
debug getChildDevices(false), children=8


#120

Oh yeah…Forgot to mention that you can’t do an in place upgrade of the code. You actually have to first delete the smart app and devices, then install the new code, then re-add the smart app which will create the respective device.


#121

I suspected as much, thanks.