I utilized some existing code and modified it for my needs. I have been troubleshooting why my logic around checking to make sure the tripped time is equal isn’t working. The first part is the code I have created. The second part is the output of the log file that I was watching. Can you please help me understand why this is occurring? The main variables to focus on are trippedtime and lastTrip.
trippedtime is pulled outside of the function and lastTrip is pulled inside of the function. I realize that I have created an infinite loop with this, but I am trying to understand why the two variables never will match!
[code]local sensorDeviceNo = 6 – Motion Sensor device number
local lightDeviceNo = 13 – Light device number
local period = 10 – Seconds
local countdown = 30
local SS_SID = “urn:micasaverde-com:serviceId:SecuritySensor1” – Security Sensor Service ID
local SP_SID = “urn:upnp-org:serviceId:SwitchPower1” – Switch Power Service ID
local trippedtime = luup.variable_get(“urn:micasaverde-com:serviceId:SecuritySensor1”, “LastTrip”, 6)
local t = os.date(‘*t’)
local current = t.hour * 3600 + t.min * 60 + t.sec
local min_time = 17 * 3600 + 30 * 60
local max_time = 20 * 3600 + 15 * 60
local adult_time = 20 * 3600 + 15 + 60 + 1
local bed_time = 22 * 3600
local night_time = 22 * 3600 + 1
local morning = 6 * 3600
local morning_ready = 6 * 3600 + 1
local morning_ready_end = 8 * 3600 + 30 * 60
function checkLastTrip()
local lastTrip = luup.variable_get(“urn:micasaverde-com:serviceId:SecuritySensor1”, “LastTrip”, 6)
if (trippedtime == lastTrip) then
luup.log("Tripped and last equal - " … "trippedtime: " … trippedtime … " lastTrip: " … lastTrip)
if (os.difftime (os.time(), tonumber (lastTrip)) >= countdown) then
if (current > min_time) and (current < max_time) then
luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”, “SetTarget”, {newTargetValue = “0”}, 5) --floor lamp
luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”, “SetTarget”, {newTargetValue = “0”}, 7) --table lamp
luup.call_action(“urn:upnp-org:serviceId:Dimming1”, “SetLoadLevelTarget”, {newLoadlevelTarget = “0”}, 65) --Ceiling Light
luup.call_action(“urn:upnp-org:serviceId:Dimming1”, “SetLoadLevelTarget”, {newLoadlevelTarget = “0”}, 8) --Mantle Light
elseif (current > adult_time) and (current < bed_time) then
luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”, “SetTarget”, {newTargetValue = “0”}, 5) --floor lamp
luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”, “SetTarget”, {newTargetValue = “0”}, 7) --table lamp
luup.call_action(“urn:upnp-org:serviceId:Dimming1”, “SetLoadLevelTarget”, {newLoadlevelTarget = “0”}, 65) --Ceiling Light
luup.call_action(“urn:upnp-org:serviceId:Dimming1”, “SetLoadLevelTarget”, {newLoadlevelTarget = “0”}, 8) --Mantle Light
elseif (current > night_time) or (current < morning) then
luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”, “SetTarget”, {newTargetValue = “0”}, 5) --floor lamp
luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”, “SetTarget”, {newTargetValue = “0”}, 7) --table lamp
luup.call_action(“urn:upnp-org:serviceId:Dimming1”, “SetLoadLevelTarget”, {newLoadlevelTarget = “0”}, 65) --Ceiling Light
luup.call_action(“urn:upnp-org:serviceId:Dimming1”, “SetLoadLevelTarget”, {newLoadlevelTarget = “0”}, 8) --Mantle Light
elseif (current > morning_ready) and (current < morning_ready_end) then
luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”, “SetTarget”, {newTargetValue = “0”}, 5) --floor lamp
luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”, “SetTarget”, {newTargetValue = “0”}, 7) --table lamp
luup.call_action(“urn:upnp-org:serviceId:Dimming1”, “SetLoadLevelTarget”, {newLoadlevelTarget = “0”}, 65) --Ceiling Light
luup.call_action(“urn:upnp-org:serviceId:Dimming1”, “SetLoadLevelTarget”, {newLoadlevelTarget = “0”}, 8) --Mantle Light
else
return false
end
else
luup.call_delay (“checkLastTrip”, 60) – Check when the sensor was last tripped every seconds.
end
else
luup.log("Tripped and not equal - " … "trippedtime: " … trippedtime … " lastTrip: " … lastTrip)
luup.call_delay (“checkLastTrip”,15)
end
end
luup.call_delay (“checkLastTrip”, 10)
return true[/code]
root@MiOS_35008018:/tmp/log/cmh# tail -f /var/log/cmh/LuaUPnP.log | grep equal
50 05/10/13 8:31:00.100 luup_log:0: Tripped and not equal - trippedtime: 1368192452 lastTrip: 1368192650 <0x2d2fd680>
50 05/10/13 8:31:15.100 luup_log:0: Tripped and not equal - trippedtime: 1368192452 lastTrip: 1368192650 <0x2d2fd680>
50 05/10/13 8:31:30.100 luup_log:0: Tripped and not equal - trippedtime: 1368192452 lastTrip: 1368192650 <0x2d2fd680>
50 05/10/13 8:31:45.100 luup_log:0: Tripped and not equal - trippedtime: 1368192452 lastTrip: 1368192650 <0x2d2fd680>
50 05/10/13 8:32:00.100 luup_log:0: Tripped and not equal - trippedtime: 1368192452 lastTrip: 1368192650 <0x2d2fd680>
50 05/10/13 8:32:15.008 luup_log:0: Tripped and not equal - trippedtime: 1368192452 lastTrip: 1368192650 <0x2d2fd680>
50 05/10/13 8:32:30.100 luup_log:0: Tripped and not equal - trippedtime: 1368192452 lastTrip: 1368192650 <0x2d2fd680>
50 05/10/13 8:32:45.100 luup_log:0: Tripped and not equal - trippedtime: 1368192452 lastTrip: 1368192650 <0x2d2fd680>
50 05/10/13 8:33:00.100 luup_log:0: Tripped and not equal - trippedtime: 1368192452 lastTrip: 1368192650 <0x2d2fd680>
50 05/10/13 8:33:15.100 luup_log:0: Tripped and not equal - trippedtime: 1368192452 lastTrip: 1368192650 <0x2d2fd680>
50 05/10/13 8:33:30.100 luup_log:0: Tripped and not equal - trippedtime: 1368192452 lastTrip: 1368192650 <0x2d2fd680>
50 05/10/13 8:33:45.100 luup_log:0: Tripped and not equal - trippedtime: 1368192452 lastTrip: 1368192650 <0x2d2fd680>
50 05/10/13 8:34:00.100 luup_log:0: Tripped and not equal - trippedtime: 1368192452 lastTrip: 1368192650 <0x2d2fd680>
50 05/10/13 8:34:15.101 luup_log:0: Tripped and not equal - trippedtime: 1368192452 lastTrip: 1368192650 <0x2d2fd680>
50 05/10/13 8:34:30.100 luup_log:0: Tripped and not equal - trippedtime: 1368192452 lastTrip: 1368192650 <0x2d2fd680>
50 05/10/13 8:34:45.008 luup_log:0: Tripped and not equal - trippedtime: 1368192452 lastTrip: 1368192650 <0x2d2fd680>
50 05/10/13 8:35:00.100 luup_log:0: Tripped and not equal - trippedtime: 1368192452 lastTrip: 1368192650 <0x2d2fd680>
50 05/10/13 8:35:15.100 luup_log:0: Tripped and not equal - trippedtime: 1368192452 lastTrip: 1368192650 <0x2d2fd680>
50 05/10/13 8:35:30.100 luup_log:0: Tripped and not equal - trippedtime: 1368192452 lastTrip: 1368192650 <0x2d2fd680>
50 05/10/13 8:35:45.008 luup_log:0: Tripped and not equal - trippedtime: 1368192452 lastTrip: 1368192650 <0x2d2fd680>
50 05/10/13 8:36:00.100 luup_log:0: Tripped and not equal - trippedtime: 1368192452 lastTrip: 1368192650 <0x2d2fd680>
50 05/10/13 8:36:15.100 luup_log:0: Tripped and not equal - trippedtime: 1368192452 lastTrip: 1368192650 <0x2d2fd680>
50 05/10/13 8:36:30.100 luup_log:0: Tripped and not equal - trippedtime: 1368192452 lastTrip: 1368192650 <0x2d2fd680>
50 05/10/13 8:36:45.100 luup_log:0: Tripped and not equal - trippedtime: 1368192452 lastTrip: 1368192650 <0x2d2fd680>
50 05/10/13 8:37:00.100 luup_log:0: Tripped and not equal - trippedtime: 1368192452 lastTrip: 1368192650 <0x2d2fd680>
50 05/10/13 8:37:15.008 luup_log:0: Tripped and not equal - trippedtime: 1368192452 lastTrip: 1368192650 <0x2d2fd680>
50 05/10/13 8:37:30.100 luup_log:0: Tripped and not equal - trippedtime: 1368192452 lastTrip: 1368192650 <0x2d2fd680>
50 05/10/13 8:37:45.100 luup_log:0: Tripped and not equal - trippedtime: 1368192452 lastTrip: 1368192650 <0x2d2fd680>
50 05/10/13 8:38:00.100 luup_log:0: Tripped and not equal - trippedtime: 1368192452 lastTrip: 1368192650 <0x2d2fd680>
50 05/10/13 8:38:15.008 luup_log:0: Tripped and not equal - trippedtime: 1368192452 lastTrip: 1368192650 <0x2d2fd680>
50 05/10/13 8:38:30.008 luup_log:0: Tripped and not equal - trippedtime: 1368192452 lastTrip: 1368192650 <0x2d2fd680>
50 05/10/13 8:38:45.008 luup_log:0: Tripped and not equal - trippedtime: 1368192452 lastTrip: 1368192650 <0x2d2fd680>
50 05/10/13 8:39:00.100 luup_log:0: Tripped and not equal - trippedtime: 1368192452 lastTrip: 1368192650 <0x2d2fd680>
50 05/10/13 8:39:15.100 luup_log:0: Tripped and not equal - trippedtime: 1368192452 lastTrip: 1368192650 <0x2d2fd680>
50 05/10/13 8:39:30.008 luup_log:0: Tripped and not equal - trippedtime: 1368192452 lastTrip: 1368192650 <0x2d2fd680>
50 05/10/13 8:39:45.008 luup_log:0: Tripped and not equal - trippedtime: 1368192452 lastTrip: 1368192650 <0x2d2fd680>
50 05/10/13 8:40:00.100 luup_log:0: Tripped and not equal - trippedtime: 1368192452 lastTrip: 1368193185 <0x2d2fd680>
50 05/10/13 8:40:15.100 luup_log:0: Tripped and not equal - trippedtime: 1368192452 lastTrip: 1368193185 <0x2d2fd680>
50 05/10/13 8:40:30.100 luup_log:0: Tripped and not equal - trippedtime: 1368192452 lastTrip: 1368193185 <0x2d2fd680>
50 05/10/13 8:40:45.100 luup_log:0: Tripped and not equal - trippedtime: 1368192452 lastTrip: 1368193185 <0x2d2fd680>
50 05/10/13 8:41:00.100 luup_log:0: Tripped and not equal - trippedtime: 1368192452 lastTrip: 1368193185 <0x2d2fd680>
50 05/10/13 8:41:15.100 luup_log:0: Tripped and not equal - trippedtime: 1368192452 lastTrip: 1368193185 <0x2d2fd680>
50 05/10/13 8:41:30.100 luup_log:0: Tripped and not equal - trippedtime: 1368192452 lastTrip: 1368193185 <0x2d2fd680>
50 05/10/13 8:41:45.100 luup_log:0: Tripped and not equal - trippedtime: 1368192452 lastTrip: 1368193185 <0x2d2fd680>
50 05/10/13 8:42:00.008 luup_log:0: Tripped and not equal - trippedtime: 1368192452 lastTrip: 1368193185 <0x2d2fd680>
50 05/10/13 8:42:15.008 luup_log:0: Tripped and not equal - trippedtime: 1368192452 lastTrip: 1368193185 __LEAK__ this:245760 start:794624 to 0x1381000 <0x2d2fd680>
50 05/10/13 8:42:30.008 luup_log:0: Tripped and not equal - trippedtime: 1368192452 lastTrip: 1368193185 <0x2d2fd680>
50 05/10/13 8:42:45.100 luup_log:0: Tripped and not equal - trippedtime: 1368192452 lastTrip: 1368193185 <0x2d2fd680>
50 05/10/13 8:43:00.100 luup_log:0: Tripped and not equal - trippedtime: 1368193185 lastTrip: 1368193375 <0x2d2fd680>
50 05/10/13 8:43:05.008 luup_log:0: Tripped and not equal - trippedtime: 1368193185 lastTrip: 1368193375 <0x2d2fd680>
50 05/10/13 8:43:15.100 luup_log:0: Tripped and not equal - trippedtime: 1368193185 lastTrip: 1368193375 <0x2d2fd680>
50 05/10/13 8:43:20.009 luup_log:0: Tripped and not equal - trippedtime: 1368193185 lastTrip: 1368193375 <0x2d2fd680>
50 05/10/13 8:43:30.100 luup_log:0: Tripped and not equal - trippedtime: 1368193185 lastTrip: 1368193375 <0x2d2fd680>
50 05/10/13 8:43:35.100 luup_log:0: Tripped and not equal - trippedtime: 1368193185 lastTrip: 1368193375 <0x2d2fd680>
50 05/10/13 8:43:45.100 luup_log:0: Tripped and not equal - trippedtime: 1368193185 lastTrip: 1368193375 <0x2d2fd680>
50 05/10/13 8:43:50.100 luup_log:0: Tripped and not equal - trippedtime: 1368193185 lastTrip: 1368193375 <0x2d2fd680>
50 05/10/13 8:44:00.100 luup_log:0: Tripped and not equal - trippedtime: 1368193185 lastTrip: 1368193375 <0x2d2fd680>
50 05/10/13 8:44:05.100 luup_log:0: Tripped and not equal - trippedtime: 1368193185 lastTrip: 1368193375 <0x2d2fd680>
50 05/10/13 8:44:15.101 luup_log:0: Tripped and not equal - trippedtime: 1368193185 lastTrip: 1368193375 <0x2d2fd680>
50 05/10/13 8:44:20.101 luup_log:0: Tripped and not equal - trippedtime: 1368193185 lastTrip: 1368193375 <0x2d2fd680>
50 05/10/13 8:44:30.100 luup_log:0: Tripped and not equal - trippedtime: 1368193185 lastTrip: 1368193375 <0x2d2fd680>
50 05/10/13 8:44:35.008 luup_log:0: Tripped and not equal - trippedtime: 1368193185 lastTrip: 1368193375 <0x2d2fd680>
50 05/10/13 8:44:45.100 luup_log:0: Tripped and not equal - trippedtime: 1368193185 lastTrip: 1368193375 <0x2d2fd680>
50 05/10/13 8:44:50.008 luup_log:0: Tripped and not equal - trippedtime: 1368193185 lastTrip: 1368193375 <0x2d2fd680>
50 05/10/13 8:45:00.100 luup_log:0: Tripped and not equal - trippedtime: 1368193185 lastTrip: 1368193375 <0x2d2fd680>
50 05/10/13 8:45:05.101 luup_log:0: Tripped and not equal - trippedtime: 1368193185 lastTrip: 1368193375 <0x2d2fd680>
50 05/10/13 8:45:15.100 luup_log:0: Tripped and not equal - trippedtime: 1368193185 lastTrip: 1368193375 <0x2d2fd680>
50 05/10/13 8:45:20.008 luup_log:0: Tripped and not equal - trippedtime: 1368193185 lastTrip: 1368193375 <0x2d2fd680>
50 05/10/13 8:45:30.100 luup_log:0: Tripped and not equal - trippedtime: 1368193185 lastTrip: 1368193375 <0x2d2fd680>
50 05/10/13 8:45:35.008 luup_log:0: Tripped and not equal - trippedtime: 1368193185 lastTrip: 1368193375 <0x2d2fd680>
50 05/10/13 8:45:45.008 luup_log:0: Tripped and not equal - trippedtime: 1368193185 lastTrip: 1368193375 <0x2d2fd680>
50 05/10/13 8:45:50.008 luup_log:0: Tripped and not equal - trippedtime: 1368193185 lastTrip: 1368193375 <0x2d2fd680>
50 05/10/13 8:46:00.101 luup_log:0: Tripped and not equal - trippedtime: 1368193185 lastTrip: 1368193375 <0x2d2fd680>
50 05/10/13 8:46:05.100 luup_log:0: Tripped and not equal - trippedtime: 1368193185 lastTrip: 1368193375 <0x2d2fd680>
50 05/10/13 8:46:15.101 luup_log:0: Tripped and not equal - trippedtime: 1368193185 lastTrip: 1368193375 <0x2d2fd680>
50 05/10/13 8:46:20.100 luup_log:0: Tripped and not equal - trippedtime: 1368193185 lastTrip: 1368193375 <0x2d2fd680>
50 05/10/13 8:46:30.100 luup_log:0: Tripped and not equal - trippedtime: 1368193185 lastTrip: 1368193375 <0x2d2fd680>
50 05/10/13 8:46:35.008 luup_log:0: Tripped and not equal - trippedtime: 1368193185 lastTrip: 1368193375 <0x2d2fd680>
50 05/10/13 8:46:45.100 luup_log:0: Tripped and not equal - trippedtime: 1368193185 lastTrip: 1368193375 <0x2d2fd680>
50 05/10/13 8:46:50.008 luup_log:0: Tripped and not equal - trippedtime: 1368193185 lastTrip: 1368193375 <0x2d2fd680>
50 05/10/13 8:47:00.008 luup_log:0: Tripped and not equal - trippedtime: 1368193185 lastTrip: 1368193375 <0x2d2fd680>
50 05/10/13 8:47:05.100 luup_log:0: Tripped and not equal - trippedtime: 1368193185 lastTrip: 1368193375 <0x2d2fd680>
50 05/10/13 8:47:15.008 luup_log:0: Tripped and not equal - trippedtime: 1368193185 lastTrip: 1368193375 <0x2d2fd680>
50 05/10/13 8:47:20.101 luup_log:0: Tripped and not equal - trippedtime: 1368193185 lastTrip: 1368193375 <0x2d2fd680>
50 05/10/13 8:47:30.008 luup_log:0: Tripped and not equal - trippedtime: 1368193185 lastTrip: 1368193375 <0x2d2fd680>
50 05/10/13 8:47:35.008 luup_log:0: Tripped and not equal - trippedtime: 1368193185 lastTrip: 1368193375 <0x2d2fd680>
50 05/10/13 8:47:45.100 luup_log:0: Tripped and not equal - trippedtime: 1368193185 lastTrip: 1368193375 <0x2d2fd680>
50 05/10/13 8:47:50.100 luup_log:0: Tripped and not equal - trippedtime: 1368193185 lastTrip: 1368193375 <0x2d2fd680>
50 05/10/13 8:48:00.100 luup_log:0: Tripped and not equal - trippedtime: 1368193185 lastTrip: 1368193375 <0x2d2fd680>
50 05/10/13 8:48:05.100 luup_log:0: Tripped and not equal - trippedtime: 1368193185 lastTrip: 1368193375 <0x2d2fd680>
50 05/10/13 8:48:15.008 luup_log:0: Tripped and not equal - trippedtime: 1368193185 lastTrip: 1368193375 <0x2d2fd680>
50 05/10/13 8:48:20.100 luup_log:0: Tripped and not equal - trippedtime: 1368193185 lastTrip: 1368193375 <0x2d2fd680>
50 05/10/13 8:48:30.100 luup_log:0: Tripped and not equal - trippedtime: 1368193185 lastTrip: 1368193375 <0x2d2fd680>
50 05/10/13 8:48:35.100 luup_log:0: Tripped and not equal - trippedtime: 1368193185 lastTrip: 1368193375 <0x2d2fd680>
50 05/10/13 8:48:45.100 luup_log:0: Tripped and not equal - trippedtime: 1368193185 lastTrip: 1368193375 <0x2d2fd680>
50 05/10/13 8:48:50.109 luup_log:0: Tripped and not equal - trippedtime: 1368193185 lastTrip: 1368193375 <0x2d2fd680>
50 05/10/13 8:49:00.100 luup_log:0: Tripped and not equal - trippedtime: 1368193185 lastTrip: 1368193375 <0x2d2fd680>
50 05/10/13 8:49:05.100 luup_log:0: Tripped and not equal - trippedtime: 1368193185 lastTrip: 1368193375 <0x2d2fd680>
50 05/10/13 8:49:15.008 luup_log:0: Tripped and not equal - trippedtime: 1368193185 lastTrip: 1368193375 <0x2d2fd680>
50 05/10/13 8:49:20.100 luup_log:0: Tripped and not equal - trippedtime: 1368193185 lastTrip: 1368193375 <0x2d2fd680>
50 05/10/13 8:49:30.008 luup_log:0: Tripped and not equal - trippedtime: 1368193185 lastTrip: 1368193768 <0x2d2fd680>
50 05/10/13 8:49:35.100 luup_log:0: Tripped and not equal - trippedtime: 1368193185 lastTrip: 1368193768 <0x2d2fd680>
50 05/10/13 8:49:45.100 luup_log:0: Tripped and not equal - trippedtime: 1368193185 lastTrip: 1368193768 <0x2d2fd680>
50 05/10/13 8:49:50.101 luup_log:0: Tripped and not equal - trippedtime: 1368193185 lastTrip: 1368193768 <0x2d2fd680>
50 05/10/13 8:50:00.100 luup_log:0: Tripped and not equal - trippedtime: 1368193185 lastTrip: 1368193768 <0x2d2fd680>
50 05/10/13 8:50:05.100 luup_log:0: Tripped and not equal - trippedtime: 1368193185 lastTrip: 1368193768 <0x2d2fd680>
50 05/10/13 8:50:15.100 luup_log:0: Tripped and not equal - trippedtime: 1368193185 lastTrip: 1368193768 <0x2d2fd680>
50 05/10/13 8:50:20.009 luup_log:0: Tripped and not equal - trippedtime: 1368193185 lastTrip: 1368193768 <0x2d2fd680>
50 05/10/13 8:50:30.008 luup_log:0: Tripped and not equal - trippedtime: 1368193185 lastTrip: 1368193768 <0x2d2fd680>
50 05/10/13 8:50:35.008 luup_log:0: Tripped and not equal - trippedtime: 1368193185 lastTrip: 1368193768 <0x2d2fd680>
50 05/10/13 8:50:45.101 luup_log:0: Tripped and not equal - trippedtime: 1368193185 lastTrip: 1368193768 <0x2d2fd680>
50 05/10/13 8:50:50.101 luup_log:0: Tripped and not equal - trippedtime: 1368193185 lastTrip: 1368193768 <0x2d2fd680>
50 05/10/13 8:51:00.101 luup_log:0: Tripped and not equal - trippedtime: 1368193185 lastTrip: 1368193768 <0x2d2fd680>
50 05/10/13 8:51:05.100 luup_log:0: Tripped and not equal - trippedtime: 1368193185 lastTrip: 1368193768 <0x2d2fd680>
50 05/10/13 8:51:15.100 luup_log:0: Tripped and not equal - trippedtime: 1368193185 lastTrip: 1368193768 <0x2d2fd680>
50 05/10/13 8:51:20.100 luup_log:0: Tripped and not equal - trippedtime: 1368193185 lastTrip: 1368193768 <0x2d2fd680>
50 05/10/13 8:51:30.100 luup_log:0: Tripped and not equal - trippedtime: 1368193185 lastTrip: 1368193768 <0x2d2fd680>
50 05/10/13 8:51:35.100 luup_log:0: Tripped and not equal - trippedtime: 1368193185 lastTrip: 1368193768 <0x2d2fd680>
50 05/10/13 8:51:45.100 luup_log:0: Tripped and not equal - trippedtime: 1368193185 lastTrip: 1368193768 <0x2d2fd680>
50 05/10/13 8:51:50.100 luup_log:0: Tripped and not equal - trippedtime: 1368193185 lastTrip: 1368193768 <0x2d2fd680>