Luup Variables

From MiOS
(Difference between revisions)
Jump to: navigation, search
(Examples)
 
(21 intermediate revisions by 5 users not shown)
Line 1: Line 1:
 +
[[Category:Development]]
 
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.
 
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.
  
==On/Off Switch==
 
  
Device category: 3, UPnP device id: urn:schemas-upnp-org:device:BinaryLight:1
+
=On/Off Switch=
  
Variables:
+
==Device category==
 +
Device Category 3,
 +
UPnP device id: ''urn:schemas-upnp-org:device:BinaryLight:1''
  
Service: ''urn:upnp-org:serviceId:SwitchPower1'' Variable name: ''Status''
+
==Variables==
 +
{|  width="85%" cellpadding="10%" cellspacing="0" border="1"
 +
|+
 +
! align="left" width="30%"|Service!! align="left"|Variable!! align="left"|Description
 +
|-
 +
|''urn:upnp-org:serviceId:SwitchPower1''||''Status''||If the device is on, the value is ''1'', otherwise it's ''0''.
 +
|}
  
If the device is on, the value is 1, otherwise it's 0.
+
==Examples==
 +
* Getting whether the Switch/Light is on or off
 +
<source lang="lua">
 +
    local switchOnOff = luup.variable_get("urn:upnp-org:serviceId:SwitchPower1", "Status", 37)
 +
    if (switchOnOff == "1") then
 +
      -- Switch is on
 +
      ...
 +
    end -- if
 +
</source>
  
==Dimmable Light==
+
* Request that the Switch be turned on.  This will, eventually, set the variable after the device has responded to the request
 +
<source lang="lua">
 +
    luup.call_action("urn:upnp-org:serviceId:SwitchPower1", "SetTarget", {newTargetValue = "1"}, 37)
 +
</source>
  
Device category: 2, UPnP device id: urn:schemas-upnp-org:device:DimmableLight:1
+
=Dimmable Light=
  
Variables:
+
==Device category==
 +
Device category 2,
 +
UPnP device id: ''urn:schemas-upnp-org:device:DimmableLight:1''
  
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.
+
==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''
+
{|  width="85%" cellpadding="10%" cellspacing="0" border="1"
 +
|+
 +
! align="left" width="30%"|Service!! align="left"|Variable!! align="left"|Description
 +
|-
 +
|''urn:upnp-org:serviceId:Dimming1''||''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.
 +
|}
  
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.
+
==Examples==
 +
* Getting the current light/load level
 +
<source lang="lua">
 +
    local lightLevel = luup.variable_get("urn:upnp-org:serviceId:Dimming1", "LoadLevelStatus", 37)
 +
</source>
  
==Thermostat==
+
* Request that the Dimmer be set to 50% light/load level.  This will, eventually, set the variable after the device has responded to the request
 +
<source lang="lua">
 +
    luup.call_action("urn:upnp-org:serviceId:Dimming1", "SetLoadLevelTarget", {newLoadlevelTarget = "50"}, 19)
 +
</source>
  
Device category: 5, UPnP device id: urn:schemas-upnp-org:device:HVAC_ZoneThermostat:1
 
  
Variables:
+
=Thermostat=
  
Service: ''urn:upnp-org:serviceId:HVAC_UserOperatingMode1''  Variable name: ''ModeStatus''
+
==Device category==
 +
Device category 5,
 +
