LastTrip variable not working (using sample code)

I am a new vera user and luup programmer and I’m having trouble getting some of the sample code running. I have the Elk Alarm plugin up and working. The device specified by sensorDeviceNo is one of my motion detectors on my elk alarm system.

The below sample code (straight from the wiki) does not work properly. The lights turn on when motion is detected but never turn off. So I know I specified the correct device numbers. I did some debugging and found out that the line “local lastTrip = luup.variable_get (SS_SID, “LastTrip”, sensorDeviceNo) or os.time()” is always returning the os.time() and never gets the LastTrip time. Can anyone offer some assistance?

[code]local sensorDeviceNo = 16 – Motion Sensor device number
local lightDeviceNo = 13 – Light device number
local period = 10 – Seconds

local SS_SID = “urn:micasaverde-com:serviceId:SecuritySensor1” – Security Sensor Service ID
local SP_SID = “urn:upnp-org:serviceId:SwitchPower1” – Switch Power Service ID

function checkLastTrip()
local lastTrip = luup.variable_get (SS_SID, “LastTrip”, sensorDeviceNo) or os.time()
if (os.difftime (os.time(), tonumber (lastTrip)) >= period) then
luup.call_action (SP_SID, “SetTarget”, {[“newTargetValue”] = 0}, lightDeviceNo) – Turn off the light.
else
luup.call_delay (“checkLastTrip”, period) – Check when the sensor was last tripped every seconds.
end
end

luup.call_delay (“checkLastTrip”, period)

return true[/code]

Can you verify that the motion sensor from your alarm panel has a value of LastTrip. This can be found in the advanced tab when clicking the wrench icon for the motion sensor in Vera. Scroll to the bottom and you should see the variables. If you do not see the lastTrip variable, than the code will not work at the Elk Alarm Panel plugin does not write the LastTrip value to the motion device.

  • Garrett

[quote=“garrettwp, post:2, topic:176409”]Can you verify that the motion sensor from your alarm panel has a value of LastTrip. This can be found in the advanced tab when clicking the wrench icon for the motion sensor in Vera. Scroll to the bottom and you should see the variables. If you do not see the lastTrip variable, than the code will not work at the Elk Alarm Panel plugin does not write the LastTrip value to the motion device.

  • Garrett[/quote]

Thanks for your help. It does not have a variable named LastTrip. Am I correct that this is something that would need to be fixed in the alarm plugin itself?

