last_movement2 = ts
last_movement3 = ts
}
-
- if last_movement > 0 && ts - last_movement < 3600*6 && ts - last_movement > 3600*3 {
- last_movement = 0
- ps.Pub( r3events.SomethingReallyIsMoving{false,99,ts}, "movement")
- }
- if last_movement1 > 0 && ts - last_movement < 3600*6 && ts - last_movement1 > 120 {
- last_movement1 = 0
- ps.Pub( r3events.SomethingReallyIsMoving{false,10,ts}, "movement")
- }
- if last_movement2 > 0 && ts - last_movement < 3600*6 && ts - last_movement2 > 1800 {
- last_movement2 = 0
- ps.Pub( r3events.SomethingReallyIsMoving{false,25,ts}, "movement")
- }
- if last_movement3 > 0 && ts - last_movement < 3600*6 && ts - last_movement3 > 3600 {
- last_movement3 = 0
- ps.Pub( r3events.SomethingReallyIsMoving{false,50,ts}, "movement")
+ // this sucks.....
+ if last_movement > 0 && ts - last_movement < 3600*6 {
+ if ts - last_movement > 3600*3 {
+ last_movement = 0
+ ps.Pub( r3events.SomethingReallyIsMoving{false,99,ts}, "movement")
+ } else if ts - last_movement > 3600 && last_movement3 > 0 {
+ last_movement3 = 0
+ ps.Pub( r3events.SomethingReallyIsMoving{false,50,ts}, "movement")
+ } else if ts - last_movement > 1800 && last_movement2 > 0 {
+ last_movement2 = 0
+ ps.Pub( r3events.SomethingReallyIsMoving{false,20,ts}, "movement")
+ } else if ts - last_movement > 120 && last_movement1 > 0 {
+ last_movement1 = 0
+ ps.Pub( r3events.SomethingReallyIsMoving{false,5,ts}, "movement")
+ }
}
} }
}
\ No newline at end of file
func MetaEventRoutine_Presence(ps *pubsub.PubSub, movement_timeout, button_timeout int64) {
//~ var last_door_cmd *r3events.DoorCommandEvent
var last_presence bool
- var last_movement, last_buttonpress, last_frontlock_use int64
+ var last_event_indicating_presence, last_frontlock_use int64
var front_locked, front_shut, back_shut bool = true, true, true
events_chan := ps.Sub("door", "doorcmd", "buttons", "movement")
switch evnt := event.(type) {
case r3events.SomethingReallyIsMoving:
if evnt.Movement {
- last_movement = evnt.Ts
+ //ignore movements that happened just after locking door
+ if (evnt.Ts - last_event_indicating_presence) > movement_timeout {
+ new_presence = true
+ }
+ last_event_indicating_presence = evnt.Ts
} else {
- last_movement = 0
- if last_presence { Syslog_.Print("Presence: Mhh, SomethingReallyIsMoving{false} received but presence still true. Quite still a bunch we have here.") }
+ if last_presence { Syslog_.Printf("Presence: Mhh, SomethingReallyIsMoving{%+v} received but presence still true. Quite still a bunch we have here.", evnt) }
+ if front_locked && front_shut && back_shut && evnt.Confidence >= 20 && last_event_indicating_presence > 1800 {
+ new_presence = false
+ }
}
case r3events.BoreDoomButtonPressEvent:
- last_buttonpress = evnt.Ts
new_presence = true
+ last_event_indicating_presence = evnt.Ts
case r3events.DoorCommandEvent:
//~ last_door_cmd = &evnt
case r3events.DoorLockUpdate:
front_locked = evnt.Locked
last_frontlock_use = evnt.Ts
+ last_event_indicating_presence = evnt.Ts
case r3events.DoorAjarUpdate:
if front_shut == false && evnt.Shut && front_locked && evnt.Ts - last_frontlock_use > 2 {
Syslog_.Print("Presence: ignoring frontdoor ajar event, since obviously someone is fooling around with the microswitch while the door is still open")
} else {
front_shut = evnt.Shut
}
+ last_event_indicating_presence = evnt.Ts
case r3events.BackdoorAjarUpdate:
back_shut = evnt.Shut
+ last_event_indicating_presence = evnt.Ts
}
any_door_unlocked := (front_locked == false)
//... skip state check .. we had a definite presence event
} else if any_door_unlocked || any_door_ajar {
new_presence = true
- } else if ts - last_movement < movement_timeout || ts - last_buttonpress < button_timeout {
- new_presence = true
} else {
new_presence = false
}