Luup Declarations
When the Luup engine calls your Lua code it will pass your code some variables relevant to whatever the code is supposed to do. You can see how your code looks with the full function declarations by bringing up this page in a web browser: http://ip_of_vera:49451/data_request?id=lu_lua&DeviceNum=8
Here is a list of the variables that are passed to your Lua code, and also a list of what return values the Lua code should send back:
run
variables: lul_device is a number that is the device id. lul_settings is a table with all the arguments to the action.
return value: true or false where true means the function ran ok, false means it failed.
Sample:
function SetTarget_run(lul_device,lul_settings)
lu_log('device: ' .. tostring(lul_device) .. ' value: ' .. tostring(lul_settings.newTargetValue))
local lul_send = "setstate," .. lug_module_by_child(lul_device) .. "," .. lul_settings.newTargetValue
lu_log('send: ' .. tostring(lul_send))
lu_iop_intercept_incoming()
if lu_iop_send(lul_send)==false then
lu_log("cannot send: " .. tostring(lul_send),1)
lu_SetCommFailure(true)
return false
end
incoming_data = lu_iop_recv_block();
if( incoming_data=="state," .. lug_module_by_child(lul_device) .. "," .. lul_settings.newTargetValue ) then
lu_log('good response: ' .. tostring(incoming_data))
lu_SetVariable("urn:upnp-org:serviceId:SwitchPower1","Target",lul_settings.newTargetValue,lul_device) lu_SetVariable("urn:upnp-org:serviceId:SwitchPower1","Status",lul_settings.newTargetValue,lul_device)
return true
else
lu_log('bad response: ' .. tostring(incoming_data))
return false
end
end