Has anyone else using addChildDevice seen issues where a call to that method seems to work, but later calls to getChildDevice() or getChildDevices() report that the SmartApp has 0 children? It doesn’t happen all of the time, only sometimes, but I can’t figure out any pattern in when it works and when this strangeness happens. The device is still created successfully, it just isn’t a child of the SmartApp. Any ideas?
Here is some logging from a case where this happened. You can see a child device being created, then shortly after, I call getChildDevices() and find 0 devices:
def d = addChildDevice("com.obycode", "obything Music Player", childId, location.hubs[0].id, [name:"obything Music Player", label:childName, completedSetup:true])
It returns a valid device as expected. I then call getChildDevices() after a few other operations, within the same function. It makes me think that addChildDevice is an asynchronous operation and I am calling getChildDevices before it has completed, but in the case where the new child does not show in the list, it does not show up later either; it never gets added.
I’ve been having issues where the create child device call works as expected, but the device only gets installed to the IDE under a session for the device type, this isn’t related to your issue, just a curiosity on my end.
The suggestion on the runIn being to mitigate any asynchronous issues that you could be facing.
Using runin would give the app time to fully install (if that’s the issue), before the child device gets created.