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

 找回密码
 立即注册
查看: 7728|回复: 3

[流程系列] 如何使node-red的tts与微信只推送其中一条有效的内容?

[复制链接]

22

主题

319

帖子

3925

积分

论坛元老

Rank: 8Rank: 8

积分
3925
金钱
3601
HASS币
30
发表于 2021-2-16 21:00:09 | 显示全部楼层 |阅读模式
本帖最后由 MX10085 于 2021-2-16 21:07 编辑

node-red 在重复信息中如何只推送一条内容?

本人node red新手,学习了萝卜的百度人脸识别,照搬了flows文件。因为人体移动,需要摄像头连续拍照捕捉人脸来提高辨识度,但结果后面推送也连续进行。

请问各位大神,要怎样才能使node-red的tts与微信只推送其中一条有效的内容呢?

原帖地址:小白萝卜小方1s改造最便宜人脸识别门铃 - 『Node-RED』综合讨论区 - 『瀚思彼岸』» 智能家居技术论坛 - Powered by Discuz! (hassbian.com)
QQ截图20210216204711.png

[{"id":"ab904761.3e0218","type":"tab","label":"流程 2","disabled":false,"info":""},{"id":"b34b67ac.688328","type":"inject","z":"ab904761.3e0218","name":"手动测试","repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{}","payloadType":"json","x":120,"y":400,"wires":[["dcd42b75.d79ff8"]]},{"id":"9c79fa35.9ae658","type":"function","z":"ab904761.3e0218","name":"存储抓到图的文件名称","func":"// 保存图片到 msg.image\nmsg.image=msg.payload;\n\n// 判断是否找到人脸,如果找到即停止循环抓图\nif (flow.get('face_find') === true){ //已经找到人脸,停止抓图\n    return null;\n}\nif (msg.image_num < 20) { // 继续抓图\n    msg.image_num = msg.image_num+1;\n    msg.headers = null;\n    return msg;\n}\nelse {\n    return null;\n}\n","outputs":1,"noerr":0,"x":720,"y":400,"wires":[["fa642b9e.dd7168","dd7a61d.4b83ea"]]},{"id":"dcd42b75.d79ff8","type":"function","z":"ab904761.3e0218","name":"初始化变量","func":"// 创建图像序号\nmsg.image_num = 1;\n\n// 定义用户列表\nmsg.user_list = {"xxxxx":"萝卜","xxxx":"老婆","mama":"妈妈"};\n\n// 初始化 flow 全局变量\nflow.set('face_find',false);\nreturn msg;","outputs":1,"noerr":0,"x":310,"y":400,"wires":[["ceac077b.ae6f28"]]},{"id":"dd7a61d.4b83ea","type":"base64","z":"ab904761.3e0218","name":"","action":"","property":"payload","x":920,"y":400,"wires":[["f4b0608d.04dd3"]]},{"id":"f4b0608d.04dd3","type":"function","z":"ab904761.3e0218","name":"人脸检测","func":"msg.access_token = flow.get('token');\nvar image = {"image":msg.payload};\nvar image_type = {"image_type":"BASE64"};\n// var group_id_list = {"group_id_list":"home"};\nvar max_face_num = {"max_face_num":"10"};\nvar face_field = {"face_field":"quality"};\nmsg.payload = {};\nObject.assign(msg.payload,image,image_type,max_face_num,face_field);\nmsg.headers = {"Content-Type":"application/json; charset=UTF-8"};\nmsg.url = "https://aip.baidubce.com/rest/2.0/face/v3/detect?access_token=" + msg.access_token;    \nreturn msg;","outputs":1,"noerr":0,"x":1120,"y":400,"wires":[["9502716a.b38db"]]},{"id":"9502716a.b38db","type":"www-request","z":"ab904761.3e0218","name":"调用百度人脸API","method":"POST","ret":"obj","url":"","follow-redirects":true,"tls":"","x":1330,"y":400,"wires":[["adf6ae1c.f327e"]]},{"id":"adf6ae1c.f327e","type":"function","z":"ab904761.3e0218","name":"是否找到人脸","func":"if (msg.payload.error_code === 0 && flow.get('face_find') === false ){\n    //筛选完整人脸\n    msg.face_list = [];\n    for (var i in msg.payload.result.face_list) {\n        if (msg.payload.result.face_list[i].face_probability > 0.8 && msg.payload.result.face_list[i].quality.blur < 0.01){\n            msg.face_list.push(msg.payload.result.face_list[i]);\n        }\n    }\n    //callback 人脸太模糊重新获取\n    if (msg.face_list.length === 0){\n    callback();\n    return null;\n    }\n    //保存人脸数\n    msg.face_num = msg.face_list.length - 1;\n    //保存图片用作推送。\n    msg.payload = msg.image;\n    //设置全局变量,停止循环抓图\n    flow.set('face_find',true);\n    return msg;\n}\nelse{\n    // 没有找到人脸\n    return null;\n}","outputs":1,"noerr":0,"x":1520,"y":400,"wires":[["7a22cf89.96cc"]]},{"id":"188e0a9a.593ce5","type":"function","z":"ab904761.3e0218","name":"人脸搜索","func":"var image = {"image":msg.face_list[msg.face_num].face_token};\nvar image_type = {"image_type":"FACE_TOKEN"};\nvar group_id_list = {"group_id_list":"home"};\nmsg.payload = {};\nObject.assign(msg.payload,image,image_type,group_id_list);\nmsg.headers = {"Content-Type":"application/json; charset=UTF-8"};\nmsg.url = "https://aip.baidubce.com/rest/2.0/face/v3/search?access_token=" + msg.access_token;\nmsg.face_num--;\nreturn msg;","outputs":1,"noerr":0,"x":180,"y":560,"wires":[["ddd38237.4dfb2"]]},{"id":"ddd38237.4dfb2","type":"www-request","z":"ab904761.3e0218","name":"调用百度人脸API","method":"POST","ret":"obj","url":"","follow-redirects":true,"tls":"","x":370,"y":560,"wires":[["fd550f2.eb79ef"]]},{"id":"fd550f2.eb79ef","type":"function","z":"ab904761.3e0218","name":"人脸对比是否完毕","func":"if (!msg.face_name){\n    msg.face_name = "";\n}\n// 搜集识别到的用户名\nif (msg.payload.result.user_list[0].score > 70){\n    var name = msg.user_list[msg.payload.result.user_list[0].user_id];\n    msg.face_name = msg.face_name + name + "," ;\n}\nelse {\n    msg.face_name = msg.face_name +  "客人," ;\n}\n\n\nif (msg.face_num < 0){\n    // 人脸对比完毕\n    msg.face_name = msg.face_name.substring(0,msg.face_name.length-1);\n    return [msg,null];\n}\nelse {\n    // 没完成人脸对比循环,继续检测。\n    msg.url = null;\n    msg.headers = null;\n    return [null,msg];\n}\n","outputs":2,"noerr":0,"x":570,"y":560,"wires":[["ff7f77b7.d2bfd8","7dd2a59d.a242cc","9f950399.9b6c3","3451009.7f1a4"],["5ce0bd98.fd9364"]]},{"id":"be549334.2e10c","type":"link in","z":"ab904761.3e0218","name":"人脸搜索循环(多线程)in","links":["5ce0bd98.fd9364"],"x":55,"y":560,"wires":[["188e0a9a.593ce5"]]},{"id":"5ce0bd98.fd9364","type":"link out","z":"ab904761.3e0218","name":"人脸搜索循环(多线程)out","links":["be549334.2e10c"],"x":615,"y":620,"wires":[]},{"id":"ff7f77b7.d2bfd8","type":"function","z":"ab904761.3e0218","name":"APP推送内容","func":"var message = msg.face_name + "回家啦";\nmsg.payload.data = {"title":"大门情况","message":message,"data":{"push":{"category":"camera"},"entity_id":"camera.damen_image_processing","hied-thumbnail":true}};\nreturn msg;","outputs":1,"noerr":0,"x":780,"y":600,"wires":[["5d8e3449.a8174c"]]},{"id":"5d8e3449.a8174c","type":"api-call-service","z":"ab904761.3e0218","name":"APP推送","server":"f5baec9d.d79c1","service_domain":"notify","service":"ios_xxxxx_iphone","data":"","mergecontext":"","x":1000,"y":600,"wires":[["329d82f6.73ae3e"]]},{"id":"e1432dcc.85645","type":"api-call-service","z":"ab904761.3e0218","name":"小爱同学TTS","server":"f5baec9d.d79c1","service_domain":"hello_miai","service":"send","data":"","mergecontext":"","x":1010,"y":540,"wires":[["892c9718.9e1a28"]]},{"id":"ceac077b.ae6f28","type":"www-request","z":"ab904761.3e0218","name":"大方摄像机获取图片","method":"GET","ret":"bin","url":"http://192.168.31.150/cgi-bin/currentpic.cgi","follow-redirects":true,"tls":"","x":500,"y":400,"wires":[["9c79fa35.9ae658"]]},{"id":"892c9718.9e1a28","type":"debug","z":"ab904761.3e0218","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1190,"y":540,"wires":[]},{"id":"329d82f6.73ae3e","type":"debug","z":"ab904761.3e0218","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1190,"y":600,"wires":[]},{"id":"7dd2a59d.a242cc","type":"function","z":"ab904761.3e0218","name":"APP推送内容","func":"var message = msg.face_name + "欢迎回家";\nmsg.payload.data = {"message":message};\nreturn msg;","outputs":1,"noerr":0,"x":780,"y":540,"wires":[["e1432dcc.85645"]]},{"id":"b64caf4b.eeb18","type":"server-state-changed","z":"ab904761.3e0218","name":"大门外监测","server":"f5baec9d.d79c1","entityidfilter":"binary_sensor.motion_sensor_158d00015e65a0","entityidfiltertype":"substring","outputinitially":false,"haltifstate":"off","outputs":1,"x":100,"y":440,"wires":[["dcd42b75.d79ff8"]]},{"id":"a83511c8.064f1","type":"api-call-service","z":"ab904761.3e0218","name":"若琪播报","server":"f5baec9d.d79c1","service_domain":"rokid_tts","service":"speak","data":"","mergecontext":"","x":1000,"y":720,"wires":[[]]},{"id":"9f950399.9b6c3","type":"function","z":"ab904761.3e0218","name":"若琪通知","func":"var message = msg.face_name + "欢迎光临";\nmsg.payload = {};\nmsg.payload.data = {"message":message};\nreturn msg;","outputs":1,"noerr":0,"x":760,"y":720,"wires":[["a83511c8.064f1"]]},{"id":"cbddc4cb.3f03f8","type":"file","z":"ab904761.3e0218","name":"保存相片","filename":"","appendNewline":true,"createDir":true,"overwriteFile":"true","x":1120,"y":440,"wires":[[]]},{"id":"fa642b9e.dd7168","type":"function","z":"ab904761.3e0218","name":"以时间命名","func":"Date.prototype.Format = function (fmt) {  \n    var o = {\n        "M+": this.getMonth() + 1, //月份 \n        "d+": this.getDate(), //日 \n        "h+": this.getHours(), //小时 \n        "m+": this.getMinutes(), //分 \n        "s+": this.getSeconds(), //秒 \n        "q+": Math.floor((this.getMonth() + 3) / 3), //季度 \n        "S": this.getMilliseconds() //毫秒 \n    };\n    if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));\n    for (var k in o)\n    if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));\n    return fmt;\n}\n\nvar file_name = new Date().Format("yyyy-MM-dd-hh-mm-ss");\nvar dir_name = new Date().Format("yyyy-MM-dd");\n\nmsg.filename = '/data/tmp/' + dir_name + '/' + file_name + '.jpg';\nreturn msg;","outputs":1,"noerr":0,"x":930,"y":440,"wires":[["cbddc4cb.3f03f8"]]},{"id":"99eadd3f.a83ed","type":"server-events","z":"ab904761.3e0218","name":"获取所有事件","server":"f5baec9d.d79c1","event_type":"","x":110,"y":320,"wires":[["70bf2986.a7ee98"]]},{"id":"70bf2986.a7ee98","type":"switch","z":"ab904761.3e0218","name":"无线开关类事件","property":"payload.event_type","propertyType":"msg","rules":[{"t":"eq","v":"click","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":320,"y":320,"wires":[["6e2a5373.2c171c"]]},{"id":"9af4b279.fd681","type":"debug","z":"ab904761.3e0218","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":670,"y":320,"wires":[]},{"id":"6e2a5373.2c171c","type":"switch","z":"ab904761.3e0218","name":"门铃无线开关","property":"payload.entity_id","propertyType":"msg","rules":[{"t":"eq","v":"binary_sensor.switch_158d00011354eb","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":500,"y":320,"wires":[["9af4b279.fd681","dcd42b75.d79ff8"]]},{"id":"c7e47e67.4738b","type":"comment","z":"ab904761.3e0218","name":"获取token到flow变量","info":"flow变量名为 token\n获取方法 msg.access_token = flow.get('token');","x":130,"y":180,"wires":[]},{"id":"d1faa81b.619d08","type":"inject","z":"ab904761.3e0218","name":"半小时获取一次token","repeat":"900","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{}","payloadType":"json","x":160,"y":240,"wires":[["709de174.a90fb"]]},{"id":"709de174.a90fb","type":"function","z":"ab904761.3e0218","name":"API_KEY","func":"var API_Key = '1111111ddddeedeeeee';\nvar API_Secret_Key = 'cdddeddeedddghg';\nmsg.url = 'https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=' + API_Key + '&client_secret=' + API_Secret_Key;\nreturn msg;","outputs":1,"noerr":0,"x":360,"y":240,"wires":[["27ddfb36.f59884"]]},{"id":"27ddfb36.f59884","type":"www-request","z":"ab904761.3e0218","name":"获取token","method":"GET","ret":"obj","url":"","follow-redirects":true,"tls":"","x":500,"y":240,"wires":[["c4c05a1c.cddaa8"]]},{"id":"c4c05a1c.cddaa8","type":"function","z":"ab904761.3e0218","name":"保存token到flow变量","func":"flow.set('token',msg.payload.access_token);\nreturn null;","outputs":0,"noerr":0,"x":700,"y":240,"wires":[]},{"id":"7a22cf89.96cc","type":"function","z":"ab904761.3e0218","name":"以时间命名","func":"Date.prototype.Format = function (fmt) {  \n    var o = {\n        "M+": this.getMonth() + 1, //月份 \n        "d+": this.getDate(), //日 \n        "h+": this.getHours(), //小时 \n        "m+": this.getMinutes(), //分 \n        "s+": this.getSeconds(), //秒 \n        "q+": Math.floor((this.getMonth() + 3) / 3), //季度 \n        "S": this.getMilliseconds() //毫秒 \n    };\n    if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));\n    for (var k in o)\n    if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));\n    return fmt;\n}\n\nvar file_name = new Date().Format("yyyy-MM-dd-hh-mm-ss");\nvar dir_name = new Date().Format("yyyy-MM-dd");\n\nmsg.filename = '/config/' + dir_name + '/' + file_name + '.jpg';\nreturn msg;","outputs":1,"noerr":0,"x":1690,"y":400,"wires":[["2aba2153.54865e"]]},{"id":"2aba2153.54865e","type":"file","z":"ab904761.3e0218","name":"保存相片","filename":"","appendNewline":true,"createDir":true,"overwriteFile":"true","x":1840,"y":400,"wires":[["6c2e75c1.135b9c","923e7636.1e3a38"]]},{"id":"6c2e75c1.135b9c","type":"debug","z":"ab904761.3e0218","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":1990,"y":360,"wires":[]},{"id":"923e7636.1e3a38","type":"link out","z":"ab904761.3e0218","name":"保存相片(out)","links":["d2996c3f.bb26e"],"x":1955,"y":400,"wires":[]},{"id":"d2996c3f.bb26e","type":"link in","z":"ab904761.3e0218","name":"人脸搜索(in)","links":["923e7636.1e3a38"],"x":55,"y":520,"wires":[["188e0a9a.593ce5"]]},{"id":"3451009.7f1a4","type":"moment","z":"ab904761.3e0218","name":"当前时间","topic":"","input":"","inputType":"date","inTz":"Asia/Shanghai","adjAmount":0,"adjType":"days","adjDir":"add","format":"YYYY-MM-DD-HH-mm-ss","locale":"POSIX","output":"nowtime","outputType":"msg","outTz":"Asia/Shanghai","x":760,"y":660,"wires":[["385c926.d116c6e"]]},{"id":"385c926.d116c6e","type":"change","z":"ab904761.3e0218","name":"设置推送参数","rules":[{"t":"set","p":"title","pt":"msg","to":"门口监控","tot":"str"},{"t":"set","p":"description","pt":"msg","to":"在门口走动,请查看","tot":"str"},{"t":"set","p":"agentid","pt":"msg","to":"1000002","tot":"num"},{"t":"set","p":"touser","pt":"msg","to":"@all","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":955,"y":660,"wires":[["7cac12f9.5ceb4c"]]},{"id":"7cac12f9.5ceb4c","type":"function","z":"ab904761.3e0218","name":"微信推送内容","func":"\n\nmsg.payload = {\n   "touser" :  `${msg.touser}`,\n   "toparty" : "PartyID1|PartyID2",\n   "totag" : "TagID1 | TagID2",\n   "msgtype" : "news",\n   "agentid" : `${msg.agentid}`,\n   "news" : {\n       "articles" : [\n           {\n               "title" : `${msg.title}`,\n               "description" : `当前时间是${msg.nowtime},${msg.face_name}${msg.description}`,\n               "url" : msg.responseUrl,\n               "picurl" : msg.responseUrl\n           }\n        ]\n   }\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1155,"y":660,"wires":[["5d5ff645.8ec428"]]},{"id":"5d5ff645.8ec428","type":"bizwechat-push","z":"ab904761.3e0218","name":"","bizwechat":"bbbdb4fa.ad73f8","x":1335,"y":660,"wires":[[]]},{"id":"f5baec9d.d79c1","type":"server","name":"Home Assistant","legacy":true,"rejectUnauthorizedCerts":true},{"id":"bbbdb4fa.ad73f8","type":"bizwechat-configurator","name":"企业微信配置","port":"3001","corpid":"ww65868bbab17bff4c","agentid":"1000002","corpsecret":"HiriK_RVQKDx0MfEwRi8BNiwN2z-1Gf-_qTGjrz2mHE","url":"http://cloud-link.me:3001","token":"LK6yCgyPGZp9ucsAHLnJ0YhF","aeskey":"Hdh3BSN5nM8cRML3eOGcPMVqeF4yi7ESKYaFAinBd0J","client_id":"a2eUzg9lxN893y3gcNLQz3Qx","client_secret":"W7mrkVWsri79cfGnr197yuiyHuZxz7kZ"}]



回复

使用道具 举报

33

主题

2196

帖子

5838

积分

论坛元老

Rank: 8Rank: 8

积分
5838
金钱
3642
HASS币
60
QQ
发表于 2021-2-16 23:58:10 | 显示全部楼层
没研究过,坐等大佬回复。
我不生产技术,我只是技术的搬运工。
回复

使用道具 举报

43

主题

412

帖子

3806

积分

元老级技术达人

积分
3806
金钱
3389
HASS币
136
发表于 2021-2-17 09:50:23 | 显示全部楼层
增加stoptime2  节点。 可以控制在给定时间内,只传输最后一个有效状态。
回复

使用道具 举报

22

主题

319

帖子

3925

积分

论坛元老

Rank: 8Rank: 8

积分
3925
金钱
3601
HASS币
30
 楼主| 发表于 2021-2-17 11:21:55 | 显示全部楼层
hunterfox 发表于 2021-2-17 09:50
增加stoptime2  节点。 可以控制在给定时间内,只传输最后一个有效状态。

多谢啦,已解决!
回复

使用道具 举报

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

本版积分规则

Archiver|手机版|小黑屋|Hassbian

GMT+8, 2024-11-21 22:58 , Processed in 2.430266 second(s), 29 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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