New to scene scripting

Hi all,

Have some experience in vbscript and turbo pascal, but new to Luup and Lua :slight_smile:

Can read KWH from different device, but have to make my code more effective.


local varDeviceID = 8
local kw = luup.variable_get(“urn:schemas-upnp-org:device:BinaryLight:1”, “KWH”, varDeviceID )
luup.variable_set(“urn:schemas-upnp-org:device:BinaryLight:1”, “KWH24”, kw, varDeviceID)
local varDeviceID = 9
local kw = luup.variable_get(“urn:schemas-upnp-org:device:BinaryLight:1”, “KWH”, varDeviceID )
luup.variable_set(“urn:schemas-upnp-org:device:BinaryLight:1”, “KWH24”, kw, varDeviceID)
return true


If I have a lot of devices, can I change the code to use a while, repeat or for statement ?

I have try this.


local varDeviceID = 0
for varDeviceID = 8,9,10,12,14 do
local kw = luup.variable_get(“urn:schemas-upnp-org:device:BinaryLight:1”, “KWH”, varDeviceID )
luup.variable_set(“urn:schemas-upnp-org:device:BinaryLight:1”, “KWH24”, kw, varDeviceID)
end
return true


Thank you

local svs = "urn:schemas-upnp-org:device:BinaryLight:1"
for i, dev in ipairs ( { 8,9,10,12,14}) do 
  local kw = luup.variable_get(svs, "KWH", dev)
  luup.variable_set(svs, "KWH24", dev)
end
return true