Virtual Devices, Locations, and Hubs

Can anyone explain what specifying the hub ID does when creating a virtual device? In this example, I’m creating either on/off or momentary button tiles.

The addChildDevice() API docs say that it’s optional and defaults to null but don’t explain what you gain or lose by setting it.

With all other parameters equal, this code works and results in the device being created (but not associated with a hub, just a location):

addChildDevice("bkeifer", deviceType, deviceID, null, [name: deviceID, label: deviceLabel, completedSetup: true])

…but this does not:

def hub = location.hubs[0]
addChildDevice("bkeifer", deviceType, deviceID, hub.id, [name: deviceID, label: deviceLabel, completedSetup: true])

To the best of my knowledge (and this is partially memory and partially a guess), hub.id is deprecated (obsolete) in this command, because currently SmartThings does not support more than one Hub per Location and SmartApps cannot run across Locations.

With those two constraints, hub.id is meaningless, so null is as good as anything.

1 Like

Thanks!

I couldn’t find anything that I couldn’t do without it associated to a hub (and the phones we use for mobile presence also don’t have an associated hub), so I suspected this might be the case.

I’ll roll without it for now unless @slagle or @Jim chime in otherwise.

1 Like