From 74360b8c40d0893d8840d6fd4bdfdbfec815cbb2 Mon Sep 17 00:00:00 2001 From: Greg Thornton Date: Mon, 21 Dec 2020 05:56:32 -0600 Subject: [PATCH] Ignore motion events when night mode is switched on/off (#1648) * Ignore motion events if night mode has recently changed. * Add night mode motion delay to web ui * Change night_delay config to night_mode_event_delay --- firmware_mod/config/motion.conf.dist | 1 + firmware_mod/scripts/common_functions.sh | 2 ++ firmware_mod/scripts/detectionOn.sh | 9 +++++++++ firmware_mod/www/cgi-bin/ui_motion.cgi | 11 ++++++++--- firmware_mod/www/motion.html | 4 ++++ 5 files changed, 24 insertions(+), 3 deletions(-) diff --git a/firmware_mod/config/motion.conf.dist b/firmware_mod/config/motion.conf.dist index e1b751a..bcc93b8 100644 --- a/firmware_mod/config/motion.conf.dist +++ b/firmware_mod/config/motion.conf.dist @@ -24,6 +24,7 @@ send_email=false send_telegram=false telegram_alert_type=image send_matrix=false +night_mode_event_delay=30 # General group_date_pattern="+%Y-%m-%d/%H" diff --git a/firmware_mod/scripts/common_functions.sh b/firmware_mod/scripts/common_functions.sh index 2558c13..5c3d64f 100755 --- a/firmware_mod/scripts/common_functions.sh +++ b/firmware_mod/scripts/common_functions.sh @@ -703,6 +703,7 @@ motion_mqtt_video(){ night_mode(){ case "$1" in on) + touch /tmp/last-night /system/sdcard/bin/setconf -k n -v 1 . /system/sdcard/config/autonight.conf if [ -z "$ir_led_off" ] || [ $ir_led_off = false ]; then @@ -713,6 +714,7 @@ night_mode(){ ir_cut off ;; off) + touch /tmp/last-night ir_led off ir_cut on /system/sdcard/bin/setconf -k n -v 0 diff --git a/firmware_mod/scripts/detectionOn.sh b/firmware_mod/scripts/detectionOn.sh index 6ce197d..38265e9 100644 --- a/firmware_mod/scripts/detectionOn.sh +++ b/firmware_mod/scripts/detectionOn.sh @@ -47,6 +47,15 @@ record_video () { fi } +if [ -f /tmp/last-night -a -n "$night_mode_event_delay" -a "$night_mode_event_delay" -gt 0 ]; then + now_ts="$(date +%s)" + night_ts="$(/system/sdcard/bin/busybox stat -c %Y /tmp/last-night)" + dt="$(($now_ts-$night_ts))" + if [ "$dt" -lt "$night_mode_event_delay" ]; then + exit 0 + fi +fi + # Turn on the amber led if [ "$motion_trigger_led" = true ] ; then debug_msg "Trigger LED" diff --git a/firmware_mod/www/cgi-bin/ui_motion.cgi b/firmware_mod/www/cgi-bin/ui_motion.cgi index 37d88c1..ce25f9a 100755 --- a/firmware_mod/www/cgi-bin/ui_motion.cgi +++ b/firmware_mod/www/cgi-bin/ui_motion.cgi @@ -51,7 +51,8 @@ if [ -n "$F_cmd" ]; then echo "sendTelegram#:#${send_telegram}" echo "telegramAlertType#:#${telegram_alert_type}" echo "sendMatrix#:#${send_matrix}" - + echo "nightModeEventDelay#:#${night_mode_event_delay}" + ;; save_config) if [ -n "${F_motionDetection+x}" ]; then @@ -74,7 +75,7 @@ if [ -n "$F_cmd" ]; then echo -n "Motion color indicator set to " echo -n $(echo $color | cut -d ' ' -f $(($F_motionIndicatorColor + 1))) echo "
" - fi + fi fi if [ -n "${F_motionTracking+x}" ]; then F_motionTracking=$(printf '%b' "${F_motionTracking//%/\\x}") @@ -221,6 +222,11 @@ if [ -n "$F_cmd" ]; then rewrite_config /system/sdcard/config/motion.conf send_matrix $F_sendMatrix echo "Send Matrix on motion set to $F_sendMatrix
" fi + if [ -n "${F_nightModeEventDelay+x}" ]; then + F_nightModeEventDelay=$(printf '%b' "${F_nightModeEventDelay//%/\\x}") + rewrite_config /system/sdcard/config/motion.conf night_mode_event_delay $F_nightModeEventDelay + echo "Motion night mode delay set to $F_nightModeEventDelay
" + fi if [ -n "${F_regions+x}" ]; then F_regions=$(printf '%b' "${F_regions//%/\\x}") rewrite_config /system/sdcard/config/motion.conf region_of_interest $F_regions @@ -240,4 +246,3 @@ if [ -n "$F_cmd" ]; then fi exit 0 - diff --git a/firmware_mod/www/motion.html b/firmware_mod/www/motion.html index 7c22d19..eee661a 100755 --- a/firmware_mod/www/motion.html +++ b/firmware_mod/www/motion.html @@ -273,6 +273,10 @@ +
+ + +