mirror of
https://github.com/blakeblackshear/frigate.git
synced 2025-05-03 01:17:23 +02:00
send the best person frame over mqtt for faster updates in homeassistant
This commit is contained in:
parent
700bd1e3ef
commit
2ec45cd1b6
24
README.md
24
README.md
@ -61,8 +61,8 @@ Access the mjpeg stream at `http://localhost:5000/<camera_name>` and the best pe
|
|||||||
```
|
```
|
||||||
camera:
|
camera:
|
||||||
- name: Camera Last Person
|
- name: Camera Last Person
|
||||||
platform: generic
|
platform: mqtt
|
||||||
still_image_url: http://<ip>:5000/<camera_name>/best_person.jpg
|
topic: frigate/<camera_name>/snapshot
|
||||||
|
|
||||||
binary_sensor:
|
binary_sensor:
|
||||||
- name: Camera Person
|
- name: Camera Person
|
||||||
@ -71,6 +71,26 @@ binary_sensor:
|
|||||||
value_template: '{{ value_json.person }}'
|
value_template: '{{ value_json.person }}'
|
||||||
device_class: motion
|
device_class: motion
|
||||||
availability_topic: "frigate/available"
|
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://<ip>:5000/<camera_name>/best_person.jpg
|
||||||
|
caption: A person was detected.
|
||||||
```
|
```
|
||||||
|
|
||||||
## Tips
|
## Tips
|
||||||
|
@ -1,13 +1,15 @@
|
|||||||
import json
|
import json
|
||||||
|
import cv2
|
||||||
import threading
|
import threading
|
||||||
|
|
||||||
class MqttObjectPublisher(threading.Thread):
|
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)
|
threading.Thread.__init__(self)
|
||||||
self.client = client
|
self.client = client
|
||||||
self.topic_prefix = topic_prefix
|
self.topic_prefix = topic_prefix
|
||||||
self.objects_parsed = objects_parsed
|
self.objects_parsed = objects_parsed
|
||||||
self._detected_objects = detected_objects
|
self._detected_objects = detected_objects
|
||||||
|
self.best_person_frame = best_person_frame
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
last_sent_payload = ""
|
last_sent_payload = ""
|
||||||
@ -31,3 +33,9 @@ class MqttObjectPublisher(threading.Thread):
|
|||||||
if new_payload != last_sent_payload:
|
if new_payload != last_sent_payload:
|
||||||
last_sent_payload = new_payload
|
last_sent_payload = new_payload
|
||||||
self.client.publish(self.topic_prefix+'/objects', new_payload, retain=False)
|
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)
|
@ -175,7 +175,7 @@ class Camera:
|
|||||||
self.object_cleaner.start()
|
self.object_cleaner.start()
|
||||||
|
|
||||||
# start a thread to publish object scores (currently only person)
|
# 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()
|
mqtt_publisher.start()
|
||||||
|
|
||||||
# create a watchdog thread for capture process
|
# create a watchdog thread for capture process
|
||||||
|
Loading…
Reference in New Issue
Block a user