diff --git a/README.md b/README.md index 60393d491..fe3594231 100644 --- a/README.md +++ b/README.md @@ -61,8 +61,8 @@ Access the mjpeg stream at `http://localhost:5000/` and the best pe ``` camera: - name: Camera Last Person - platform: generic - still_image_url: http://:5000//best_person.jpg + platform: mqtt + topic: frigate//snapshot binary_sensor: - name: Camera Person @@ -71,6 +71,26 @@ binary_sensor: value_template: '{{ value_json.person }}' device_class: motion availability_topic: "frigate/available" + +automation: + - alias: Alert me if a person is detected while armed away + trigger: + platform: state + entity_id: binary_sensor.camera_person + from: 'off' + to: 'on' + condition: + - condition: state + entity_id: alarm_control_panel.home_alarm + state: armed_away + action: + - service: notify.user_telegram + data: + message: "A person was detected." + data: + photo: + - url: http://:5000//best_person.jpg + caption: A person was detected. ``` ## Tips diff --git a/frigate/mqtt.py b/frigate/mqtt.py index 0a7bd6de7..f6a9e57a4 100644 --- a/frigate/mqtt.py +++ b/frigate/mqtt.py @@ -1,13 +1,15 @@ import json +import cv2 import threading class MqttObjectPublisher(threading.Thread): - def __init__(self, client, topic_prefix, objects_parsed, detected_objects): + def __init__(self, client, topic_prefix, objects_parsed, detected_objects, best_person_frame): threading.Thread.__init__(self) self.client = client self.topic_prefix = topic_prefix self.objects_parsed = objects_parsed self._detected_objects = detected_objects + self.best_person_frame = best_person_frame def run(self): last_sent_payload = "" @@ -30,4 +32,10 @@ class MqttObjectPublisher(threading.Thread): new_payload = json.dumps(payload, sort_keys=True) if new_payload != last_sent_payload: last_sent_payload = new_payload - self.client.publish(self.topic_prefix+'/objects', new_payload, retain=False) \ No newline at end of file + self.client.publish(self.topic_prefix+'/objects', new_payload, retain=False) + # send the snapshot over mqtt as well + if not self.best_person_frame.best_frame is None: + ret, jpg = cv2.imencode('.jpg', self.best_person_frame.best_frame) + if ret: + jpg_bytes = jpg.tobytes() + self.client.publish(self.topic_prefix+'/snapshot', jpg_bytes, retain=True) \ No newline at end of file diff --git a/frigate/video.py b/frigate/video.py index 09f464f82..cbf7d67eb 100644 --- a/frigate/video.py +++ b/frigate/video.py @@ -175,7 +175,7 @@ class Camera: self.object_cleaner.start() # start a thread to publish object scores (currently only person) - mqtt_publisher = MqttObjectPublisher(self.mqtt_client, self.mqtt_topic_prefix, self.objects_parsed, self.detected_objects) + mqtt_publisher = MqttObjectPublisher(self.mqtt_client, self.mqtt_topic_prefix, self.objects_parsed, self.detected_objects, self.best_person_frame) mqtt_publisher.start() # create a watchdog thread for capture process