Subscribing to multiple contact sensors

Hi there,

I’m currently writing a SmartApp to “connect” my ST Multipurpose sensors to a local machine via httpPost and sync the open/close events.

Code worked pretty well for a single Sensor hence I started with multiple Sensors which are stored in an array.

Now, when subscribing to the sensor events in the array (“” and “contact.close”) I noticed that somehow the function triggered threw an open or close event cannot distinguish, which sensor was triggering it (in below example the it.getID() always returns an array of all sensors IDs in the initial array but not the sensor which triggered the event)

Would anyone have an idea how to distinguish the triggering device in open or close event (have only the ID of the sensor which was opened/closed)?

preferences {

section(“Select Sensors:”) {

input “myDevice”, “capability.contactSensor”, required: true, title: “Which Sensor”, multiple:true




def initialize() {

subscribe(myDevice, “”, myOpen)


(I also tried to subscribe individually per sensor but with same result)

def initialize() {

myDevice.each {

subscribe(it, “”, myOpen)



def myOpen(evt) {

try {

httpPost(“http://SOMEURL/client.php","command=${it.getId()}:I0=0”) { resp ->

log.debug “response data: ${}”

log.debug “response contentType: ${resp.contentType}”


} catch (e) {

log.debug “something went wrong: $e”



I’m really rusty and was never any good at this thing, but I would have thought evt.getDevice() or evt.getDeviceId() is what you are after. evt.getId() is an ID for the event I believe, though incorrectly described in the docs.

Did you mean to use ‘it’ rather than ‘evt’?

Thanks for the tip!It solved the problem :slight_smile:

the code u have supplied isnt pulling out any detals from the ‘evt’ like

© 2019 SmartThings, Inc. All Rights Reserved. Terms of Use | Privacy Policy

SmartThings; SmartApps®; Physical Graph; Hello, Home; and Hello, Smart Home are all trademarks of the SmartThings, Inc.