addChildDevice question

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", "label", "zoneNumber"])

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!

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", "label", "zoneNumber", "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.


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?

I figured it out from various snippets and samples in the documentation. Some of the docs:

You could check out my two integrations as examples too:

1 Like