UPnP device id: ''urn:schemas-upnp-org:device:HVAC_ZoneThermostat:1''
  
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
+
==Variables==
+
{|  width="85%" cellpadding="10%" cellspacing="0" border="1"
Service: ''urn:upnp-org:serviceId:TemperatureSetpoint1_Heat'' Variable name: ''CurrentSetpoint''
+
|+
 +
! align="left" width="30%"|Service!! align="left"|Variable!! align="left"|Description
 +
|-
 +
|''urn:upnp-org:serviceId:HVAC_UserOperatingMode1''||''ModeStatus''||This indicates the current operating mode and will be one of the following basic values:  
 +
* ''Off''
 +
* ''HeatOn''
 +
* ''CoolOn''
 +
* ''AutoChangeOver''
  
Service: ''urn:upnp-org:serviceId:TemperatureSetpoint1_Cool'' Variable name: ''CurrentSetpoint''
+
In addition to the basic modes, some thermostats may also support the following modes:
 +
* ''InDeadBand''
 +
* ''AuxHeatOn''
 +
* ''EconomyHeatOn''
 +
* ''EmergencyHeatOn''
 +
* ''AuxCoolOn''
 +
* ''EconomyCoolOn''
 +
* ''BuildingProtection''
 +
* ''EnergySavingsHeating''
 +
* ''EnergySavingsCooling''
 +
|-
 +
|''urn:upnp-org:serviceId:TemperatureSetpoint1_Heat''||''CurrentSetpoint''||This indicates the current heat set point.
 +
|-
 +
|''urn:upnp-org:serviceId:TemperatureSetpoint1_Cool''||''CurrentSetpoint''||This indicatea the current cool set point.
 +
|-
 +
|''urn:upnp-org:serviceId:TemperatureSensor1''||''CurrentTemperature''||This indicates the current ambient temperature.
 +
|}
  
These indicate the current heat/cool set points.
+
==Examples==
 +
* Getting the current temperature
 +
<source lang="lua">
 +
    local outsideTemp = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1", "CurrentTemperature", 5)
 +
</source>
  
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 ''urn:micasaverde-com:serviceId:Weather1'' (taken from the XML file):
 +
 
 +
<source lang="lua">
 +
  -- Store the current Condition (eg. "rain")
 +
  luup.variable_set("urn:upnp-micasaverde-com:serviceId:Weather1", "ConditionGroup",
 +
                    condition, PARENT_DEVICE)
 +
</source>
 +
 
 +
From this we can get the Current Weather ConditionGroup using<br>
 +
Service: ''urn:upnp-micasaverde-com:serviceId:Weather1'' Variable name: ''ConditionGroup''
 +
 
 +
All we have to add is the device ID that Vera creates. In my case #''37''

Latest revision as of 21:09, 28 May 2015

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

[edit] On/Off Switch

[edit] Device category

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

[edit] Variables

Service Variable Description
urn:upnp-org:serviceId:SwitchPower1 Status If the device is on, the value is 1, otherwise it's 0.

[edit] Examples

  • Getting whether the Switch/Light is on or off
    local switchOnOff = luup.variable_get("urn:upnp-org:serviceId:SwitchPower1", "Status", 37)
    if (switchOnOff == "1") then
      -- Switch is on
      ...
    end -- if
  • Request that the Switch be turned on. This will, eventually, set the variable after the device has responded to the request
    luup.call_action("urn:upnp-org:serviceId:SwitchPower1", "SetTarget", {newTargetValue = "1"}, 37)

[edit] Dimmable Light

[edit] Device category

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

[edit] 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 Variable Description
urn:upnp-org:serviceId:Dimming1 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.

[edit] Examples

  • Getting the current light/load level
    local lightLevel = luup.variable_get("urn:upnp-org:serviceId:Dimming1", "LoadLevelStatus", 37)
  • Request that the Dimmer be set to 50% light/load level. This will, eventually, set the variable after the device has responded to the request
    luup.call_action("urn:upnp-org:serviceId:Dimming1", "SetLoadLevelTarget", {newLoadlevelTarget = "50"}, 19)


[edit] Thermostat

[edit] Device category

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

[edit] Variables

Service Variable Description
urn:upnp-org:serviceId:HVAC_UserOperatingMode1 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
urn:upnp-org:serviceId:TemperatureSetpoint1_Heat CurrentSetpoint This indicates the current heat set point.
urn:upnp-org:serviceId:TemperatureSetpoint1_Cool CurrentSetpoint This indicatea the current cool set point.
urn:upnp-org:serviceId:TemperatureSensor1 CurrentTemperature This indicates the current ambient temperature.

[edit] Examples

  • Getting the current temperature
    local outsideTemp = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1", "CurrentTemperature", 5)


[edit] 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 urn:micasaverde-com:serviceId:Weather1 (taken from the XML file):

  -- Store the current Condition (eg. "rain")
  luup.variable_set("urn:upnp-micasaverde-com:serviceId:Weather1", "ConditionGroup",
                    condition, PARENT_DEVICE)

From this we can get the Current Weather ConditionGroup using
Service: urn:upnp-micasaverde-com:serviceId:Weather1 Variable name: ConditionGroup

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

Personal tools