Help with luup variables

I have no idea why I am having such a hard time with these, but I am. I have been able to successfully CONTROL all of these devices with luup, but only on a few of them can I actually get a variable returned to me. I have created a function to make it easier to remember without looking up the correct syntax everytime, but I need someone to take a look and see if they can spot my problem. I am one million percent positive that I have the device id’s correct, so I know that isn’t it.

Here is my function. I have commented to the right hand side which ones are not working for me. (pretty much all of them).

[code] function device_var(deviceID, pVar)

   if (pVar == "dimmer") then
     local lul_status=luup.variable_get("urn:upnp-org:serviceId:Dimming1", "LoadLevelTarget",deviceID)
     return tonumber(lul_status)
  elseif (pVar == "switch" or "plug" or "fan") then
     local lul_status=luup.variable_get("urn:upnp-org:serviceId:SwitchPower1", "Status",deviceID)
     return tonumber(lul_status)
  elseif (pVar == "weather") then
     local lul_status = luup.variable_get("urn:upnp-micasaverde-com:serviceId:Weather1","Condition",deviceID)                       -- not working
     return lul_status
  elseif (pVar == "weather-temperature") then
     local lul_status = luup.variable_get("urn:upnp-micasaverde-com:serviceId:Weather1","CurrentTemperature",deviceID)    -- not working
     return tonumber(lul_status)
  elseif (pVar == "therm-cool") then
     local lul_status = luup.variable_get("urn:upnp-org:serviceId:TemperatureSetpoint1_Cool","CurrentSetpoint",deviceID)     -- not working
     return tonumber(lul_status)
  elseif (pVar == "therm-heat") then
     local lul_status=luup.variable_get("urn:upnp-org:serviceId:TemperatureSetpoint1_Heat","CurrentSetpoint",deviceID)            -- not working
     return tonumber(lul_status)
  elseif (pVar == "therm-mode") then
     local lul_status=luup.variable_get("urn:upnp-org:serviceId:HVAC_UserOperatingMode1","ModeStatus",deviceID)         -- not working
     return lul_status
  elseif (pVar == "therm-temperature") then
     local lul_status=luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1","CurrentTemperature", deviceID)         -- not working
     return tonumber(lul_status)
  elseif (pVar == "lock") then
     local lul_status= luup.variable_get ("urn:micasaverde-com:serviceId:SecuritySensor1", "Armed", deviceID)                    -- Only works for locked status (1)
     return tonumber(lul_status)
  elseif (pVar == "sensor") then
     local lul_status= luup.variable_get ("urn:micasaverde-com:serviceId:SecuritySensor1", "Armed", deviceID)                        -- not working
     return tonumber(lul_status)
  elseif (pVar == "sensor-tripped") then
     local lul_status= luup.variable_get ("urn:micasaverde-com:serviceId:SecuritySensor1", "Tripped", deviceID)                   -- not working
     return tonumber(lul_status)
  end

end

[/code]

And here is a sample of the code I am using to check a variable:

if (device_var(50,"lock") ==0) then

end

Any pointers would be greatly appreciated!

[quote author=smikk link=topic=8295.msg52773#msg52773 date=1319908163]

      elseif (pVar == "switch" or pVar == "plug" or pVar == "fan") then

Thanks, i didn’t notice that. Although, that is one of the 2 that actually works. The rest are the the ones that I cannot get variables for.

Thanks again for the reply.

Right. You end up in that branch because of the bug.

Also, I have another variable that I am trying to figure out how to get and control if possible.

I have a ge 45606 dimmer switch, and can manually configure the time it takes to dim on and off. So instead of taking 1 second to dim completely on, you can change it to turn completely on instantly.

I have a scene that flashes the light on and off and it doesn’t really work that great when the dimmer takes 1 second to dim on. I would like to change the variable in that scene so it turns on instantly, and then when the scene is finished, it will change it back (so it takes 1 second to dim on again).

Is this possible?

Perfect, I think that fixed it!

anyone know how or if I can get/set the configuration variables?

Thanks again!

[tt]urn:micasaverde-com:serviceId:ZWaveDevice1[/tt] has [tt]VariablesGet[/tt] and [tt]VariablesSet[/tt].

I’ve never tried to set them. They probably need applied by calling [tt]Reconfigure[/tt] though, which may not be what you want to do.

Ok, I can change the variables that show up in the advanced tab of the device (by using the VariablesSet like you mentioned) but it doesn’t change the configuration variables. I may be doing something wrong though.

Also, I spoke too soon, I cannot get those variables to work above. I tried specifically the “lock” and cannot get it to work. Any other suggestions on what my problem may be??

Thanks so much for the help!

I made some modifications to your code:

[ol][li]Changed the dimmer variable from LoadLevelTarget to LoadLevelStatus[/li]
[li]Added default values in case the variable_get function returns nil.[/li]
[li]Specified the base for the tonumber function. This can avoid ambiguous number errors.[/li][/ol]

Try it and let me know if it works.

function device_var (deviceID, pVar)

    if (pVar == "dimmer") then
        local lul_status = luup.variable_get("urn:upnp-org:serviceId:Dimming1", "LoadLevelStatus", deviceID) or "0"
        return tonumber (lul_status, 10)
    elseif (pVar == "switch" or pVar == "plug" or pVar == "fan") then
        local lul_status = luup.variable_get("urn:upnp-org:serviceId:SwitchPower1", "Status", deviceID) or "0"
        return tonumber (lul_status, 10)
    elseif (pVar == "weather") then
        local lul_status = luup.variable_get("urn:upnp-micasaverde-com:serviceId:Weather1", "Condition", deviceID) or "N/A"
        return lul_status
    elseif (pVar == "weather-temperature") then
        local lul_status = luup.variable_get("urn:upnp-micasaverde-com:serviceId:Weather1", "CurrentTemperature", deviceID) or "0"
        return tonumber (lul_status, 10)
    elseif (pVar == "therm-cool") then
        local lul_status = luup.variable_get("urn:upnp-org:serviceId:TemperatureSetpoint1_Cool", "CurrentSetpoint", deviceID) or "0"
        return tonumber (lul_status, 10)
    elseif (pVar == "therm-heat") then
        local lul_status = luup.variable_get("urn:upnp-org:serviceId:TemperatureSetpoint1_Heat", "CurrentSetpoint", deviceID) or "0"
        return tonumber (lul_status, 10)
    elseif (pVar == "therm-mode") then
        local lul_status = luup.variable_get("urn:upnp-org:serviceId:HVAC_UserOperatingMode1" , "ModeStatus", deviceID) or "Off"
        return lul_status
    elseif (pVar == "therm-temperature") then
        local lul_status = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1", "CurrentTemperature", deviceID) or "0"
        return tonumber (lul_status, 10)
    elseif (pVar == "lock") then
        local lul_status = luup.variable_get ("urn:micasaverde-com:serviceId:SecuritySensor1", "Armed", deviceID) or "0"
        return tonumber (lul_status, 10)
    elseif (pVar == "sensor") then
        local lul_status = luup.variable_get ("urn:micasaverde-com:serviceId:SecuritySensor1", "Armed", deviceID) or "0"
        return tonumber (lul_status, 10)
    elseif (pVar == "sensor-tripped") then
        local lul_status = luup.variable_get ("urn:micasaverde-com:serviceId:SecuritySensor1", "Tripped", deviceID) or "0"
        return tonumber (lul_status, 10)
    end
end