I am having a heck of a time with addChildDevice

I am trying to add a child device using a SmartApp, but everytime I execute the line I get

12:49:09 PM:
error
org.springframework.security.access.AccessDeniedException: Access is denied @ line 67

Here’s the code from the SmartApp,

def initialize() {
    // nothing needed here, since the child apps will handle preferences/subscriptions
    // this just logs some messages for demo/information purposes
    log.debug "there are ${childApps.size()} child smartapps"
    childApps.each {child ->
        // this is where we will create teh child devices
        log.debug "child app: ${child.label}"
        log.debug "zone: ${child.zoneNumber} / name: ${child.zoneName} / hub: ${child.wifiHub} / hubId: ${child.wifiHub.deviceNetworkId} / Hub: ${child.wifiHub.hub.name}"
         // stopped here, come up with a standard device name..
        def deviceName = "${child.wifiHub.deviceNetworkId}/${child.zoneName}"
        log.debug(deviceName)
        def d = getChildDevice(deviceName)
        if(!d) {
            log.debug "not d : ${d}"
            d = addChildDevice("cloudsyjared", "MiLight Controller", deviceName, child.wifiHub.id, ["label":"${child.zoneName}", "name": "MiLight/${child.zoneName}"])
            log.debug "after add child"
            //subscribeAll() //helper method to update devices
        }
    }
}

What am I doing wrong here? The documentation says that the HubId can be null, but I find that when it is null, I get a string error.

groovy.lang.MissingPropertyException: No such property: data for class: java.lang.String @ line 90

If I set HubId to my hub

def hub = location.hubs[1]
log.debug “id: ${hub.id} / ${hub.name}”

I get:

d5bbb7af-c9a8-4942-add1-4ac853d32c09

1:09:47 PM:
error
groovy.lang.MissingMethodException: No signature of
method: physicalgraph.device.HubService.get() is applicable for argument
types: (physicalgraph.app.HubWrapper) values:
[physicalgraph.app.HubWrapper@1fa63828]

what is line 67?..
Also, I’m thinking you’ll be better off creating the childdevice in the child app, rather than the parent.
When the child gets deleted, so will the device.

Sorry Mike, line67 is the addChildDevice line

        d = addChildDevice("cloudsyjared", "MiLight Controller", deviceName, child.wifiHub.id, ["label":"${child.zoneName}", "name": "MiLight/${child.zoneName}"])

That’s a good idea, I didn’t know that.

I’ve had lots of issues explicitly deleting childDevices, however when it’s created by a childApp it seems to be less of an issue.

Do you see anything wrong with my addChildDevice code? What would SmartThings be trying to get .data() from ?

what’s line 90?..

your call to set the hub id should be 0, not 1
ie: def hub = location.hubs[0]

Line 90 doesn’t actually exist in the SmartApp. Hubs[0] was a virtual hub device, which is why I went with 1. However, all the examples I see are setting it to null anyway, so I’m not sure if its important.

I got it, thanks. It was passing “updated” to my parse method for my device code, while I was expecting a JSON object from the HTTP stuff. I’ll figure out a work around.