One of the most frequent problems we see in requests for help with Lua code, is errors in Service IDs and variable or parameter names in luup function calls. These errors can be tricky to find. Even one character in the wrong case will prevent the call working correctly: A luup.variable_get(…) will return a nil instead of the expected value; A luup.call_action(…) may do absolutely nothing.
Listed below are example luup calls for the most common device types. All examples assume that local variable dID contains the ID of the device being addressed. e.g. local dID = 123 Alternatively, replace dID in the calls with the required device ID number. Examples are given for reading a device variable using luup.variable_get(…) and for initiating an action with luup.call_action(…). It is also possible to directly set device variables but, in many cases, this will have little or no apparent effect on the device. Generally it is better to use luup.call_action(…) rather than directly setting device variables.
The examples are also in the attached pdf file. If you drop it on your desktop, you can quickly open it to copy and paste the calls into your Lua. If the device you want to address is not listed, you can find the Service ID by hovering the mouse cursor over the name of the variable on the device’s Advanced tab.
On/Off Switch
Set Target, read Status. “0” = Off, “1” = On.
[code]local status = luup.variable_get(“urn:upnp-org:serviceId:SwitchPower1”, “Status”, dID)
luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”, “SetTarget”, {newTargetValue = “1”}, dID)[/code]
Virtual Switch
Set Target, read Status. “0” = Off, “1” = On.
[code]local status = luup.variable_get(“urn:upnp-org:serviceId:VSwitch1”, “Status”, dID)
luup.call_action(“urn:upnp-org:serviceId:VSwitch1”, “SetTarget”, {newTargetValue = “1”}, dID)[/code]
Dimmable Light
Set LoadLevelTarget, read LoadLevelStatus. “0” = Off, “100” = Full.
[code]local level = luup.variable_get(“urn:upnp-org:serviceId:Dimming1”, “LoadLevelStatus”, dID)
luup.call_action(“urn:upnp-org:serviceId:Dimming1”, “SetLoadLevelTarget”, {newLoadlevelTarget = “50”}, dID)[/code]
Thermostat
Set ModeTarget, read ModeStatus. “Off”, “HeatOn”, “CoolOn”, “AutoChangeOver”.
[code]local mode = luup.variable_get(“urn:upnp-org:serviceId:HVAC_UserOperatingMode1”, “ModeStatus”, dID)
luup.call_action(“urn:upnp-org:serviceId:HVAC_UserOperatingMode1”, “SetModeTarget”, {NewModeTarget = “Off”}, dID)[/code]
Set and read CurrentSetpoint. (Degrees)
[code]local setpoint = luup.variable_get(“urn:upnp-org:serviceId:TemperatureSetpoint1_Heat”, “CurrentSetpoint”, dID)
luup.call_action(“urn:upnp-org:serviceId:TemperatureSetpoint1_Heat”, “SetCurrentSetpoint”, {NewCurrentSetpoint = “25”}, dID)
local setpoint = luup.variable_get(“urn:upnp-org:serviceId:TemperatureSetpoint1_Cool”, “CurrentSetpoint”, dID)
luup.call_action(“urn:upnp-org:serviceId:TemperatureSetpoint1_Cool”, “SetCurrentSetpoint”, {NewCurrentSetpoint = “30”}, dID)[/code]
Temperature Sensor
local temp = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1", "CurrentTemperature", dID)
Generic Sensor
local level = luup.variable_get("urn:micasaverde-com:serviceId:GenericSensor1", "CurrentLevel", dID)
Light Sensor
local level = luup.variable_get("urn:micasaverde-com:serviceId:LightSensor1", "CurrentLevel", dID)
Humidity Sensor
local level = luup.variable_get("urn:micasaverde-com:serviceId:HumiditySensor1", "CurrentLevel", dID)
Security Sensor
[code]local tripped = luup.variable_get(“urn:micasaverde-com:serviceId:SecuritySensor1”, “Tripped”, dID)
local armed = luup.variable_get(“urn:micasaverde-com:serviceId:SecuritySensor1”, “Armed”, dID)
local lasttrip = luup.variable_get(“urn:micasaverde-com:serviceId:SecuritySensor1”, “LastTrip”, dID)
luup.call_action(“urn:micasaverde-com:serviceId:SecuritySensor1”, “SetArmed”, {newArmedValue = “1”}, dID)[/code]
Window Covering
Use Dimmable Light Status variable for current position. Down = 0, Up = 100.
[code]local level = luup.variable_get(“urn:upnp-org:serviceId:Dimming1”, “LoadLevelStatus”, dID)
luup.call_action(“urn:upnp-org:serviceId:WindowCovering1”, “Up”, {}, dID)
luup.call_action(“urn:upnp-org:serviceId:WindowCovering1”, “Down”, {}, dID)
luup.call_action(“urn:upnp-org:serviceId:WindowCovering1”, “Stop”, {}, dID)[/code]
Variable Container
Set and read VariableN where N is 1 to 5.
[code]local vcvar1 = luup.variable_get(“urn:upnp-org:serviceId:VContainer1”, “Variable1”, dID)
luup.variable_set(“urn:upnp-org:serviceId:VContainer1”, “Variable1”,newvalue, dID)
luup.variable_set(“urn:upnp-org:serviceId:VContainer1”, “Variable5”,“newtext”, dID)[/code]
DayTime plugin
Set and read Status. “0” = Night, “1” = Day.
[code]local itsday = luup.variable_get(“urn:rts-services-com:serviceId:DayTime”, “Status”, dID)
luup.variable_set(“urn:rts-services-com:serviceId:DayTime”, “Status”, “1”, dID)[/code]
Edit: 13/05/2014 08:50 Corrected typo in DayTime example.