『瀚思彼岸』» 智能家居技术论坛

标题: Frigate + MQTT + HA 推送摄像头----更新为PushDeer推视截图+视频 [打印本页]

作者: shenbo    时间: 2024-1-13 12:22
标题: Frigate + MQTT + HA 推送摄像头----更新为PushDeer推视截图+视频
本帖最后由 shenbo 于 2024-1-14 23:29 编辑

更新一下:
HA的提醒在iPhone里不太好用,一点就消失了,还是推送消息比较灵活,一开始用了企业微信,但是比较麻烦,而且需要固定的公网IP,转用pushdeer,很好用,能一直看到消息点击图片后能跳转视频。
[attach]55220[/attach]


[attach]55221[/attach]

[attach]55222[/attach]


  1. msg.text = "%23%23%20摄像机探测发现";
  2. msg.pushkey = "xxx"; //Besnon
  3. msg.desp = `**`+msg.payload.before.camera+`摄像头探测到有人**%0A%0A
  4. **事件ID为`+msg.payload.before.id+`**%0A%0A
  5. [![摄像机截图](http://xxx:5000/api/events/`+ msg.payload.before.id + `/snapshot.jpg)](http://xxx:5000/api/events/` + msg.payload.before.id +`/clip.mp4)%0A%0A
  6. **注意安全!**`;
  7. msg.method = "get";
  8. return msg;
复制代码



[attach]55223[/attach]
  1. https://api2.pushdeer.com/message/push?pushkey={{{pushkey}}}&text={{{text}}}&desp={{{desp}}}&type=markdown
复制代码




最近闲了没事,研究了一下frigate的mqtt topic,其中event这个topic做的真不错,可以用node red对payload检索后筛选出你要情况和截图推送,当然也可以接一堆自动化,看大家的需要。分享一下我的经验。
提醒效果:

[attach]55167[/attach]

大家可以细看一下: 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."
  1.   "type": "update", // new, update, end
  2.   "before": {
  3.     "id": "1607123955.475377-mxklsc",
  4.     "camera": "front_door",
  5.     "frame_time": 1607123961.837752,
  6.     "snapshot_time": 1607123961.837752,
  7.     "label": "person",
  8.     "sub_label": null,
  9.     "top_score": 0.958984375,
  10.     "false_positive": false,
  11.     "start_time": 1607123955.475377,
  12.     "end_time": null,
  13.     "score": 0.7890625,
  14.     "box": [424, 500, 536, 712],
  15.     "area": 23744,
  16.     "ratio": 2.113207,
  17.     "region": [264, 450, 667, 853],
  18.     "current_zones": ["driveway"],
  19.     "entered_zones": ["yard", "driveway"],
  20.     "thumbnail": null,
  21.     "has_snapshot": false,
  22.     "has_clip": false,
  23.     "stationary": false, // whether or not the object is considered stationary
  24.     "motionless_count": 0, // number of frames the object has been motionless
  25.     "position_changes": 2 // number of times the object has moved from a stationary position
  26.   },
  27.   "after": {
  28.     "id": "1607123955.475377-mxklsc",
  29.     "camera": "front_door",
  30.     "frame_time": 1607123962.082975,
  31.     "snapshot_time": 1607123961.837752,
  32.     "label": "person",
  33.     "sub_label": null,
  34.     "top_score": 0.958984375,
  35.     "false_positive": false,
  36.     "start_time": 1607123955.475377,
  37.     "end_time": null,
  38.     "score": 0.87890625,
  39.     "box": [432, 496, 544, 854],
  40.     "area": 40096,
  41.     "ratio": 1.251397,
  42.     "region": [218, 440, 693, 915],
  43.     "current_zones": ["yard", "driveway"],
  44.     "entered_zones": ["yard", "driveway"],
  45.     "thumbnail": null,
  46.     "has_snapshot": false,
  47.     "has_clip": false,
  48.     "stationary": false, // whether or not the object is considered stationary
  49.     "motionless_count": 0, // number of frames the object has been motionless
  50.     "position_changes": 2 // number of times the object has changed position
  51.   }
  52. }
复制代码




