Clever door sensor at toilet

Good day Sirs.
I want to make following:
The door at toilet is always closed. If someone wants to go to the toilet, he opens the door (the door sensor is triped) and the lights on, he entered to the toilet closed the door and the light is still on). Then he has finished his deals, he wants to leave the toilet - opens the door and the light is off. Sometimes may happen, if someone opened the toilet door by mistake and left it opened - the light will remain ON. How can I automatically switch it off for example after 10 minutes if the door is opened.
To resolve this situation, I’ve created to scenes:

  1. “Turning the lights on”. The start value of sensor is Bypassed. the trigger is set if the device is tripped, than turn On the light and set the sensor status in 5 seconds to Armed. The LUUP code is following:

local lul_tmp = luup.variable_get(“urn:micasaverde-com:serviceId:SecuritySensor1”, “Armed”, 46)
if (lul_tmp == “1”) then
return false
end

  1. “Turning the lights off”. The start value of sensor is Bypassed. the trigger is set if the device is tripped, that turn Off the light and set the sensor status in 5 seconds to Bypass. The LUUP code is following:

local lul_tmp = luup.variable_get(“urn:micasaverde-com:serviceId:SecuritySensor1”, “Armed”, 46)
if (lul_tmp == “0”) then
return false
end

This procedure is working very good. But I can’t understand how to set the scene, if someon will leave door opened, the system will shut down the light automatically in 10 minutes.

Please advice your ideas.
Thanks in advance.

Download the countdown timer plugin.

Set timer duration to 10 minutes

In your existing scene to turn on light add the action to “restart” timer unmuted when door is open.

add second scene to mute timer when door is closed.

Set third scene to shut lights off when timer finishes and is UNmuted.

This way it will shut the lights off if the door is left open after 10 minutes.

There may be a better way, and you can find more examples in the count down tuner thread I believe. Hope it helps!