Getting List of All Devices, Capability of Any


(Erik) #1

Hello,

I am attempting to create a SmartApp which is capable of forwarding event data from any device. Unfortunately selecting devices of any capability seems impossible with the current API. Is there some secret that I am not aware of, or are there any plans to support this in the future?

Many thanks!
-Erik


(ActionTiles.com co-founder Terry @ActionTiles; GitHub: @cosmicpuppy) #2

The common workaround that I have seen is to use two inputs; “capability.sensor” and “capability.actuator”.

Every device is supposed to claim one of those two Capabilities in addition to more specific one(s).


(Erik) #3

Thanks for the info @tgauchat, that is a good work-around for now.

Also sent a support request asking to allow device input for all of the available devices, would be a nice feature to have.


(Rohit Gandhe) #4

Thanks for this answer. I tried using these as inputs with mappings of /sensors and /actuators with methods for listing

def listSensors() {

def resp = []
sensors.each {
    resp << [name: it.name, value: it.currentValue("sensors")]
    log.debug "${sensors.displayName}, name: ${it.displayName}"
}

def listActuators() {

def resp = []
actuators.each {
    resp << [name: it.displayName, value: it.currentValue("actuators")]
}

}

but when I call /sensors and /actuators as ResT calls, I get 200 response but empty body.


(Ryan) #5

you should return the resp at the end of the method


(Rohit Gandhe) #6

(Rohit Gandhe) #7

So, I tried that and I get an empty array :neutral_face:
Can someone please confirm this still works?

Here’s the code:

mappings {
path("/sensors") {
action: [
  GET: "listSensors"
]
}
path("/actuators") {
  action: [
    GET: "listActuators"
  ]
}
}

def listSensors() {

def resp = []
sensors.each {
    resp << [id: it.id, name: it.displayName, value: it.currentValue("sensors")]
    log.debug "${sensors.displayName}, name: ${it.displayName}"
}

return resp
}

def listActuators() {

def resp = []
actuators.each {
    resp << [id: it.id, name: it.displayName, value: it.currentValue("actuators")]
}

return resp
}

(ActionTiles.com co-founder Terry @ActionTiles; GitHub: @cosmicpuppy) #8

If you want help debugging, please – you’ll have to provide the FULL code for the SmartApp, including the input statements where you fetch the list of Sensors and Actuators from the user!