Hi,
I’m coming to the end of my presence detection rules and am pretty happy with the whole process but I’m getting confused on the last bit. I keep making it far to complicated and I’m sure there is an easier way…that’s where I hope you lovely people can come in…
So, my code:
rule "vMotion is ON - Intruder!"
when
Item vMotion changed
then
if(vMotion.state == ON)
{
logInfo(logName, "vMotion Alert - Double Check for Presence")
*** do some stuff to check for my / wife presence in the house and set vPresent to ON if there is
if(vPresent.state == ON) // vPresent is ON - someone is actually home
{
logInfo(logName, "vMotion Alert - Phew - Someone was actually present - nothing to do")
vMotion.sendCommand(OFF) // set vMotion OFF again as it was me / wife that set the motion sensor off
}
else
{
logInfo(logName, "vMotion Alert - INTRUDER - No one is home")
sendBroadcastNotification("vMotion Alert - INTRUDER - No one is home")
*** turn on camera to log who set of motion
logInfo(logName, "vMotion Alert - INTRUDER - Turning on cameras")
sendBroadcastNotification("vMotion Alert - INTRUDER - Turning on cameras")
}
}
else
{
logInfo(logName, "vMotion set to OFF")
sendBroadcastNotification("vMotion Alert - INTRUDER - No more motion detected after 5 minutes - vMotion OFF")
}
end
So a quick summary of the rule, I have a few motion sensors, all grouped into a vMotion group switch. When motion is detected this rule fires.
If vMotion is set to ON, it first checks to see if a family member is present, if they are it turns vMotion OFF and adds a logfile.
If we aren’t present then it takes it to the next stage where it assumes an intruder, (simple logic of no one home but there is movement so someone must be in the house), so it sends me as message and turns on the camera if they aren’t already on.
The vMotion item has an expire binding of 5 minutes, so obviously if there is no more motion it turns vMotion to OFF after 5 minutes and the final part of the else rule runs, informing me that it was a one off motion so either postman, spider, ghost, whatever but leaves the cameras on just in case, (and to be honest I’ll have checked them by then anyway).
All good, and the rule runs perfectly. The issue I have is at the moment other than turning the cameras on when first motion is detected, I have nothing to say what happens if more motion is detected within the 5 minute expire.
Ideally I’d like it to turn on another proxy variable called vAlarm from within this rule which then runs another ‘when vAlarm changes’ rule to sound the alarm, flash the lights etc. However, I am struggling to see the best way for the rule to check that more motion has been detected.
My thought is that I might need to remove the expire binding and add an ‘in rule’ timer in its place or incorporate a counter which increments for each motion and if after 5 minutes it is more than 1 set vAlarm but I’m getting into knots as to the best way to do it really.
Ideally there would be some way in the expire binding to pull out how many timer resets the 5m expire timer has had but I don’t think that is possible…
Any ideas gratefully welcomed!