Understanding the format of app.id in getChildDevice or addChildDevice

I have an app with "matching" virtual device. I'm trying to understand the format of the app.id in the add/getChildDevice.

In the 2nd line of the below code snippet the device.id
from the docs the addChildDevice syntax is;
addChildDevice(String namespace, String typeName, String deviceNetworkId, Map properties = [:])

So the deviceNetworkId is entered as ; "DEWPoint_${app.id}"
I understand ${any variable} but I don't understand the structure "DEWPoint_${app.id}"

I might assume the DEWPoint_ is an arbitrary name to allow us to use this deviceNetworkId elsewhere (kinda like a name tag on a person at a conference).
In this case something like George${app.id} would work as long as I was consistent.

Am I close?
Thanks
John

   def dewpointDev = getChildDevice("DEWPoint_${app.id}")
    if(!dewpointDev) dewpointDev = addChildDevice("hubitat", "Virtual DewPoint54", "DEWPoint_${app.id}", null, [label: thisName, name: thisName])
    dewpointDev.setDewPoint(0)

I'm not 100% sure I get the question, but hopefully my fumbling answer might prompt some questions.... By the sounds of it you understand that if you define a variable and include it in a string you get the value of the variable, so if you have "XYZ${var_name}" and var_name has a value of 123, you would get XYZ123 as the output of the string.

The same is true for built-in properties of devices and app objects, i.e. there are some things the HE platform manages for us like app IDs and Device Ids, which you see in the address bar when you open a device or app in the web UI. So when developing a device driver or app you can reference these without defining them. I going to make a guess and say app.id may be one of these. So once the app is installed and an instance of it created, the Dew Point device linked to the app will have the id of the app included, which I expect is the built-in id you see in the address bar of your browser.

Does that make sense? And was I on the right track? Or is it something else you were not sure about?

app.id is just a number that corresponds to the number assigned to the current application. If you bring up an app in the app list and look at the URL it will be in the format of http://<hubIPaddress>/installedapp/configure/app.id/…

2 Likes

Adding to the above, can I assume this is is an app that you found, not one that you wrote? If so, what this author was undoubtedly trying to do is find a way to make the DNI (device network ID) unique, as it must be for all devices on the same Hubitat hub. Combining some vague descriptor with the ID of the parent app or device is an easy way to very nearly ensure that this is the case for any child device your app or driver creates.

If you're writing the app/driver, it's totally up to you how you want to handle this, but, again, that's not a bad way. :smiley: If you're just curious about one you found or are considering modifying it, the same is ultimately true — but you'd need to examine their code to see if the parent ever uses the child DNIs for anything, e.g., identifying different types of child devices.

1 Like

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.