本帖最后由 shenbo 于 2024-1-14 23:29 编辑
更新一下:
HA的提醒在iPhone里不太好用,一点就消失了,还是推送消息比较灵活,一开始用了企业微信,但是比较麻烦,而且需要固定的公网IP,转用pushdeer,很好用,能一直看到消息点击图片后能跳转视频。
msg.text = "%23%23%20摄像机探测发现";
msg.pushkey = "xxx"; //Besnon
msg.desp = `**`+msg.payload.before.camera+`摄像头探测到有人**%0A%0A
**事件ID为`+msg.payload.before.id+`**%0A%0A
[![摄像机截图](http://xxx:5000/api/events/`+ msg.payload.before.id + `/snapshot.jpg)](http://xxx:5000/api/events/` + msg.payload.before.id +`/clip.mp4)%0A%0A
**注意安全!**`;
msg.method = "get";
return msg;
复制代码
https://api2.pushdeer.com/message/push?pushkey={{{pushkey}}}&text={{{text}}}&desp={{{desp}}}&type=markdown
复制代码
最近闲了没事,研究了一下frigate的mqtt topic,其中event这个topic做的真不错,可以用node red对payload检索后筛选出你要情况和截图推送,当然也可以接一堆自动化,看大家的需要。分享一下我的经验。
提醒效果:
大家可以细看一下: https://docs.frigate.video/integrations/mqtt/ 和 https://docs.frigate.video/integrations/api/
先贴一个frigate关于event这个payload的说明,其中type这个object对于截图的选择比较重要,分为new/update/end三个状态,官方的解释"Message published for each changed event. The first message is published when the tracked object is no longer marked as a false_positive. When Frigate finds a better snapshot of the tracked object or when a zone change occurs, it will publish a message with the same id. When the event ends, a final message is published with end_time set."
"type": "update", // new, update, end
"before": {
"id": "1607123955.475377-mxklsc",
"camera": "front_door",
"frame_time": 1607123961.837752,
"snapshot_time": 1607123961.837752,
"label": "person",
"sub_label": null,
"top_score": 0.958984375,
"false_positive": false,
"start_time": 1607123955.475377,
"end_time": null,
"score": 0.7890625,
"box": [424, 500, 536, 712],
"area": 23744,
"ratio": 2.113207,
"region": [264, 450, 667, 853],
"current_zones": ["driveway"],
"entered_zones": ["yard", "driveway"],
"thumbnail": null,
"has_snapshot": false,
"has_clip": false,
"stationary": false, // whether or not the object is considered stationary
"motionless_count": 0, // number of frames the object has been motionless
"position_changes": 2 // number of times the object has moved from a stationary position
},
"after": {
"id": "1607123955.475377-mxklsc",
"camera": "front_door",
"frame_time": 1607123962.082975,
"snapshot_time": 1607123961.837752,
"label": "person",
"sub_label": null,
"top_score": 0.958984375,
"false_positive": false,
"start_time": 1607123955.475377,
"end_time": null,
"score": 0.87890625,
"box": [432, 496, 544, 854],
"area": 40096,
"ratio": 1.251397,
"region": [218, 440, 693, 915],
"current_zones": ["yard", "driveway"],
"entered_zones": ["yard", "driveway"],
"thumbnail": null,
"has_snapshot": false,
"has_clip": false,
"stationary": false, // whether or not the object is considered stationary
"motionless_count": 0, // number of frames the object has been motionless
"position_changes": 2 // number of times the object has changed position
}
}
复制代码
我是用Node Red的MQTTIN订阅frigate/events这个topic后,通过switch筛选需要的数据,最后用HA的notify.mobile服务推送带图片的消息
Node Red流程
Node Red代码
[{"id":"6d1b614840d5f527","type":"mqtt in","z":"ea2865902fe60675","name":"","topic":"frigate/events","qos":"0","datatype":"json","broker":"cea17a054e8ae49f","nl":false,"rap":true,"rh":0,"inputs":0,"x":110,"y":120,"wires":[["e2ffcbb040b746f3"]]},{"id":"70e12b2fcb425d27","type":"switch","z":"ea2865902fe60675","name":"Parking&MainDoor","property":"payload.before.camera","propertyType":"msg","rules":[{"t":"eq","v":"Parking","vt":"str"},{"t":"eq","v":"MainDoor","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":550,"y":120,"wires":[["ece377350be0e14c"],["ece377350be0e14c"]]},{"id":"ece377350be0e14c","type":"switch","z":"ea2865902fe60675","name":"探测到人","property":"payload.before.label","propertyType":"msg","rules":[{"t":"eq","v":"person","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":760,"y":120,"wires":[["e5422c8f888b3609","124098b20948a4c1"]]},{"id":"e5422c8f888b3609","type":"api-call-service","z":"ea2865902fe60675","name":"通知Benson","server":"3a102ef0.e7fc62","version":5,"debugenabled":false,"domain":"notify","service":"mobile_app_benson12","areaId":[],"deviceId":[],"entityId":[],"data":"{"title":"摄像头探测到人员","message":"{{payload.before.camera}}摄像头探测到有人靠近 事件ID:{{payload.before.id}}","data":{"ttl":0,"priority":"high","image":"http://www.benhome.xyz:5000/api/events/{{payload.before.id}}/snapshot.jpg"}}","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":950,"y":60,"wires":[["5166d8c062f41927"]]},{"id":"124098b20948a4c1","type":"api-call-service","z":"ea2865902fe60675","name":"通知Wen","server":"3a102ef0.e7fc62","version":5,"debugenabled":false,"domain":"notify","service":"mobile_app_wen12","areaId":[],"deviceId":[],"entityId":[],"data":"{"title":"摄像头探测到人员","message":"{{payload.before.camera}}摄像头探测到有人靠近","data":{"ttl":0,"priority":"high","image":"http://www.benhome.xyz:5000/api/events/{{payload.before.id}}/snapshot.jpg"}}","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":940,"y":140,"wires":[["5166d8c062f41927"]]},{"id":"67d0472fad2f1829","type":"mqtt in","z":"ea2865902fe60675","name":"","topic":"frigate/events","qos":"0","datatype":"json","broker":"cea17a054e8ae49f","nl":false,"rap":true,"rh":0,"inputs":0,"x":110,"y":260,"wires":[["9acb45e2beb61ddb"]]},{"id":"14d7776cebf239b2","type":"switch","z":"ea2865902fe60675","name":"Kids","property":"payload.before.camera","propertyType":"msg","rules":[{"t":"eq","v":"Kids","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":490,"y":260,"wires":[["fcccc97b1694e9fc"]]},{"id":"fcccc97b1694e9fc","type":"switch","z":"ea2865902fe60675","name":"探测到人","property":"payload.before.label","propertyType":"msg","rules":[{"t":"eq","v":"person","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":680,"y":260,"wires":[["26ca62f0319184bd"]]},{"id":"2af7fc51a0c418b3","type":"api-call-service","z":"ea2865902fe60675","name":"通知Benson","server":"3a102ef0.e7fc62","version":5,"debugenabled":false,"domain":"notify","service":"mobile_app_benson12","areaId":[],"deviceId":[],"entityId":[],"data":"{"title":"摄像头探测到人员","message":"{{payload.before.camera}}摄像头探测到有人靠近","data":{"ttl":0,"priority":"high","image":"http://www.benhome.xyz:5000/api/events/{{payload.before.id}}/snapshot.jpg"}}","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1130,"y":220,"wires":[[]]},{"id":"72a11bdb65831cc4","type":"api-call-service","z":"ea2865902fe60675","name":"通知Wen","server":"3a102ef0.e7fc62","version":5,"debugenabled":false,"domain":"notify","service":"mobile_app_wen12","areaId":[],"deviceId":[],"entityId":[],"data":"{"title":"摄像头探测到人员","message":"{{payload.before.camera}}摄像头探测到有人靠近","data":{"ttl":0,"priority":"high","image":"http://www.benhome.xyz:5000/api/events/{{payload.before.id}}/snapshot.jpg"}}","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1140,"y":280,"wires":[[]]},{"id":"26ca62f0319184bd","type":"time-range-switch","z":"ea2865902fe60675","name":"23:30-6:30","lat":"","lon":"","startTime":"23:30","endTime":"6:30","startOffset":0,"endOffset":0,"x":890,"y":260,"wires":[["2af7fc51a0c418b3","72a11bdb65831cc4"],[]]},{"id":"5166d8c062f41927","type":"debug","z":"ea2865902fe60675","name":"debug 1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1160,"y":60,"wires":[]},{"id":"e2ffcbb040b746f3","type":"switch","z":"ea2865902fe60675","name":"Type new&end","property":"payload.type","propertyType":"msg","rules":[{"t":"eq","v":"new","vt":"str"},{"t":"eq","v":"end","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":300,"y":120,"wires":[[],["70e12b2fcb425d27"]]},{"id":"9acb45e2beb61ddb","type":"switch","z":"ea2865902fe60675","name":"Type new&end","property":"payload.type","propertyType":"msg","rules":[{"t":"eq","v":"new","vt":"str"},{"t":"eq","v":"end","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":300,"y":260,"wires":[["14d7776cebf239b2"],["14d7776cebf239b2"]]},{"id":"cea17a054e8ae49f","type":"mqtt-broker","name":"HA MQTT SERVER","broker":"192.168.1.12","port":"1883","clientid":"","autoConnect":true,"usetls":false,"protocolVersion":"4","keepalive":"60","cleansession":true,"autoUnsubscribe":true,"birthTopic":"","birthQos":"0","birthRetain":"false","birthPayload":"","birthMsg":{},"closeTopic":"","closeQos":"0","closeRetain":"false","closePayload":"","closeMsg":{},"willTopic":"","willQos":"0","willRetain":"false","willPayload":"","willMsg":{},"userProps":"","sessionExpiry":""},{"id":"3a102ef0.e7fc62","type":"server","name":"Home Assistant","addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"","connectionDelay":false,"cacheJson":false,"heartbeat":false,"heartbeatInterval":"","statusSeparator":"","enableGlobalContextStore":false}]
复制代码
我遇到的坑主要是message的组合,大家可以参考以下内容
data部分的代码,关于message如何组合重点参考https://docs.frigate.video/integrations/api/
{
"title": "摄像头探测到人员",
"message": "{{payload.before.camera}}摄像头探测到有人 事件ID:{{payload.before.id}}",
"data": {
"ttl": 0,
"priority": "high",
"image": "http://192.168.1.14:5000/api/events/{{payload.before.id}}/snapshot.jpg"
}
}
复制代码
frigate的object有很多,大家可以结合frigate的文档依据自己的需要调整。