From 4d81a0859711fbf1ce97f70a1f35bb72ce5ca1e5 Mon Sep 17 00:00:00 2001 From: Nick Mowen Date: Thu, 12 May 2022 16:21:28 -0600 Subject: [PATCH] Make sure multiple True values aren't published for the same motion --- frigate/object_processing.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/frigate/object_processing.py b/frigate/object_processing.py index 7698a058b..29f38d72a 100644 --- a/frigate/object_processing.py +++ b/frigate/object_processing.py @@ -848,11 +848,15 @@ class TrackedObjectProcessor(threading.Thread): def should_mqtt_motion(self, camera, motion_boxes): # publish if motion is currently being detected if motion_boxes: - self.client.publish( - f"{self.topic_prefix}/{camera}/motion/detected", - True, - retain=False, - ) + # only send True if motion hasn't been detected recently + if self.last_motion_updates[camera] == 0: + self.client.publish( + f"{self.topic_prefix}/{camera}/motion/detected", + True, + retain=False, + ) + + # always updated latest motion self.last_motion_updates[camera] = int(time.time()) elif not motion_boxes and self.last_motion_updates.get(camera, 0) != 0: mqtt_delay = self.config.cameras[camera].motion.mqtt_off_delay