Skip to content

Commit

Permalink
Ignore motion events when night mode is switched on/off (EliasKotlyar…
Browse files Browse the repository at this point in the history
…#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
  • Loading branch information
xdissent authored Dec 21, 2020
1 parent 6a13b28 commit 74360b8
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 3 deletions.
1 change: 1 addition & 0 deletions firmware_mod/config/motion.conf.dist
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 2 additions & 0 deletions firmware_mod/scripts/common_functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
9 changes: 9 additions & 0 deletions firmware_mod/scripts/detectionOn.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
11 changes: 8 additions & 3 deletions firmware_mod/www/cgi-bin/ui_motion.cgi
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 "<br />"
fi
fi
fi
if [ -n "${F_motionTracking+x}" ]; then
F_motionTracking=$(printf '%b' "${F_motionTracking//%/\\x}")
Expand Down Expand Up @@ -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<br/>"
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<br/>"
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
Expand All @@ -240,4 +246,3 @@ if [ -n "$F_cmd" ]; then
fi

exit 0

4 changes: 4 additions & 0 deletions firmware_mod/www/motion.html
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,10 @@ <h1 class="is-size-4">Motion Settings</h1>
<option value="true">Activate</option>
</select>
</div>
<div class="w3-container">
<label>Night mode delay (ignore motion events after switching night mode)</label>
<input class="w3-input" id="nightModeEventDelay" type="number" size="6">
</div>
<p><button class="w3-btn w3-theme" >Save</button></form></p>
</div>
<!-- Zones Tab -->
Expand Down

0 comments on commit 74360b8

Please sign in to comment.