Remove child devices in custom device type handler DTH?

I am working on a custom DTH that aggregates the open/close status for a group of contact sensors managed through webcore.

I have the parent and child DTH working now to create the child devices, update the child open/close status, and update the parent status based on “all closed” or “1 or more contacts are open”. this also shows all of the child device tiles in the main parent device.

ok cool so far, but what if i change/remove some contact sensors in the group. well any child device that got removed from the group, is still ‘active’ in the parent device. but it no longer gets updated, obviously as there is no physical contact sensor in the group that is referenced for this child device.

Is there a way to programmatically remove child devices by name? or a way to remove all of the child devices for a parent device? i have not been able to find anything about removing child devices from this forum or the smartthings developer documentation.

I am planning on posting a topic with code when i have it working more consistently.

any help is much appreciated.

I don’t believe so. I think the user having to manually add/remove devices is kind of like a security measure so that a SmartApp cannot access devices you do not want it to.

After some more digging, it appears there is an undocumented way to remove child devices from inside a DTH. the below is wrapped in a function that is the ‘action’ i call from a tile ‘button’:

	childDevices.each {
		catch (e) {
			log.debug "Error deleting ${it.deviceNetworkId}: ${e}"

I have created a new thread for the released DTH and webCoRE pistons:

1 Like