Possible to get all devices with any capability via input?

Is it possible to have a preference input list all devices from a location despite capability and type?

Something like:

input "items", "device.*", title : "Devices To Use", multiple: true

Thanks!

Similarly, is it possible to retrieve an object’s entire state?

So, instead of iterating over known attribute names

def temp = device.currentValue("temperature")
def contact = device.currentValue("contact")
// ...

it’d be nice to

def state = device.currentState()

This sort of functionality would be immensely helpful to metaprogramming SmartApps, as to better serve a more diverse and mutable set of devices.

I was able to answer my second question re: the whole state of a device.
Using #supportedAttributes I can get all attributes, loop through them, and build my own total state object.

def all_attributes_of_device = device.supportedAttributes
// loop over all_attributes_of_device...

I was reading the SmartDevice class summary instead of the Device docs. Oops.
Sorry, if I’m over documenting, just hoping it may help someone else down the line.

1 Like

I don’t know if the code here (originally for switches) will be any help to you - but it does loop over the attributes.

1 Like

Thanks! That’s very similar to what I ended up doing:

def device_state = [:]
for (attribute in device.supportedAttributes) {
  device_state."${attribute}" = device.currentValue("${attribute}")
}

Now if I could only get all devices as options for an input…

Are you working on a ST App or accessing the API (OAuth)? Just wondering why you’d want to access every device for a single input.

I’m writing a SmartApp with the web based IDE. No external application.

I’m trying to push the state of each device to an external service.

Is that a use-case for a “SmartThings Web Service”? For now I am just trying to keep it self-contained as a SmartApp while I play around, and not involve other appliances yet.

Someday the Core API will be available and SmartApps like these won’t be needed anymore. I look forward to that day.

2 Likes

Thanks for this, its exactly what i want but how do i implement this into a smart app?
Do you have any example code?

I’m also looking for a way to get all devices. (not based on capability)
I’d like to know when the Core API will be available.

2 Likes

Yah… We really need this for SmartTiles V6.

Yea, we really need this for developer sanity, I wonder how many of us are spending hours building almost the same exact thing which just about every IOT platform gives you out of the box… a basic RESTful API. Instead of working on our unique app ideas were busy hacking together something that will work which waiting on Samsung to provide something that should have been a day one deliverable. Shame

2 Likes