Device Handler Polling Other Contact Sensor State


(Dan) #1

Hi there, I have a garage door device handler that controls three of my doors with an arduino.

The device handler preferences request the user to select 3 contact sensors. These are used to update the tiles in the device handler (if a contact sensor is open, the door is open - if its closed, the door is closed - etc).

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
}
}

When I go to query the state of these sensors with something like:

doorSensor2.currentValue("contact")

I get an error because doorSensor2 is returning a string (the ID of the sensor) instead of a reference to the sensor:

groovy.lang.MissingMethodException: No signature of method: java.lang.String.currentValue() is applicable for argument types: (java.lang.String) values: [contact] @ line 83

This used to work, but now I have been trying all day to get a reference to the actual sensor instead of a string consisting of the ID. Did something change, is there no way to get the state of another sensor from within a device handler?


(Dan) #2

Dan,

I don’t believe you can reference another device from within a traditional DH. Only a SmartApp can do that.

However, SmartThings recently released a new type of Device Handler called the Composite Device Handler (or Parent/Child Device Handler.) http://docs.smartthings.com/en/latest/composite-devices/index.html

I have written an Arduino Library and associated Device Handler which takes advantage of the Composite Device Handler design. This allows a single parent device handler to create multiple child devices (even of the same Device Capability) and have them all readily accessible to “normal” SmartApps (i.e. no custom attributes are required at all!)

Take a look at TS_Anything below:

Dan


(Dan) #3

Thanks ogiewon! I came across ST_Anything when researching this issue earlier. It looks like it could be useful but would be re-engineering what I’ve already done. I’m definitely going to look into it more.

I know for certain that this used to be possible, but it doesn’t seem like a normal use case and maybe it was deprecated. That said, I think I’ve worked around the issue by creating some Virtual Garage Door Openers and updating my associated SmartApp to manage those - that way the Device Handler doesn’t need to have a visual interface anymore. Seems to be working for now.