Skip to content

Add object detection, tracking, mobile notifications, and search to any security camera.

notif checkbox

roryclearfe574b627fec
diff --git a/clearcam.py b/clearcam.py
index 6cb76d9..4bf454b 100644
--- a/clearcam.py
+++ b/clearcam.py
@@ -357,6 +357,7 @@ class RollingClassCounter:
self.sched = sched
self.cam_name = cam_name
self.is_on = True
+ self.is_notif = True
def add(self, class_id):
if self.classes is not None and class_id not in self.classes: return
@@ -604,7 +605,7 @@ class VideoCapture:
if not alert.is_active(offset=4): alert.last_det = time.time() # don't send alert when just active
if alert.get_counts()[1]:
if time.time() - alert.last_det >= alert.window:
- send_det = True
+ if alert.is_notif: send_det = True
timestamp = datetime.now().strftime("%Y-%m-%d")
filepath = CAMERA_BASE_DIR / f"{self.cam_name}/event_images/{timestamp}"
filepath.mkdir(parents=True, exist_ok=True)
@@ -612,7 +613,7 @@ class VideoCapture:
self.annotated_frame = self.draw_predictions(frame.copy(), filtered_preds)
cv2.imwrite(str(filename), self.annotated_frame, [cv2.IMWRITE_JPEG_QUALITY, 85]) # we've 10MB limit for video file, raw png is 3MB!
text = f"Event Detected ({getattr(alert, 'cam_name')})" if getattr(alert, 'cam_name', None) else None
- if userID is not None: threading.Thread(target=send_notif, args=(userID,text,), daemon=True).start()
+ if userID is not None and alert.is_notif: threading.Thread(target=send_notif, args=(userID,text,), daemon=True).start()
last_det = time.time()
alert.last_det = time.time()
if (send_det and userID is not None) and time.time() - last_det >= 6: #send 15ish second clip after
@@ -1053,10 +1054,12 @@ class HLSRequestHandler(BaseHTTPRequestHandler):
if zone is None: zone = {}
outside = query.get("outside", [None])[0]
is_on = query.get("is_on", [None])[0]
+ is_notif = query.get("is_notif", [None])[0]
show_dets = query.get("show_dets", [self.show_dets])[0]
if show_dets is not None: self.show_dets = str(int(time.time())) # 2 mins
threshold = query.get("threshold", [None])[0] #default 0.5?
if is_on is not None: is_on = str(is_on).lower() == "true"
+ if is_notif is not None: is_notif = str(is_notif).lower() == "true"
if outside is not None: outside = str(outside).lower() == "true"
coords_json = query.get("coords", [None])[0]
@@ -1068,6 +1071,7 @@ class HLSRequestHandler(BaseHTTPRequestHandler):
w = query.get("w", [None])[0]
h = query.get("h", [None])[0]
if is_on is not None: zone["is_on"] = is_on
+ if is_notif is not None: zone["is_notif"] = is_notif
if outside is not None: zone["outside"] = outside
if threshold is not None: zone["threshold"] = float(threshold)
if self.show_dets is not None: zone["show_dets"] = self.show_dets
@@ -1090,6 +1094,7 @@ class HLSRequestHandler(BaseHTTPRequestHandler):
alert = None
alert_id = query.get("id", [None])[0]
is_on = query.get("is_on", [None])[0]
+ is_notif = query.get("is_notif", [None])[0]
if alert_id is None: # no id, add alert
window = query.get("window", [None])[0]
max_count = query.get("max", [None])[0]
@@ -1112,7 +1117,11 @@ class HLSRequestHandler(BaseHTTPRequestHandler):
is_on = str(is_on).lower() == "true"
raw_alerts[alert_id].is_on = is_on
alert = raw_alerts[alert_id]
- else:
+ if is_notif is not None:
+ is_notif = str(is_notif).lower() == "true"
+ raw_alerts[alert_id].is_notif = is_notif
+ alert = raw_alerts[alert_id]
+ if is_on is None and is_notif is None:
del raw_alerts[alert_id]
with open(alerts_file, 'wb') as f: pickle.dump(raw_alerts, f)
added_alerts_file = CAMERA_BASE_DIR / cam_name / "added_alerts.pkl"
@@ -1161,6 +1170,7 @@ class HLSRequestHandler(BaseHTTPRequestHandler):
"id": str(key),
"sched": sched,
"is_on": alert.is_on,
+ "is_notif": alert.is_notif,
})
except Exception as e:
self.send_error(500, f"Failed to load alerts: {e}")
diff --git a/mainview.html b/mainview.html
index c18bf43..f4c7dd1 100644
--- a/mainview.html
+++ b/mainview.html
@@ -88,6 +88,7 @@
text-align: left;
border-bottom: 2px solid #dee2e6;
font-weight: 600;
+ white-space: nowrap;
}
.camera-card .icon {
@@ -99,6 +100,7 @@
padding: 8px;
border-bottom: 1px solid #dee2e6;
vertical-align: middle;
+ white-space: nowrap;
}
#alertsContainer button {
@@ -1078,6 +1080,7 @@
<th style="text-align:left; padding:6px; border-bottom:1px solid #ccc;">Window</th>
<th style="text-align:left; padding:6px; border-bottom:1px solid #ccc;">Schedule</th>
<th style="text-align:center; padding:6px; border-bottom:1px solid #ccc;">Enabled</th>
+ <th style="text-align:center; padding:6px; border-bottom:1px solid #ccc;">Send Alerts</th>
<th style="text-align:center; padding:6px; border-bottom:1px solid #ccc;">Actions</th>
</tr>
</thead><tbody>`;
@@ -1111,7 +1114,9 @@
}
const isOn = alert.hasOwnProperty("is_on") ? alert.is_on : true;
+ const isNotif = alert.hasOwnProperty("is_notif") ? alert.is_notif : true;
const checkedAttr = isOn ? "checked" : "";
+ const notifCheckedAttr = isNotif ? "checked" : "";
html += `<tr>
<td style="padding:6px; border-bottom:1px solid #eee; text-align:center;">${alert.max}</td>
@@ -1120,7 +1125,12 @@
<td style="padding:6px; border-bottom:1px solid #eee;">${scheduleStr}</td>
<td style="padding:6px; border-bottom:1px solid #eee; text-align:center;">
<input type="checkbox" data-alert-id="${alert.id}" ${checkedAttr}
- onchange="toggleAlert('${alert.id}', this.checked)"
+ onchange="toggleAlert('${alert.id}', this.checked, 'is_on')"
+ style="transform:scale(1.2); cursor:pointer;">
+ </td>
+ <td style="padding:6px; border-bottom:1px solid #eee; text-align:center;">
+ <input type="checkbox" data-alert-id="${alert.id}" ${notifCheckedAttr}
+ onchange="toggleAlert('${alert.id}', this.checked, 'is_notif')"
style="transform:scale(1.2); cursor:pointer;">
</td>
<td style="padding:6px; border-bottom:1px solid #eee; text-align:center;">
@@ -1204,6 +1214,7 @@
max: formData.get('max'),
class_ids: classIds,
sched: JSON.stringify(schedArray),
+ is_notif: 'true' // Default to true for new alerts
});
fetch(`/edit_alert?${params.toString()}`)
@@ -1223,13 +1234,13 @@
}
let currentAlertsCamera = null;
- function toggleAlert(alertId, isOn) {
+ function toggleAlert(alertId, isChecked, field) {
if (!currentAlertsCamera) return;
- fetch(`/edit_alert?cam=${encodeURIComponent(currentAlertsCamera)}&id=${alertId}&is_on=${isOn}`)
+ fetch(`/edit_alert?cam=${encodeURIComponent(currentAlertsCamera)}&id=${alertId}&${field}=${isChecked}`)
.then(res => {
if (!res.ok) throw new Error("Failed to toggle alert");
- console.log(`Alert ${alertId} ${isOn ? 'enabled' : 'disabled'}`);
+ console.log(`Alert ${alertId} ${field} ${isChecked ? 'enabled' : 'disabled'}`);
})
.catch(err => {
console.error("Toggle alert failed:", err);
@@ -1237,6 +1248,7 @@
fetchAlerts();
});
}
+
document.addEventListener('DOMContentLoaded', function() {
initAlertCheckboxes();
});