Trapped In Venus Box Algorithm
1. Assume there is no prey in the Venus box.
2. Have you heard a prey flying/moving outside of the Venus box, near to leaf trap of the Venus box?
YES = Venus opens leaf trap, waiting for the prey to go in the Venus box.
NO = Venus keeps waiting for the next prey
3. Have you still heard the prey moving in the Venus box 10 seconds after the leaf trap was opened?
YES = Venus snaps the leaf trap. The prey is snap-trapped in the Venus box until you are told otherwise.
NO = The prey did not go in the Venus box or it went in and came out too fast, faster than 10 seconds lack of response that helps to prevent false alarms. Venus will ignore this prey and keep waiting for the next prey.
4. Have you heard the prey flying/moving outside of the Venus box, near to leaf trap of the Venus box after it has been snap-trapped in the Venus box?
YES = The Venus leaf trap was forced to open by the prey, the prey probably escaped.
NO = The prey is still snap-trapped in the Venus box.
To implement Trapped In Venus Box Algorithm, we need to be able to detect movement inside and movement outside of a room. I already have 2 motion sensors inside kitchen room, I need another motion sensor outside of kitchen room.
Luckily, I no need to buy another motion sensor, I already have 2 motion sensors inside dinning room. I can use one of dinning room’s motion sensors to detect movement outside of kitchen room. That dinning room’s motion sensor will be used as dual purpose motion sensor: monitor movement inside dinning room and monitor movement outside kitchen room.
Here is Vera Smart Home implementation of Trapped In Venus Box Algorithm for my kitchen room.
- Modify lua start up add following:
TrapInVenusBox = 0
LastVenusOpen = os.time()
VenusLackOfResponseDelay = 10 – 10 seconds is detection interval default setting of my dinning room’s motion sensor. Detection interval or re-trigger interval or blind time of a motion sensor is the interval of being re-triggered after the PIR detector has been triggered. No report will be sent during this interval if a movement is presented. i.e PIR sensor will be “blind” (insensitive) to motion after last detection for the amount of time specified in this parameter setting. Set this interval to shorter time periods allow to detect motion more frequently, but the battery will be drained faster.
lua start up
SS_SID = “urn:micasaverde-com:serviceId:SecuritySensor1”
SP_SID = “urn:upnp-org:serviceId:SwitchPower1”
HumanInKitchen = 0
LastTripInKitchen = os.time()
HumanInDinning = 0
LastTripInDinning = os.time()
PeakHourTimeout = 600 – 10 minutes
NonPeakHourTimeout = 180 – 3 minutes
TrapInVenusBox = 0
LastVenusOpen = os.time()
VenusLackOfResponseDelay = 10
KitchenLight = 186
KitchenNeoMotionSensor = 152
KitchenFibaroMotionSensor = 158
DinningLight = 82
DinningNeoMotionSensor = 140 – this is dual purpose motion sensor that monitor movement inside dinning room and movement outside kitchen room
DinningFibaroMotionSensor = 69
function getStatus(devID)
local devStatus = luup.variable_get(SP_SID, “Status”, devID)
return devStatus
end
function isOn(devID)
local devStatus = luup.variable_get(SP_SID, “Status”, devID)
if (devStatus == “1”) then
return true
else
return false
end
end
function isOff(devID)
local devStatus = luup.variable_get(SP_SID, “Status”, devID)
if (devStatus == “0”) then
return true
else
return false
end
end
function getTrip(devID)
local devStatus = luup.variable_get(SS_SID, “Tripped”, devID)
return devStatus
end
function isTrip(devID)
local devStatus = luup.variable_get(SS_SID, “Tripped”, devID)
if (devStatus == “1”) then
return true
else
return false
end
end
function isNotTrip(devID)
local devStatus = luup.variable_get(SS_SID, “Tripped”, devID)
if (devStatus == “0”) then
return true
else
return false
end
end
function turnOnLight(devID)
local lightStatus = luup.variable_get(SP_SID, “Status”, devID)
if (lightStatus == “0”) then
luup.call_action (SP_SID, “SetTarget”, {[“newTargetValue”] = 1}, devID)
end
end
function turnOffLight(devID)
local lightStatus = luup.variable_get(SP_SID, “Status”, devID)
if (lightStatus == “1”) then
luup.call_action (SP_SID, “SetTarget”, {[“newTargetValue”] = 0}, devID)
end
end
function breakfasttime()
local t = os.date(‘*t’)
if (6 <= t.hour and t.hour < 9) then
return true
else
return false
end
end
function morningtime()
local t = os.date(‘*t’)
if (9 <= t.hour and t.hour < 11) then
return true
else
return false
end
end
function lunchtime()
local t = os.date(‘*t’)
if (11 <= t.hour and t.hour < 13) then
return true
else
return false
end
end
function afternoontime()
local t = os.date(‘*t’)
if (13 <= t.hour and t.hour < 17) then
return true
else
return false
end
end
function dinnertime()
local t = os.date(‘*t’)
if (17 <= t.hour and t.hour < 19) then
return true
else
return false
end
end
function eveningtime()
local t = os.date(‘*t’)
if (19 <= t.hour and t.hour < 23) then
return true
else
return false
end
end
function sleepingtime()
local t = os.date(‘*t’)
if (23 <= t.hour or t.hour < 6) then
return true
else
return false
end
end
function cookingtime()
local t = os.date(‘*t’)
if (16 <= t.hour and t.hour < 19) then
return true
else
return false
end
end
-
Create new scene name VenusOpen. This scene will be triggered by DinningNeoMotionSensor tripped event. In lua code of this scene, put following:
if TrapInVenusBox == 0 then
–log(“A prey is flying outside of the Venus box, open Venus leaf trap and wait for the prey to go inside”)
TrapInVenusBox = 0
else
–log(“Venus leaf trap was forced to open by the prey, the prey probably escaped”)
TrapInVenusBox = 0
end
LastVenusOpen = os.time()
-
Modify scene SomebodyInKitchen as below:
if os.difftime(os.time(), LastVenusOpen) > VenusLackOfResponseDelay then
– log(“The prey is moving in the Venus box " … VenusLackOfResponseDelay … " seconds after Venus leaf trap was opened, close Venus leaf trap”)
TrapInVenusBox = 1
end
LastTripInKitchen = os.time()
HumanInKitchen = 1
–log(“Detected movement in kitchen room, turn on kitchen light”)
turnOnLight(KitchenLight)
-
Mofify scene NobodyInKitchen as below:
function CheckHumanInKitchenStatus()
if TrapInVenusBox == 1 then
– log(“Venus leaf trap is closed, the prey is in Venus box, do not turn off light”)
return true
end
if cookingtime() then
if HumanInKitchen == 1 or os.difftime(os.time(), LastTripInKitchen) < PeakHourTimeout then
– log(“Movement in kitchen room before delay " … PeakHourTimeout … " seconds, do not turn off light”)
return true
end
else
if HumanInKitchen == 1 or os.difftime(os.time(), LastTripInKitchen) < NonPeakHourTimeout then
– log(“Movement in kitchen room before delay " … NonPeakHourTimeout … " seconds, do not turn off light”)
return true
end
end
– log(“No movement in kitchen room after delay Peak/NonPeakHourTimeout, turn off light”)
turnOffLight(KitchenLight)
end
LastTripInKitchen = os.time()
– log(“Detected no movement in kitchen room, check all sensors”)
if isNotTrip(KitchenFibaroMotionSensor) and isNotTrip(KitchenNeoMotionSensor) then
– log(“All sensors are not tripped. Turn off HumanInKitchen indicator and call delay Peak/NonPeakHourTimeout seconds to turn off kitchen light”)
HumanInKitchen = 0
if cookingtime() then
luup.call_delay (“CheckHumanInKitchenStatus”, PeakHourTimeout)
else
luup.call_delay (“CheckHumanInKitchenStatus”, NonPeakHourTimeout)
end
end
If you want to see how the algorithm works, you can create 3 virtual switches for HumanInDinning, HumanInKitchen and TrapInVenusBox indicators to see how these indicators turn on and off on Vera dashboard in real time.