Updates
This commit is contained in:
parent
14267d15db
commit
13b36a8502
|
@ -0,0 +1 @@
|
||||||
|
suanni.server --hostname=0.0.0.0 --port=5354 --synology-host=cargo.sea.fudo.org --synology-port=5001 --synology-user=suanni --synology-password-file=/tmp/synology.passwd --mqtt-host=mqtt.sea.fudo.org --mqtt-port=1883 --mqtt-user=suanni --mqtt-password-file=/tmp/mqtt.passwd --mqtt-topic=suanni/events/motion --objectifier-host=objectifier.sea.fudo.org --objectifier-port=5121 --verbose
|
|
@ -0,0 +1,33 @@
|
||||||
|
(ns suanni.watcher
|
||||||
|
(:require [milquetoast.client :as mqtt]
|
||||||
|
[clojure.core.async :as async :refer [go-loop <! >!]])
|
||||||
|
(:import java.time.Instant))
|
||||||
|
|
||||||
|
(defn start-watching! [& {:keys [mqtt-client event-chan sensor-location-map verbose]
|
||||||
|
:or {verbose false}}]
|
||||||
|
(letfn [(exposes-occupancy? [d]
|
||||||
|
(some (fn [exp] (-> exp :property (= "occupancy")))
|
||||||
|
(-> d :definition :exposes)))
|
||||||
|
(assoc-location [sensor]
|
||||||
|
(assoc sensor :location (get sensor-location-map
|
||||||
|
(:ieee_address sensor))))]
|
||||||
|
(let [motion-sensors (->> (mqtt/get! mqtt-client "zigbee2mqtt/bridge/devices")
|
||||||
|
:payload
|
||||||
|
(filter exposes-occupancy?)
|
||||||
|
(map assoc-location))]
|
||||||
|
(doseq [sensor motion-sensors]
|
||||||
|
(let [sensor-topic (format "zigbee2mqtt/%s" (:ieee_address sensor))]
|
||||||
|
(when verbose (println (format "listening to channel: %s" sensor-topic)))
|
||||||
|
(let [sensor-chan (mqtt/subscribe! mqtt-client sensor-topic)]
|
||||||
|
(go-loop [evt (<! sensor-chan)]
|
||||||
|
(when evt
|
||||||
|
(>! event-chan
|
||||||
|
{
|
||||||
|
:type :motion-detected-sensor
|
||||||
|
:sensor sensor
|
||||||
|
:location (:location sensor)
|
||||||
|
:sensor-id (:ieee_address sensor)
|
||||||
|
:time (Instant/now)
|
||||||
|
})
|
||||||
|
(recur (<! sensor-chan)))))))))
|
||||||
|
true)
|
|
@ -0,0 +1,27 @@
|
||||||
|
#+title: Suanni
|
||||||
|
|
||||||
|
Suan Ni Home Guard
|
||||||
|
|
||||||
|
* Components
|
||||||
|
|
||||||
|
** Camera events
|
||||||
|
|
||||||
|
Wait for events from Synology, attach metadata, and pass them to
|
||||||
|
`suanni/events/motion/camera`
|
||||||
|
|
||||||
|
** Motion events
|
||||||
|
|
||||||
|
Get a list of presence sensors from `zigbee2mqtt`, and listen to them for
|
||||||
|
events. Attach metadata, and pass to `suanni/events/motion/sensor`
|
||||||
|
|
||||||
|
** Object detector
|
||||||
|
|
||||||
|
Watches all events on `suanni/events/motion/#`, and if there's an attached
|
||||||
|
location, attempts to take a snapshot from the nearby cameras, analyzing them
|
||||||
|
for objects. When objects are detected, post the results to
|
||||||
|
`suanni/events/object_detection`.
|
||||||
|
|
||||||
|
** Home assistant bridge
|
||||||
|
|
||||||
|
Listen for objects on `suanni/events/object_detection`, and forward events on to
|
||||||
|
a Home Assistant binary sensor.
|
Loading…
Reference in New Issue