LUA code for dashboard shortcuts for Locks and Light On

Silly question,

does anyone know what it takes LUA wise to determine if; all the locks are locked and all the lights are off and if not what the count of devices not locked/off (same as used on the dashboard). I was inspecting various examples of Sono templates in particular “Check The Status Of The Lights” which announces at a prescribed time that all lights have or have not been turned off. The issue that saw with the current approach requires every light/lock device to be identified/declared and placed into a sequential “or” statement (no good if you change/delete devices at a later time period). I was hoping that the system (dashboard solution would be a cleaner way of reporting light and lock status, any help would be greatly appreciated. Mike

I think you’ll find those dashboard level totals as top-level system attributes, which means they would be reported in an HTTP port 3480 request for user_data, but more easily accessed with luup.attr_get() without specifying a device number.

A perusal of the user_data would give you the relevant attribute names.

@akbooer,
The code below is three examples of three different device type, could you advise if I used the condition correctly and secondly I’m not sure the way I defined the device ID will it look at all devices of the category? Mike

[code]luup.log(‘Commencing BinaryLight device search loop’)
for deviceNo,d in pairs(luup.devices) do
if d.category_num == 3 then
local switchOnOff = luup.variable_get(“urn:schemas-upnp-org:serviceId:SwitchPower1”, “Status”,deviceNo)
if (switchOnOff == “1”) then
– Switch is on

end – if

luup.log(‘Commencing Dimmer device search loop’)
for deviceNo,d in pairs(luup.devices) do
if d.category_num == 2 then
local lightLevelOnOff = luup.variable_get(“urn:schemas-upnp-org:serviceId:Dimming1”, “Status”,deviceNo)
if (LightLevelOnOff == “1”) then
– Switch is on

end – if

luup.log(‘Commencing Lock device search loop’)
for deviceNo,d in pairs(luup.devices) do
if d.category_num == 7 then
local LockLocked = luup.variable_get(“urn:schemas-upnp-org:serviceId: DoorLock1”, “Locked”, deviceNo)
if (LockLocked == “1”) then
– Switch is on

end – if[/code]
[/code]

Ah, well, that wasn’t exactly what I meant. This looks OK, but I led you down the garden path a little by mentioning user_data and attr_get when I should have said status.

Assuming you’re using UI7, then the following will probably give you the information you seek?

local _, status = luup.inet.wget "http://127.0.0.1:3480/data_request?id=status"
local json = require "dkjson"
local s = json.decode (status)
local function p(x) print (x, s[x]) end

p "lights_on"
p "lights_off"
p "doors_locked"
p "doors_unlocked"
p "sensors_tripped"
p "sensors_not_tripped"

I’ve put in a print statement, assuming that you’ll try this out first in Rex Becketts’ excellent LuaTest, but anyway it should give you a clue as to how to access useful info.