SmartThings Community

getChildDevices returns 0


#1

I’m trying to get a list of child devices which have been linked to an app.
Following the example from:
https://docs.smartthings.com/en/latest/ref-docs/installed-smart-app-wrapper-ref.html#getchilddevices

def printChildDevices(){
    def children = app.getChildDevices()
    log.debug "SmartApp with id $app.id has ${children.size()} child devices"

    children.each { child ->
        log.debug "child device id $child.id with label $child.label"
    }
}

and the function is called from:

def genericHandler(evt) {
log.debug "genericHandler - Verion: ${version()}, Device Name: ${evt.device}, Event Name: ${evt.name}"
printChildDevices()

but the output I get is:

SmartApp with id xxxxxxxxxx has 0 child devices


#2

Your code is correct for getting a list of child devices created by the SmartApp.

Are you sure you’re working with child devices? Or are these devices that your SmartApp is subscribing to?


#3

Ah, I thinks that was my misunderstanding.
I have an app that I want to be subscribed to all devices, all events and send status changes to my server (REST POST call). If I have a list of devices the app is subscribe to I can check against my complete list of devices to see if any are missing.
I don’t think there is a way for an app to list all devices on the network?

I see there is getSubscriptions() but what are the properties of subscriptions? How can I list names, IDs…?


#4

Take a look at the Influx DB logger SmartApp. The code might give you some good ideas regarding maintaining a list of subscribed devices, getting their attributes, etc.