SmartThings Community

Access device by ID

(Troy Kelly) #1

Is it possible to access a device by ID?

For example, I have subscribed to the device with

subscribe(theDevice, attrName, stateChange)

I then get the event, and know the device ID from

def deviceID = evt.deviceId

What I now wish to do (among other things) is unsubscribe from the device because it has changed. How can I use the device ID to unsubscribe - I don’t want to loop through every device, and see if it matches the deviceID and then unsubscribe - there must be a more efficient way.

(Troy Kelly) #2

It seems I can subscribe (and then unsubscribe) via the device ID - so that sorts out part of the equation.

What I need to do now is be able to access current/lastState values for a device by ID.

Subscribing to device by device id?
(Brice; #3

Hi @troykelly. Sorry to resurrect this old thread, but I too am trying to figure out how to get a device from its ID. Did you ever figure out how to do that? I figure there must at least be some way to get the list of input devices and search through to find the one with the given ID, but I can’t find a way to do that.

(Brice; #4

I found the answer. In the SmartApp, we can access “settings” which is a map containing the inputs/preferences.