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

 找回密码
 立即注册
查看: 1769|回复: 15

[经验分享] Frigate + MQTT + HA 推送摄像头----更新为PushDeer推视截图+视频

[复制链接]

6

主题

74

帖子

631

积分

高级会员

Rank: 4

积分
631
金钱
557
HASS币
10
发表于 2024-1-13 12:22:51 | 显示全部楼层 |阅读模式
本帖最后由 shenbo 于 2024-1-14 23:29 编辑

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


Screenshot 2024-01-14 at 23.10.34.png

Screenshot 2024-01-14 at 23.11.54.png


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;



Screenshot 2024-01-14 at 23.12.04.png
https://api2.pushdeer.com/message/push?pushkey={{{pushkey}}}&text={{{text}}}&desp={{{desp}}}&type=markdown




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

IMG_2727.PNG

大家可以细看一下: 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流程
Screenshot 2024-01-13 at 12.10.59.png

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

Screenshot 2024-01-13 at 12.18.43.png

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的文档依据自己的需要调整。

评分

参与人数 4金钱 +39 收起 理由
qq328297200 + 3
firewater + 10 论坛有你更精彩!
sorrypqa + 16 大神666!
隔壁的王叔叔 + 10 感谢楼主分享!

查看全部评分

回复

使用道具 举报

8

主题

863

帖子

5126

积分

论坛元老

Rank: 8Rank: 8

积分
5126
金钱
4263
HASS币
0
发表于 2024-1-13 15:52:45 | 显示全部楼层
厉害了,赞,学习,谢谢分享
回复

使用道具 举报

0

主题

120

帖子

946

积分

高级会员

Rank: 4

积分
946
金钱
826
HASS币
0
发表于 2024-1-13 15:58:39 | 显示全部楼层
你这个自定义不错,我是用的蓝图实现的推送,没有你这个灵活,参考下看看
回复

使用道具 举报

0

主题

120

帖子

946

积分

高级会员

Rank: 4

积分
946
金钱
826
HASS币
0
发表于 2024-1-13 17:35:12 | 显示全部楼层
Node Red代码导入有问题,没法导入
回复

使用道具 举报

6

主题

74

帖子

631

积分

高级会员

Rank: 4

积分
631
金钱
557
HASS币
10
 楼主| 发表于 2024-1-13 17:48:14 | 显示全部楼层
本帖最后由 shenbo 于 2024-1-13 17:50 编辑
jimgo 发表于 2024-1-13 17:35
Node Red代码导入有问题,没法导入

flows.json (5.32 KB, 下载次数: 22)




回复

使用道具 举报

50

主题

1300

帖子

4911

积分

论坛DIY达人

积分
4911
金钱
3611
HASS币
20
发表于 2024-1-13 21:16:05 | 显示全部楼层
没用过NR,不懂怎么用....
回复

使用道具 举报

0

主题

120

帖子

946

积分

高级会员

Rank: 4

积分
946
金钱
826
HASS币
0
发表于 2024-1-13 21:18:08 | 显示全部楼层

感谢分享!!!
回复

使用道具 举报

6

主题

114

帖子

811

积分

高级会员

Rank: 4

积分
811
金钱
697
HASS币
0
发表于 2024-1-13 22:34:31 来自手机 | 显示全部楼层
直接用集成不是更方便?再导个自动化蓝图。
回复

使用道具 举报

6

主题

74

帖子

631

积分

高级会员

Rank: 4

积分
631
金钱
557
HASS币
10
 楼主| 发表于 2024-1-14 00:37:04 | 显示全部楼层
yunliang029 发表于 2024-1-13 22:34
直接用集成不是更方便?再导个自动化蓝图。

分享学习一下
回复

使用道具 举报

22

主题

453

帖子

5004

积分

元老级技术达人

略懂一些皮毛而已!

积分
5004
金钱
4541
HASS币
40
发表于 2024-1-14 19:06:53 | 显示全部楼层
感觉推送截图这块有点不太好,因为并不能保证每次都能抓取到这个人的正脸,所以还是推送到企业微信让他抓取10秒内的画面比较好, 我个人感觉,不喜勿喷!
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|Hassbian

GMT+8, 2024-5-2 10:26 , Processed in 0.169651 second(s), 35 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表