Enumerate devices, plugins or services

I’m trying to enumerate the various devices in LUUP code for a scene. I currently have 6 thermostats with potentially more coming. I would like to make adjustments to my temperatures based on outdoor temp, and to plugin devices like GCal Google Calendar monitors. Essentially, I want to check the temperature at midnight and adjust schedules, target temps, etc. Instead of hard coding all of my device ID’s, I am hoping to be able to enumerate all of my devices and make any necessary adjustments.

I have tried using this as a basis:

for k,v in pairs(luup.devices) do if( v.category_num==4) then luup.log("SecurityDevice: " .. v.description ) elseif( v.category_num==17 ) then ... end end

It hasn’t been totally successful. I haven’t figured out what model I can use to enumerate the multiple services that a device might have (like Temperature Sensor and HVAC Heat in a single thermostat). Is there a way to essentially walk through the state(s) of the objects I see on my “Devices” tab? Do I need to use the user_data/sdata and parse it or does the object model allow me to walk it in a for/while/do or other loop?

Any help would be great. I’ve considered using naming conventions for devices and other strategies. I am trying to make my code a little more dynamic so future changes to the configuration do not require re-coding triggers and scheduled LUUP.


The Luup API is incomplete in many areas, and obtaining the implemented ServiceId’s is one of them.

If [tt]category_num[/tt] is not sufficient, then you may have to resort to parsing the more complex JSON/XML versions… It really depends upon what you’re planning to do with the data, and the level of detail you ultimately need for the task.

That said, parsing it will be resource intensive, since the “full” version of the file can get quite large (mine is 500k+). Given this, it would pay to do it infrequently, and keep the information somewhere.

If you only need to do this on a single-device, then it can be done a little more piecemeal with the [tt]lu_actions[/tt] call:

where you’ll get the JSON of the services that just that device has (4, in this example).