Update app.py
This commit is contained in:
parent
8ee1158680
commit
758de5b0fe
47
app.py
Normal file
47
app.py
Normal file
@ -0,0 +1,47 @@
|
||||
from gotify import Gotify
|
||||
import paho.mqtt.client as mqtt
|
||||
import json
|
||||
import time
|
||||
|
||||
frigate_http="https"
|
||||
frigate_url="example.com/"
|
||||
# Must point to PATH api/events/ of frigate
|
||||
frigate_api_path="snapshots/"
|
||||
# Basic HTTP Auth Fomat (e.g username:password@)
|
||||
frigate_auth="username:password@"
|
||||
mqtt_ip="ip"
|
||||
mqtt_port=1883
|
||||
|
||||
gotify = Gotify(
|
||||
base_url="https://gotify.example.com/",
|
||||
app_token="token",
|
||||
)
|
||||
|
||||
def on_connect(client, userdata, flags, rc):
|
||||
print("Connected with result code "+str(rc))
|
||||
client.subscribe("frigate/events")
|
||||
|
||||
def on_message(client, userdata, msg):
|
||||
data = msg.payload
|
||||
decoded_data = json.loads(data.decode())
|
||||
if decoded_data["type"] == "new":
|
||||
print(f'{time.ctime(1545925769.9618232)}: A {decoded_data["after"]["label"]} has been detected at {decoded_data["after"]["camera"]}. See at {frigate_http}://{frigate_url}api/events/{decoded_data["after"]["id"]}/snapshot.jpg')
|
||||
frigate_title = f'A {decoded_data["after"]["label"]} has been detected at {decoded_data["after"]["camera"]}.'
|
||||
frigate_msg = f'A {decoded_data["after"]["label"]} has been detected at {decoded_data["after"]["camera"]}. See at {frigate_http}://{frigate_url}api/events/{decoded_data["after"]["id"]}/snapshot.jpg'
|
||||
frigate_extras = {
|
||||
"client::notification": {
|
||||
"bigImageUrl": f'{frigate_http}://{frigate_url}{frigate_api_path}{decoded_data["after"]["id"]}/snapshot.jpg',
|
||||
"click": { "url": f'{frigate_http}://{frigate_auth}{frigate_url}events?camera={decoded_data["after"]["camera"]}&label={decoded_data["after"]["label"]}' }
|
||||
}
|
||||
}
|
||||
gotify.create_message(frigate_msg,frigate_extras,title=frigate_title,priority=7)
|
||||
print(frigate_extras)
|
||||
|
||||
|
||||
client = mqtt.Client()
|
||||
client.on_connect = on_connect
|
||||
client.on_message = on_message
|
||||
|
||||
client.connect(mqtt_ip, mqtt_port, 60)
|
||||
|
||||
client.loop_forever()
|
Loading…
x
Reference in New Issue
Block a user