I actually suspected this was the problem originally and posted in the thread dedicated to the alarm plugin (http://forum.micasaverde.com/index.php/topic,6916.msg121261.html#msg121261) but didn’t get any response.

Yeah, it needs to be implemented in the plugin. (Example: I haven’t set this variable in the Caddx alarm plugin. I should.)

here is what worked for me

[code]dofile(“/root/SceneScripts/Devices.luup”)

local ProjectorState= luup.variable_get(“urn:upnp-org:serviceId:SwitchPower1”, “Status”, Projector) – Get Projector State
local Dimmlvl= luup.variable_get(“urn:upnp-org:serviceId:Dimming1”, “LoadLevelLast”, HueKitchen2)
local SwitchState= luup.variable_get(“urn:upnp-org:serviceId:SwitchPower1”, “Status”, KitchenLights) – Get Get Kitchen Light State

local SS_SID = “urn:micasaverde-com:serviceId:SecuritySensor1” – Security Sensor Service ID
local SD_SID = “urn:upnp-org:serviceId:Dimming1” – Switch Dimming Service ID
local SP_SID = “urn:upnp-org:serviceId:SwitchPower1” – Switch Power Service ID
local PH_SID = “urn:upnp-org:serviceId:althue1”
local period = 130 – Seconds
local DefDimmlvl = 3 – Default Dimming Load Level
local Dimthresh = 30 – Dimming Threshhold
– Scene Id
local Kitchenbrightall = “N0uJiME6DcilNln”
local Kitchendimall = “hNQMaFECpN0Gu9v”
local Kitchenmoviebright = “Iht1YQUJziXbdg9”

if (tonumber (Dimmlvl) >= tonumber (Dimthresh) ) then --Checks the dimming level
Dimmlvl = DefDimmlvl
luup.log(“Dim load Level > Dimming Threshold”)
end

if (SwitchState ~= “1”) then – Check Projector State
luup.log(“Turn on Lights”)
luup.call_action(SP_SID, “SetTarget”, {[“newTargetValue”] = 1}, KitchenLights) – Brighten Turn On Kitchen Lights
end

if (ProjectorState == “1”) then – Check Projector State
luup.log(“run Scene to brighten back 2 lights to 60”)
luup.call_action(PH_SID, “RunHueScene”, {hueSceneID= Kitchenmoviebright }, BurnsedPl)
luup.log(“Kitchen number 2 load leve change”)
luup.call_action(SD_SID, “SetLoadLevelTarget”, {newLoadlevelTarget=“60”}, HueKitchen2) – Brighten Kitchen Number 2
luup.log(“Kitchen number 4 load leve change”)
luup.call_action(SD_SID, “SetLoadLevelTarget”, {newLoadlevelTarget=“60”}, HueKitchen4) – Brighten Kitchen Number 4
else
luup.log(“Projector is off Brighten All Lights”) – Projector off
luup.log(“run Scene to brighten all lights”)
luup.call_action(PH_SID, “RunHueScene”, {hueSceneID= Kitchenbrightall }, BurnsedPl) – Brighten Scene
luup.log(“Kitchen number 1 load leve change”)
luup.call_action(SD_SID, “SetLoadLevelTarget”, {newLoadlevelTarget=“100”}, HueKitchen1) – Brighten Kitchen Number 1
luup.log(“Kitchen number 2 load leve change”)
luup.call_action(SD_SID, “SetLoadLevelTarget”, {newLoadlevelTarget=“100”}, HueKitchen2) – Brighten Kitchen Number 2
luup.log(“Kitchen number 3 load leve change”)
luup.call_action(SD_SID, “SetLoadLevelTarget”, {newLoadlevelTarget=“100”}, HueKitchen3) – Brighten Kitchen Number 3
luup.log(“Kitchen number 4 load leve change”)
luup.call_action(SD_SID, “SetLoadLevelTarget”, {newLoadlevelTarget=“100”}, HueKitchen4) – Brighten Kitchen Number 4

end

function checkLastTrip()
local lastTripmotion = luup.variable_get (SS_SID, “LastTrip”, KitchenMotion) --or os.time()
local Tripstate = luup.variable_get (SS_SID, “Tripped”, KitchenMotion)
local Ostime = os.time()
local osdifftime = os.difftime (tonumber (os.time()), tonumber (lastTripmotion))
luup.log("Os Time = " … Ostime … ", LastTrip = " … lastTripmotion … ", Diff = " … osdifftime … ", Trip state = " … Tripstate … “.”)
if (Tripstate == “0”) then
–(tonumber (os.difftime (tonumber (os.time()), tonumber (lastTripmotion))) >= tonumber (period))

	luup.log("run Scene to dimm lights")
	luup.call_action(PH_SID, "RunHueScene", {hueSceneID= Kitchendimall }, BurnsedPl) -- Brighten Scene
	luup.log("Re-dimm the light Scene")
    luup.call_action(SD_SID, "SetLoadLevelTarget", {newLoadlevelTarget= tonumber (Dimmlvl)}, HueKitchen1) -- Re-dimm the light.
	luup.log("Re-dimm the light.")
    luup.call_action(SD_SID, "SetLoadLevelTarget", {newLoadlevelTarget= tonumber (Dimmlvl)}, HueKitchen1) -- Re-dimm the light.
	luup.log("Re-dimm the light.")
	luup.call_action(SD_SID, "SetLoadLevelTarget", {newLoadlevelTarget= tonumber (Dimmlvl)}, HueKitchen2) -- Re-dimm the light.	
	luup.log("Re-dimm the light.")
    luup.call_action(SD_SID, "SetLoadLevelTarget", {newLoadlevelTarget= tonumber (Dimmlvl)}, HueKitchen3) -- Re-dimm the light.
	luup.log("Re-dimm the light.")
	luup.call_action(SD_SID, "SetLoadLevelTarget", {newLoadlevelTarget= tonumber (Dimmlvl)}, HueKitchen4) -- Re-dimm the light.				
else
    luup.call_delay ("checkLastTrip", period) -- Check when the sensor was last tripped every <period> seconds.
end

end

luup.call_delay (“checkLastTrip”, period)

return true

[/code]

the problem is for some reason Lasttrip fails to work because it fails to update so your sensor will look like it hasnt been tripped
so i just decresed the timeout to 1 min and used time out instead