Access outside device from custom Device Type?

Hi all,

I am enhancing my custom garage door handler. It uses separate z-wave door contacts to determine whether it’s open or closed, but I want to display that status in my Device Type.

I created a Preferences section in the Device Type like you would in a SmartApp, and I can select the sensors - but when I try to access them it doesn’t work. Is this not possible in a Device Type?

Instead of getting “open” or “closed” I’m getting something like: physicalgraph.app.AttributeWrapper@3c1b85e8

preferences {
section("Doors") {
	input "doorSensor1", "capability.contactSensor", title: "Left door sensor"
	input "doorSensor2", "capability.contactSensor", title: "Middle door sensor", required: false
	input "doorSensor3", "capability.contactSensor", title: "Right door sensor", required: false
}
}

def refresh() {
log.debug "*** Checking Door Sensors ***"
	if (doorSensor1) {
			log.debug "Door 1"
			log.debug doorSensor1.contact
    	if (doorSensor1.contact == "open") {
			Opened1()
        } else {
			Closed1()
        }
    }
    if (doorSensor2) {
 			log.debug "Door 2"
			log.debug doorSensor2.contact
	if (doorSensor2.contact == "open") {
			Opened2()
        } else {
			Closed2()
        }
    
    }

if (doorSensor3) {
		log.debug "Door 3"
		log.debug doorSensor3.contact
 	if (doorSensor3.contact == "open") {
		Opened3()
    } else {
		Closed3()
    }

}
}

To get the current value of an attribute, you either need to append current before the attribute (doorSensor1.currentContact), or by passing the attribute as a parameter to currentValue() (doorSensor1.currentValue("contact")).

For reference, see here: http://docs.smartthings.com/en/latest/smartapp-developers-guide/devices.html#getting-device-current-values

2 Likes

Thank you so much, and now it’s working. That was so simple but I spent hours trying a million other things :blush:

@Jim to the rescue!