App for an IR receiver


(Sean) #1

Hi all. I’m having a little issue with an app I made using danny@smartthings’ code for building an IR Bridge. I made the IR sensor with an UNO and the shield, and it works. The app coding I modified a little, only to add a third button. But the problem is I can turn ON my lights, but not off. I can switch the coding around a little, and then I can turn OFF my lights, but not on. Only one or the other. It seems like it is skipping the IF command. I have been trying for a while and just can’t figure it out. Code for the app is posted below.

preferences {
	section("Pick an IR device...") {
    	input "irDevice", "device.IrBridge"
    }
	section("Button A turns on or off..."){
		input "switch1", "capability.switch", title: "This light", required: false
	}
	section("Button B turns on or off..."){
		input "switch2", "capability.switch", title: "This light", required: false
	} 
	section("Button C turns on or off..."){
		input "switch3", "capability.switch", title: "This light", required: false
	}   
}

def installed() {
	log.debug "Installed with settings: ${settings}"
	subscribe(irDevice, "button.C", handleC)
    subscribe(irDevice, "button.B", handleB)
        subscribe(irDevice, "button.A", handleA)
}

def updated() {
	log.debug "Updated with settings: ${settings}"
	unsubscribe()
    	subscribe(irDevice, "button.C", handleC)
        subscribe(irDevice, "button.B", handleB)
        subscribe(irDevice, "button.A", handleA)
}

def handleA(evt) {
	log.debug "received button A" 
    if (switch1.currentValue == "on") {
        switch1.off()
        
    }
    else {
    	switch1.on()
    
    }
}

def handleB(evt) {
	log.debug "received button B"
    if (switch2.currentValue == "on") {
        switch2.off()
    }
    else {
    	switch2.on()
  	}
}

def handleC(evt) {
	log.debug "received button C"
    if (switch3.currentValue == "on") {
        switch3.off()
    }
    else {
    	switch3.on()
    }
   
}

Any help is greatly appreciated!


(Csader) #2

Someone will correct me if I’m wrong, but I believe the if code should be

if (switch1.currentValue("switch") == "on") {
        switch1.off()
    }

else {
        switch1.on()
    }

(Csader) #3

@primespcts, give that a shot and let me know if it works.


(Todd Wackford) #4

Also write out the state in a debug statement to see if the on or off state is really registered. There is a known issue with the hub not parsing shield returned messages/states correctly. If the state is not updating correctly, file an issue to the support@ folks and they’ll get Dr U. on it.

HTH,
Twack


(Sean) #5

Thanks @csader and @twack
I tried changing to code to what you posted, but it is still doing the same thing. On, but not off.

Just checked the logs while trying to turn it off. It just says the switch is on after pressing the button.

8a9c25843ed7530a013eda3dd05209d0 10:04:01 PM: debug Parse returned LR End Table switch is on
7d384acc-10fb-4088-873b-ade4ef2190a9 10:04:00 PM: debug received button A
61b2e4b6-0267-4452-8776-b6b3cfa23302 10:04:00 PM: debug Parse returned IR Remote button is A
61b2e4b6-0267-4452-8776-b6b3cfa23302 10:04:00 PM: trace code: 20dff10e
61b2e4b6-0267-4452-8776-b6b3cfa23302 10:04:00 PM: trace parse:


(Todd Wackford) #6

Yep, the state message is not being parsed by the hub correctly. File an issue to support@smartthings.com