Hi @Ryan780 let me clarify.
I have a device handler which I am using to control a Yamaha AV receiver over lan by sending POST commands with the smarthub.
here is the code for one of the yamaha device handlers.
The momentary button tiles no longer show up, but what it used to do is have buttons for each of the different inputs, like sotify, aux, hdmi etc. and by tapping that button it would then tell the yamaha to change to that input.
Momentary buttons no longer are supported, and I cant put multiple on off switches cause that would be annoying to have to turn on and back on a switch to trigger the input change post command to send.
any suggestions to make this work better. this code is a remake of something @redloro made .
metadata {
definition (name: "Yamaha Main", namespace: "eldridge-st", author: "eldridge") {
capability "Switch"
capability "Switch Level"
capability "Actuator"
capability "Polling"
command "source0"
command "source1"
command "source2"
command "source3"
command "source4"
command "source5"
}
tiles{
standardTile("switch", "device.switch", canChangeIcon: true) {
state("off", label:"Main Off", action:"switch.off", icon:"st.Electronics.electronics16", backgroundColor:"#79b821")
state("on", label:"Main On", action:"switch.on", icon:"st.Electronics.electronics16", backgroundColor:"#ffffff")
}
controlTile("volume", "device.level", "slider", height: 1, width: 6, range:"(0..160)") {
state "level", label: "Volume", action:"switch level.setLevel", backgroundColor:"#00a0dc"
}
standardTile("0", "device.source0", decoration: "flat", width: 2, height: 2) {
state("off", label:"TV", action:"source0", icon:"https://raw.githubusercontent.com/redloro/smartthings/master/images/indicator-dot-gray.png", backgroundColor:"#ffffff")
state("on", label:"TV", action:"source0", icon:"https://raw.githubusercontent.com/redloro/smartthings/master/images/indicator-dot-green.png", backgroundColor:"#ffffff")
}
standardTile("1", "device.source1", decoration: "flat", width: 2, height: 2) {
state("off", label:"Spoify", action:"source1", icon:"https://raw.githubusercontent.com/redloro/smartthings/master/images/indicator-dot-gray.png", backgroundColor:"#ffffff")
state("on", label:"Spotify", action:"source1", icon:"https://raw.githubusercontent.com/redloro/smartthings/master/images/indicator-dot-green.png", backgroundColor:"#ffffff")
}
standardTile("2", "device.source2", decoration: "flat", width: 2, height: 2) {
state("off", label:"Sonos", action:"source2", icon:"https://raw.githubusercontent.com/redloro/smartthings/master/images/indicator-dot-gray.png", backgroundColor:"#ffffff")
state("on", label:"Sonos", action:"source2", icon:"https://raw.githubusercontent.com/redloro/smartthings/master/images/indicator-dot-green.png", backgroundColor:"#ffffff")
}
standardTile("3", "device.source3", decoration: "flat", width: 2, height: 2) {
state("off", label:"AUX", action:"source3", icon:"https://raw.githubusercontent.com/redloro/smartthings/master/images/indicator-dot-gray.png", backgroundColor:"#ffffff")
state("on", label:"AUX", action:"source3", icon:"https://raw.githubusercontent.com/redloro/smartthings/master/images/indicator-dot-green.png", backgroundColor:"#ffffff")
}
standardTile("4", "device.source4", decoration: "flat", width: 2, height: 2) {
state("off", label:"AUDIO", action:"source4", icon:"https://raw.githubusercontent.com/redloro/smartthings/master/images/indicator-dot-gray.png", backgroundColor:"#ffffff")
state("on", label:"AUDIO", action:"source4", icon:"https://raw.githubusercontent.com/redloro/smartthings/master/images/indicator-dot-green.png", backgroundColor:"#ffffff")
}
// Defines which tile to show in the overview
main "switch"
// Defines which tile(s) to show when user opens the detailed view
details([
"switch",
"volume",
"0","1","2","3","4"
])
}
preferences {
input name: "source0", type: "text", title: "Source 1", defaultValue: "TV"
input name: "source1", type: "text", title: "Source 2", defaultValue: "Spotify"
input name: "source2", type: "text", title: "Source 3", defaultValue: "Sonos"
input name: "source3", type: "text", title: "Source 4", defaultValue: "AUX"
input name: "source4", type: "text", title: "Source 5", defaultValue: "AUDIO"
}
}
def on() {
sendCommand("/main/setPower?power=on")
sendCommand("/main/setInput?input=audio1")
sendEvent(name: "switch", value: "on")
}
def off() {
sendCommand("/main/setPower?power=standby")
sendEvent(name: "switch", value: "off")
}
def source0() {
setSource(0)
}
def source1() {
setSource(1)
}
def source2() {
setSource(2)
}
def source3() {
setSource(3)
}
def source4() {
setSource(4)
}
/**************************************************************************/
/**
* Called every so often (every 5 minutes actually) to refresh the
* tiles so the user gets the correct information.
*/
def poll() {
refresh()
}
def parse(String description) {
return
}
def setSource(id) {
//log.debug "source: "+getSourceName(id)
sendCommand("/main/setInput?input="+getSourceName(id)+"&mode=autoplay_disabled")
setSourceTile(getSourceName(id))
}
def getSourceName(id) {
if (settings) {
return settings."source${id}"
} else {
return ['TV', 'Spotify', 'Sonos', 'AUX', 'AUDIO'].get(id)
}
}
def setSourceTile(name) {
sendEvent(name: "source", value: "Source: ${name}")
for (def i = 0; i < 5; i++) {
if (name == getSourceName(i)) {
sendEvent(name: "source${i}", value: "on")
}
else {
sendEvent(name: "source${i}", value: "off")
}
}
}
private sendCommand(body) {
log.debug "MusicCast Receiver send command: ${body}"
def hubAction = new physicalgraph.device.HubAction(
headers: [HOST: "10.0.0.9:80"],
method: "GET",
path: "/YamahaExtendedControl/v1" + body
)
sendHubCommand(hubAction)
}
def zone(evt) {
/*
* Zone On/Off
*/
if (evt.power) {
sendEvent(name: "switch", value: (evt.power == "on") ? "on" : "off")
}
/*
* Zone Volume
*/
if (evt.volume) {
def int volLevel = evt.volume.toInteger()
sendEvent(name: "volume", value: volLevel)
}
/*
* Zone Muted
*/
if (evt.mute) {
sendEvent(name: "muted", value: (evt.mute == true) ? "on" : "off")
}
/*
* Zone Source
*/
if (evt.input) {
setSourceTile(evt.input)
}
}