我是用Node Red的MQTTIN订阅frigate/events这个topic后,通过switch筛选需要的数据,最后用HA的notify.mobile服务推送带图片的消息

Node Red流程
[attach]55163[/attach]

Node Red代码

  1. [{"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的组合,大家可以参考以下内容

[attach]55164[/attach]

data部分的代码,关于message如何组合重点参考https://docs.frigate.video/integrations/api/
  1. {
  2.     "title": "摄像头探测到人员",
  3.     "message": "{{payload.before.camera}}摄像头探测到有人 事件ID:{{payload.before.id}}",
  4.     "data": {
  5.         "ttl": 0,
  6.         "priority": "high",
  7.         "image": "http://192.168.1.14:5000/api/events/{{payload.before.id}}/snapshot.jpg"
  8.     }
  9. }
复制代码


frigate的object有很多,大家可以结合frigate的文档依据自己的需要调整。


作者: 新生活    时间: 2024-1-13 15:52
厉害了,赞,学习,谢谢分享
作者: jimgo    时间: 2024-1-13 15:58
你这个自定义不错,我是用的蓝图实现的推送,没有你这个灵活,参考下看看
作者: jimgo    时间: 2024-1-13 17:35
Node Red代码导入有问题,没法导入
作者: shenbo    时间: 2024-1-13 17:48
本帖最后由 shenbo 于 2024-1-13 17:50 编辑
jimgo 发表于 2024-1-13 17:35
Node Red代码导入有问题,没法导入

[attach]55171[/attach]





作者: sorrypqa    时间: 2024-1-13 21:16
没用过NR,不懂怎么用....
作者: jimgo    时间: 2024-1-13 21:18
shenbo 发表于 2024-1-13 17:48

感谢分享!!!
作者: yunliang029    时间: 2024-1-13 22:34
直接用集成不是更方便?再导个自动化蓝图。
作者: shenbo    时间: 2024-1-14 00:37
yunliang029 发表于 2024-1-13 22:34
直接用集成不是更方便?再导个自动化蓝图。

分享学习一下
作者: Mr.G    时间: 2024-1-14 19:06
感觉推送截图这块有点不太好,因为并不能保证每次都能抓取到这个人的正脸,所以还是推送到企业微信让他抓取10秒内的画面比较好, 我个人感觉,不喜勿喷!
作者: yunliang029    时间: 2024-1-14 19:55
[attach]55218[/attach]在加载项哪装好Frigate。hacs 哪装集成。然后添加集成。
作者: yunliang029    时间: 2024-1-14 19:58
yunliang029 发表于 2024-1-14 19:55
在加载项哪装好Frigate。hacs 哪装集成。然后添加集成。

https://my.home-assistant.io/red ... otifications%2FBeta。 蓝图
作者: shenbo    时间: 2024-1-14 22:37
Mr.G 发表于 2024-1-14 19:06
感觉推送截图这块有点不太好,因为并不能保证每次都能抓取到这个人的正脸,所以还是推送到企业微信让他抓取 ...

是的,HomeAssistan的通知是不太方便,我后来改成pushdeer推送了,当然推送clip也挺好
作者: shenbo    时间: 2024-1-14 23:04
yunliang029 发表于 2024-1-14 19:58
https://my.home-assistant.io/redirect/blueprint_import/?blueprint_url=https%3A%2F%2Fgithub.com%2FS ...

第一次用蓝图 都是用node-red,学习了
作者: pxly2k    时间: 2024-2-2 00:47
yunliang029 发表于 2024-1-13 22:34
直接用集成不是更方便?再导个自动化蓝图。

更新frigate后,集成里显示配置失败,没有实体。你们会这样吗?
作者: hood2000    时间: 2024-4-11 12:07
本帖最后由 hood2000 于 2024-4-11 12:18 编辑
  1. 更新一下:
  2. HA的提醒在iPhone里不太好用,一点就消失了
复制代码


iphone上按住消息,会显示详细内容和图片。安卓反而麻烦一些,如果不建立持久链接,那就需要走google推送。





欢迎光临 『瀚思彼岸』» 智能家居技术论坛 (https://bbs.hassbian.com/) Powered by Discuz! X3.5