So after a month I’ve captured some minor corner cases and as well splitted one rule to two (as in one it sometimes happened that one part used older data from postupdate)
so actual and 99.9% accurate solution is this (0.1% is when somebody is sleeping eg. not moving and somebody else triggers doors)
/* motion detectors activity */
rule "Motion activity"
when
Member of gMotion received update
then
var now = new DateTimeType()
postUpdate(triggeringItem.name+"_t", now.toString)
postUpdate(gMotion_t, now)
// global 15min coundown reset (expire binding)
holderPresenceMotion.sendCommand(ON)
end
rule "Presense detection / somebody home"
when
//Item gMotion changed to ON or
Member of gMotion changed to ON
then
// set doors helper to OFF because there is a movement
if(holderPresenceDoors.state != OFF){
holderPresenceDoors.sendCommand(OFF)
logInfo(logName, "Doors => helper OFF")
}
// set global presense to ON (somebody is home)
if(holderPresence.state != ON){
holderPresence.sendCommand(ON)
logInfo(logName, "Motion => somebody home")
}
end
rule "Presence detection / nobody home"
when
Item holderPresenceMotion changed to OFF
then
// 15min helper expired and doors helper is not OFF?, assume nobody home, set presence helper to OFF
if(holderPresenceDoors.state == ON){
holderPresence.sendCommand(OFF)
logInfo(logName, "15min + Doors => empty house")
}
end
rule "Presence detection / Doors in-out"
when
Member of gContactsDoors received update
then
// set in-out helper to ON as doors have been oppened/closed
if(holderPresenceDoors.state != ON){
holderPresenceDoors.sendCommand(ON)
logInfo(logName, "Doors => helper ON")
}
end
some relevant items
Switch holderPresenceMotion "Motion sensors [MAP(motion.map):%s]" <motion> (gPresence) { expire="15m,command=OFF" }
Switch holderPresenceDoors
Switch holderPresence "Is anybody home? [MAP(presense.map):%s]" <motion> (gPresence)
Group:Switch:OR(ON, OFF) gPresence "Presence [(%d)]"
Group:Switch:OR(ON, OFF) gMotion "Motion [(%d)]" <motion>
Group:Contact:OR(OPEN, CLOSED) gContacts "Doors & Windows [(%d)]" <contact>
Group:Contact:OR(OPEN, CLOSED) gContactsDoors
and as sensors
I have currently 6 PIR sensors (AM312) and indeed Contacts on entrance doors.
All PIRs have 2min cooldown, in which another movement retriggers 2min grace period.
Then I’m using one 15min expire binding holderMotion to be sure there is enough time after no movement to safely say there is nobody home when doors have been triggered.
Currently I’m not combining these informations with anything else like Kodi or mobiles or something else, as in my setup this is accurate in basically any normal life situation happening at my house.
What I’m using it for? mainly for turning down heating - so I don’t need to have programmed timespans when it should maintain temperatures, simply when somebody is home heating is set to comfort level, otherwise powersafe. Then I’m using it for some additional ambilighting here and there as well as garden lights/pond etc.
Might or might not help somebody.
It’s quite simple yet very precise solution of presence detection
(and it’s not using any timestamp at all - as I originaly wanted to avoid them )
Cheers