Need room wise device list

Hi all,

I have rooms. And in each room there are multiple dimmable bulbs.
So for example I have 10 bulbs in room 1

I have developed a plugin which controlls the dimmer value and switch. Now I want to repeat this logic in room so that if end user sets dimmer value of room to 50, all bulbs inside room should set load level to 50

This is working fine for individual devices

but I am stuck at following tasks

  1. Get assigned room id for my plugin instance
  2. Get all bullb ids in that room

Please let me know if more clarification is needed.

-Deep

[quote=“Deeps, post:1, topic:199422”]but I am stuck at following tasks

  1. Get assigned room id for my plugin instance
  2. Get all bullb ids in that room[/quote]

Every device listed in the luup.devices variable has a table structure like this:

{
	 category_num = 4,
	 description = "Front Door",
	 device_num_parent = 1,
	 device_type = "urn:schemas-micasaverde-com:device:DoorSensor:1",
	 embedded = false,
	 hidden = false,
	 id = "56",
	 invisible = false,
	 ip = "",
	 mac = "",
	 pass = "",
	 room_num = 16,
	 subcategory_num = 3,
	 udn = "uuid:4d494342-5342-5645-00a3-00000217a85c",
	 user = ""
}

with room_num being the relevant value, and the global variable luup.rooms is simply a list of room names indexed by room number.

This should give you all you need.

Sorry for asking on multiple threads

so my concern is for high no of devices and delays getting introduced due to looping thought them in following cases.

But my count of rooms and bulbs is very high. Basically my plugin is for agriculture land bulbs.
So I have almost 10-15 rooms and hundreds of bulbs

I i do device list and search for individual room and then apply room logic in loop, it will be tooo much lengthy process.

is there any API to get device ids for provided room id, room wise device list.

Actually, I don’t think this is many rooms or lights… you are, after all, using a computer (if I can call Vera that!)

To ease your mind, it is possible to make an index of devices by room number at the start of your plugin:

local room_index = {}
for i,d in pairs(luup.devices) do
    local room = d.room_num
    local idx = room_index[room] or {}
    idx[#idx+1] = i
    room_index[room] = idx
end

Then each element of room_index will contain the devices in that room:

for k,v in pairs (room_index) do
    print ("room " .. k, pretty(v))
end

results in…

room 0 	{2,3,4,13,14,16,17,18,20,21,22,23,24,25,26,27,28,29,30,32,33,34,35,36,37,38,39,40,41,42,43,44,45,47,48,49,50,51,52,53,54,55,56,57}
room 1 	{1,10083,10137,10145,10149,10151,10153,10155,10157,10159,10002,10004,10006,10008,10056,10084,10100,10090,10138,10140,10142,10150,10152,10154,10156,10158,10091,10007}
room 3 	{30094,30166,30170,30186,30198,30226,30230,30234,30238,30051,30095,30131,30211,30231,30235,30239,30008,30012,30044,30048,30052,30056,30060,30096,30188,30208,30220,30224,30228,30232,30236,30001,30009,30013,30029,30045,30057,30157,30163,30218,30216,30206,30205,30204,30199,30197,30187,30209,30217,30221,30229,30233,30002,30010,30014,30055,30030,30046,30050,30058,30047,30049}
room 4 	{20408,20412,20428,20444,20456,20460,20468,20002,20006,20273,20317,20325,20353,20365,20369,20373,20385,20389,20413,20425,20469,20473,20003,20007,20310,20326,20382,20390,20414,20438,20211,20474,20004,20271,20307,20327,20363,20371,20383,20403,20407,20318,20354,20427,20431,20443,20447,20459,20001,20005,20324,20368,20340,20475,20308,20316,20366,20336,20370,20319,20352,20364,20372,20450,20367,20384,20388}

No effort at all, to speak of.