Getting ID of a child device (using AltID?) in order to call luup.variable_set

Right now I am working on motion sensors. My problem is I don’t know the id of the child devices I create, just the altid.

This code (with a hardcoded child device id) works great:

luup.variable_set(“urn:micasaverde-com:serviceId:SecuritySensor1”, “Tripped”, ‘1’, 55)

This code does not:

local my_altid = “M-M1”
luup.variable_set(“urn:micasaverde-com:serviceId:SecuritySensor1”, “Tripped”, ‘1’, my_altid)

It seem like using an alt ID in “luup.variable_set” is not supported? Am I missing something simple?


You are correct in that it doesn’t work with the altid. However, you could get the device ID if you know the altid. Check the luup.devices variable:
[url=][/url]. There is a parameter named id, which is actually the altid. So you could parse the luup.devices variable and check the altid. When you find it, then the device ID is the index.

Thank you for the prompt response! That worked great.

Add this code:

local child_id_lookup_table = {}

– Find my children and build lookup table of altid → id

– loop over all the devices registered on Vera
for k, v in pairs(luup.devices) do
– if I am the parent device
if v.device_num_parent == luup.device then
luup.log('Found Child ID: ’ … k … ’ AltID: ’ …
child_id_lookup_table[] = k

And then later:

id = child_id_lookup_table[altid]