addChildDevice question


(Linda Thomas-Fowler) #1

I’m hoping someone can help me out for the last argument in addChildDevice. Looking at it from the outside I was guessing that it was a way to set the preferences for the newly created device.

However, the settings I’m passing in the dictionary don’t seem to be getting created. Here’s the offending line:

d = addChildDevice("ac4lt", newSensor.type, dni, location.hubs[0].id, ["name":newSensor.name, "label":newSensor.name, "zoneNumber":newSensor.id])

The new device is created but has the blue warning triangle saying it needs to be configured. It has the name but the zoneNumber isn’t set.

In my device type I have this:

	preferences {
	input description: "The zone number for this sensor in the ADT alarm panel.", displayDuringSetup: true, type: "paragraph", element: "paragraph"
	input "zoneNumber", "number", title: "Zone Number", description: "Zone Number for the sensor", range: "1..*", displayDuringSetup: true
}    

Have I made a wrong assumption? Or am I perhaps leaving something out? Any insight would be welcome!


(swanny) #2

You can add completedSetup to the array where you have name, label, and zoneNumber so it won’t have the blue triangle saying it needs to be configured:

["name":newSensor.name, "label":newSensor.name, "zoneNumber":newSensor.id, "completedSetup": true]

However, I’m not sure that you can initialize user created variables (like zoneNumber) in that way. If someone else doesn’t provide a better solution, you can create a function in the device that would do more initialization right after creating the device.

d.initialSetup(zoneNumber)

(Linda Thomas-Fowler) #3

Thanks, @swanny! That’s got the incomplete setup resolved. Now I just need to get the extra configuration info passed in. Is there a good reference for how preferences and attributes work?


(swanny) #4

I figured it out from various snippets and samples in the documentation. Some of the docs:
http://docs.smartthings.com/en/latest/device-type-developers-guide/anatomy-of-a-device-type.html
https://support.smartthings.com/hc/en-us/articles/200901360-Device-Types-Capabilities-Attributes

You could check out my two integrations as examples too: