Turn Thermostat off with Door Sensor- Please Help


I am using Vera Lite and would like to turn off the thermostat if a door is open for 5 minutes, and have it return to previous settting when door is closed. I have tried to create a scene to turn off hvac, and it works. I also created scene to turn it back on when door is closed. That also works. However, it only works if I open the door, leave it open for 5 minutes, then close it. But, If I open the door to go out and close it immediately, the HVAC will shut off 5 minutes after opening and wont turn back on unless door is opened and shut again. How can I set scene to only shut off if door is still open after 5 minutes, not 5 minutes after door opens?

I tried to do the following Luup scene, but it doesn’t seem to do anything. I replaced the correct sensor numbers and I am using a CT-100. Is that the problem? Any help would be greatly appreciated.

local SENSOR = 17 – The door/window sensor device number
local THERMOSTAT = 3 – The thermostat device number
local DELAY = 300 – Seconds

local SES_SID = “urn:micasaverde-com:serviceId:SecuritySensor1”
local HVACO_SID = “urn:upnp-org:serviceId:HVAC_UserOperatingMode1”

luup.call_delay( “turnOffAc”, DELAY)

– Turn off the thermostat if the sensor has been tripped for at least 5 minutes.
function turnOffAc()
local tripped = luup.variable_get( SES_SID, “Tripped”, SENSOR) or “0”
local lastTrip = luup.variable_get( SES_SID, “LastTrip”, SENSOR) or os.time()
if (tripped == “1” and (os.time() - lastTrip >= DELAY)) then
local modeStatus = luup.variable_get( HVACO_SID, “ModeStatus”, THERMOSTAT) or “Off”
luup.variable_set( HVACO_SID, “LastModeStatus”, modeStatus, THERMOSTAT)
luup.call_action( HVACO_SID, “SetModeTarget”, {NewModeTarget = “Off”}, THERMOSTAT)

luup.variable_get(…) returns a string. You must convert this to a number before you can use it for calculation or comparison. Try:

local lastTrip = tonumber((luup.variable_get( SES_SID, "LastTrip", SENSOR)))

Thanks for the reply. I figured it out by deleting the Luup and getting the countdown timer app.