Luup Variables

From MiOS
(Difference between revisions)
Jump to: navigation, search
m
(Other Devices or Services)
Line 46: Line 46:
  
 
You can find other variables by looking at code.  For example, looking at the code for the LUUP Weather plugin, we can see where the "serviceID" for Current Conditions is "Weather1" (taken from the XML file):
 
You can find other variables by looking at code.  For example, looking at the code for the LUUP Weather plugin, we can see where the "serviceID" for Current Conditions is "Weather1" (taken from the XML file):
 
+
<nowiki>
 
Store the current Condition (eg. "Sunny")
 
Store the current Condition (eg. "Sunny")
 
         luup.variable_set("urn:micasaverde-com:serviceId:Weather1", "Condition",
 
         luup.variable_set("urn:micasaverde-com:serviceId:Weather1", "Condition",
 
             condition, PARENT_DEVICE)
 
             condition, PARENT_DEVICE)
 
+
</nowiki>
 
From this we can get the "serviceID data":  micasaverde-com:serviceId:Weather1
 
From this we can get the "serviceID data":  micasaverde-com:serviceId:Weather1
 
The variable we want to call:  Condition
 
The variable we want to call:  Condition
Line 58: Line 58:
 
For my testing, I wanted to create a LUUP scene that will turn on a light when the Condition is Showers.  So I create a new SCENE and add the following to the LUUP SCENE:
 
For my testing, I wanted to create a LUUP scene that will turn on a light when the Condition is Showers.  So I create a new SCENE and add the following to the LUUP SCENE:
  
 +
<nowiki>
 
local lul_tmp = luup.variable_get("urn:micasaverde-com:serviceId:Weather1","Condition",37)
 
local lul_tmp = luup.variable_get("urn:micasaverde-com:serviceId:Weather1","Condition",37)
 
  if( lul_tmp=="Showers" ) then
 
  if( lul_tmp=="Showers" ) then
Line 64: Line 65:
 
  luup.call_action("urn:upnp-org:serviceId:Dimming1","SetLoadLevelTarget",{ newLoadlevelTarget="0" },19)
 
  luup.call_action("urn:upnp-org:serviceId:Dimming1","SetLoadLevelTarget",{ newLoadlevelTarget="0" },19)
 
  end
 
  end
 +
</nowiki>
  
 
To break this down, line 1 gets the variable CONDITION from the serviceID type Weather1 on DEVICE 37
 
To break this down, line 1 gets the variable CONDITION from the serviceID type Weather1 on DEVICE 37

Revision as of 05:53, 17 March 2010

The "Variables" for a device tell you it's current state, such as if it's on or off, what temperature it has, and so on. Variables are given a name and a service ID, which is defined by the UPnP forum. You can use this service ID/variable name pair to get the state of a device in the Luup engine by using the function luup.variable_get, as documented in Luup_Lua_extensions. You can also see the current value of a device's variables by going into Vera's setup page, click 'Devices', click + next to the device, then click 'Advanced'. The name of every variable for the device is shown along with the current value, and if you move your mouse over the variable name, you will the corresponding service ID in a popup window.

Contents

On/Off Switch

Device category: 3, UPnP device id: urn:schemas-upnp-org:device:BinaryLight:1

Variables:

Service: urn:upnp-org:serviceId:SwitchPower1 Variable name: Status

If the device is on, the value is 1, otherwise it's 0.

Dimmable Light

Device category: 2, UPnP device id: urn:schemas-upnp-org:device:DimmableLight:1

Variables:

Dimmable lights contain the same variable of an On/Off Switch to indicate the current on/off value, and, if it's on, LoadLevelStatus indicates the dim level.

Service: urn:upnp-org:serviceId:Dimming1 Variable name: LoadLevelStatus

If the device is off (see On/Off switch) this value indicates the last known dim level, if it's on, this value is the actual dim level. The value is a number from 0-100 indicating a percentage of brightness.

Thermostat

Device category: 5, UPnP device id: urn:schemas-upnp-org:device:HVAC_ZoneThermostat:1

Variables:

Service: urn:upnp-org:serviceId:HVAC_UserOperatingMode1 Variable name: ModeStatus

This indicates the current operating mode and will be one of the following basic values: Off, HeatOn, CoolOn, AutoChangeOver. In addition to the basic modes, some thermostats may also support the following modes: InDeadBand, AuxHeatOn, EconomyHeatOn, EmergencyHeatOn, AuxCoolOn, EconomyCoolOn, BuildingProtection, EnergySavingsHeating, EnergySavingsCooling

Service: urn:upnp-org:serviceId:TemperatureSetpoint1_Heat Variable name: CurrentSetpoint

Service: urn:upnp-org:serviceId:TemperatureSetpoint1_Cool Variable name: CurrentSetpoint

These indicate the current heat/cool set points.

Service: urn:upnp-org:serviceId:TemperatureSensor1 Variable name: CurrentTemperature

This indicates the current ambient temperature.

Other Devices or Services

You can find other variables by looking at code. For example, looking at the code for the LUUP Weather plugin, we can see where the "serviceID" for Current Conditions is "Weather1" (taken from the XML file): Store the current Condition (eg. "Sunny") luup.variable_set("urn:micasaverde-com:serviceId:Weather1", "Condition", condition, PARENT_DEVICE) From this we can get the "serviceID data": micasaverde-com:serviceId:Weather1 The variable we want to call: Condition

All we have to add is the device ID that Vera creates. In my case #37

For my testing, I wanted to create a LUUP scene that will turn on a light when the Condition is Showers. So I create a new SCENE and add the following to the LUUP SCENE:

local lul_tmp = luup.variable_get("urn:micasaverde-com:serviceId:Weather1","Condition",37) if( lul_tmp=="Showers" ) then luup.call_action("urn:upnp-org:serviceId:Dimming1","SetLoadLevelTarget",{ newLoadlevelTarget="50" },19) else luup.call_action("urn:upnp-org:serviceId:Dimming1","SetLoadLevelTarget",{ newLoadlevelTarget="0" },19) end

To break this down, line 1 gets the variable CONDITION from the serviceID type Weather1 on DEVICE 37 Line 2 compares the returned variable to "Showers" If the condition is true then it calls line 3 which turns on the lamp (device 19 at 50% level. If the condition is false, it turns off the lamp.

What good is this? Nothing past testing but it would be a good method to close the garage door if it is raining.

  • Be sure to set a timer to poll this scene ever xx minutes or hours. Please edit if you know of a way to have it automatically poll.
Personal tools