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

 找回密码
 立即注册
查看: 1737|回复: 6

[教程系列] 小白历时2周终于用上了,超温微信提示。

[复制链接]

5

主题

21

帖子

120

积分

注册会员

Rank: 2

积分
120
金钱
99
HASS币
0
发表于 2024-10-2 23:21:25 | 显示全部楼层 |阅读模式
本帖最后由 寒夜吟 于 2024-10-4 11:55 编辑

为了让手机及时接收到温度的提示。小白入坑了 ,也在论坛上发贴求助。
下面使用的代码有论坛大神的、B站大神的、自己的、AI通义千问的,就是个整合怪。
给大家分享一下。
基本想法是:1、设置正常温度湿度范围,不在正常范围就提醒。回到正常温度后提示2次。
                    2、使用PING命令判断温度湿度传感器是否在线(感觉不好用)。
使用过程中发现:1、温度到达设置的警戒值会同时提示一个超温,一个正常。影响不大,还没有解决。                            2、有时候莫名其妙掉线,PING失败。这时会一起提示: 低于警戒线16度,和温度正常温度27度。

语句不知道为什么会报错,上传了附件。
[{"id":"8430daf6e32c541b","type":"tab","label":"温湿度报警","disabled":false,"info":"温湿度","env":[]},{"id":"aa9e397c03f86663","type":"api-current-state","z":"8430daf6e32c541b","name":"温度","server":"c9ce0c5e564bed0a","version":3,"outputs":1,"halt_if":"","halt_if_type":"num","halt_if_compare":"is","entity_id":"sensor.esphome_web_107004_temperature","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"}],"for":"0","forType":"num","forUnits":"seconds","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":230,"y":340,"wires":[["2c89adc818b9dc7e"]]},{"id":"6812ab342657ab71","type":"inject","z":"8430daf6e32c541b","name":"周期","props":[],"repeat":"600","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":90,"y":340,"wires":[["aa9e397c03f86663"]]},{"id":"7ae97f2f284ec04e","type":"debug","z":"8430daf6e32c541b","name":"debug 35","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1160,"y":120,"wires":[]},{"id":"d2949244440748d0","type":"debug","z":"8430daf6e32c541b","name":"debug 36","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1160,"y":80,"wires":[]},{"id":"9783bb68f4c3f971","type":"switch","z":"8430daf6e32c541b","name":"温度20_28高低","property":"payload","propertyType":"msg","rules":[{"t":"gt","v":"28","vt":"str"},{"t":"lt","v":"20","vt":"str"},{"t":"btwn","v":"20","vt":"num","v2":"28","v2t":"num"}],"checkall":"true","repair":false,"outputs":3,"x":480,"y":280,"wires":[["a81ed7ac1f4f3253","c15269ae9ba184c1"],["8a0b9e981e7a190f","a81ed7ac1f4f3253"],["dbb277603f26353b"]]},{"id":"37accae04765c6f9","type":"function","z":"8430daf6e32c541b","name":"低温提醒","func":"msg.current = Math.floor(msg.payload);\nmsg.before = global.get("sensor.esphome_web_107004_temperature") || msg.current;\nmsg.wencha = msg.current - msg.before;\n\nif( msg.wencha != 0 ){\n    if( msg.wencha > 0 ){\n        msg.payload = "低温提醒,温度升高"+ msg.wencha +"度,当前为:" + msg.payload + "度";\n    }else if (msg.wencha < 0 ){\n        msg.payload = "低温提醒,温度降低"+ Math.abs(msg.wencha) +"度,当前为:" + msg.payload + "度";\n    }\n    global.set("sensor.esphome_web_107004_temperature", msg.current);\n    return msg;\n}else{\n    \n    global.set("sensor.esphome_web_107004_temperature", msg.current);\n}\n","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1000,"y":120,"wires":[["7ae97f2f284ec04e"]]},{"id":"29f771c6c735002e","type":"function","z":"8430daf6e32c541b","name":"超温提醒","func":"msg.current = Math.floor(msg.payload);\nmsg.before = global.get("sensor.esphome_web_107004_temperature") || msg.current;\nmsg.wencha = msg.current - msg.before;\n// 获取当前时间\nvar now = new Date();\n\n// 格式化时间为 YYYY-MM-DD HH:mm:ss\nvar formattedDate = now.toISOString().replace('T', ' ').substring(0, 19);\n\nif( msg.wencha != 0 ){\n    if( msg.wencha > 0 ){\n        msg.payload = "高温预警:超温,温度升高"+ msg.wencha +"度,当前为:" + msg.payload + "度, 当前时间"+ formattedDate;\n    }else if (msg.wencha < 0 ){\n        msg.payload = "高温预警:超温,温度降低"+ Math.abs(msg.wencha) +"度,当前为:" + msg.payload + "度, 当前时间"+ formattedDate;\n    }\n    global.set("sensor.esphome_web_107004_temperature", msg.current);\n    return msg;\n}else{\n    \n    global.set("sensor.esphome_web_107004_temperature", msg.current);\n}\n","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1000,"y":80,"wires":[["d2949244440748d0"]]},{"id":"2c89adc818b9dc7e","type":"delay","z":"8430daf6e32c541b","name":"","pauseType":"delay","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":460,"y":140,"wires":[["557929b37ff70db9"]]},{"id":"30b61553fa3cd55f","type":"template","z":"8430daf6e32c541b","name":"当前温度","field":"payload","fieldType":"msg","format":"json","syntax":"mustache","template":"温度正常:现在温度 {{payload}} 度!\n","output":"str","x":720,"y":480,"wires":[["e7da87d4f76d9dda","39897bdfbd63159a"]]},{"id":"e7da87d4f76d9dda","type":"debug","z":"8430daf6e32c541b","name":"debug 40","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":720,"y":520,"wires":[]},{"id":"32b4a1692d68104a","type":"counter","z":"8430daf6e32c541b","name":"计数器重置","init":"0","step":"1","lower":"0","upper":"5","mode":"increment","outputs":"1","x":730,"y":360,"wires":[["b5fad6cf7416056e"]]},{"id":"98f8dbed2de7045b","type":"inject","z":"8430daf6e32c541b","name":"重置","props":[{"p":"reset","v":"count","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":450,"y":480,"wires":[["32b4a1692d68104a"]]},{"id":"bb505f20f955b26b","type":"inject","z":"8430daf6e32c541b","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":90,"y":280,"wires":[["92086a44d4ebe230"]]},{"id":"92086a44d4ebe230","type":"change","z":"8430daf6e32c541b","name":"39","rules":[{"t":"set","p":"payload","pt":"msg","to":"39","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":230,"y":280,"wires":[["2c89adc818b9dc7e"]]},{"id":"d0d7fd9127984d9e","type":"change","z":"8430daf6e32c541b","name":"28","rules":[{"t":"set","p":"payload","pt":"msg","to":"28","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":230,"y":200,"wires":[["2c89adc818b9dc7e"]]},{"id":"ac1a2f3a63bf0ff1","type":"change","z":"8430daf6e32c541b","name":"16","rules":[{"t":"set","p":"payload","pt":"msg","to":"16","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":230,"y":80,"wires":[["2c89adc818b9dc7e"]]},{"id":"045dd61d6ad5e342","type":"inject","z":"8430daf6e32c541b","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":90,"y":80,"wires":[["ac1a2f3a63bf0ff1"]]},{"id":"0b2bc8f3c4e04bd2","type":"inject","z":"8430daf6e32c541b","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":90,"y":200,"wires":[["d0d7fd9127984d9e"]]},{"id":"b5fad6cf7416056e","type":"switch","z":"8430daf6e32c541b","name":"限制次数","property":"count","propertyType":"msg","rules":[{"t":"lte","v":"2","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":720,"y":400,"wires":[["20c3a5556f503b8d"]]},{"id":"dbb277603f26353b","type":"delay","z":"8430daf6e32c541b","name":"","pauseType":"delay","timeout":"3","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":720,"y":300,"wires":[["32b4a1692d68104a"]]},{"id":"c15269ae9ba184c1","type":"template","z":"8430daf6e32c541b","name":"超温提醒","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"高温预警,超出警戒线,当前温度:{{payload}} 度! ","output":"str","x":720,"y":180,"wires":[["39897bdfbd63159a"]]},{"id":"8a0b9e981e7a190f","type":"template","z":"8430daf6e32c541b","name":"低温提醒","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"低温预警,低于警戒线,当前温度:{{payload}} 度!","output":"str","x":720,"y":220,"wires":[["39897bdfbd63159a"]]},{"id":"fb9d30fb74a5a504","type":"change","z":"8430daf6e32c541b","name":"17","rules":[{"t":"set","p":"payload","pt":"msg","to":"17","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":230,"y":120,"wires":[["2c89adc818b9dc7e"]]},{"id":"fe90ff44589579e2","type":"inject","z":"8430daf6e32c541b","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":90,"y":120,"wires":[["fb9d30fb74a5a504"]]},{"id":"8808e80ed93b7bdd","type":"inject","z":"8430daf6e32c541b","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":90,"y":240,"wires":[["cbca839b7b40a2a4"]]},{"id":"cbca839b7b40a2a4","type":"change","z":"8430daf6e32c541b","name":"37","rules":[{"t":"set","p":"payload","pt":"msg","to":"37","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":230,"y":240,"wires":[["2c89adc818b9dc7e"]]},{"id":"20c3a5556f503b8d","type":"switch","z":"8430daf6e32c541b","name":"payload不为空","property":"payload","propertyType":"msg","rules":[{"t":"nnull"}],"checkall":"true","repair":false,"outputs":1,"x":740,"y":440,"wires":[["30b61553fa3cd55f"]]},{"id":"a81ed7ac1f4f3253","type":"change","z":"8430daf6e32c541b","name":"发送重置","rules":[{"t":"set","p":"reset","pt":"msg","to":"count","tot":"str"},{"t":"delete","p":"payload","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":460,"y":360,"wires":[["32b4a1692d68104a"]]},{"id":"557929b37ff70db9","type":"rbe","z":"8430daf6e32c541b","name":"温差","func":"deadbandEq","gap":"1","start":"","inout":"in","septopics":true,"property":"payload","topi":"topic","x":450,"y":200,"wires":[["9783bb68f4c3f971"]]},{"id":"8d9118c376549e26","type":"inject","z":"8430daf6e32c541b","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":90,"y":160,"wires":[["4462a279553831dd"]]},{"id":"4462a279553831dd","type":"change","z":"8430daf6e32c541b","name":"27","rules":[{"t":"set","p":"payload","pt":"msg","to":"27","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":230,"y":160,"wires":[["2c89adc818b9dc7e"]]},{"id":"10a1afba81ed9dfe","type":"function","z":"8430daf6e32c541b","name":"加上时间","func":"// 获取当前时间\nvar now = new Date();\n// 将时间转换为北京时间(UTC+8)\nnow.setHours(now.getHours() + 8);\n// 格式化时间为 YYYY-MM-DD HH:mm:ss\nvar formattedDate = now.toISOString().replace('T', ' ').substring(0, 19);\n\n// 将格式化后的时间附加到消息负载\nmsg.payload = msg.payload + "当前时间" + formattedDate;\n\n\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":460,"y":660,"wires":[["abe13261707f01ee"]]},{"id":"08b49110db5959c1","type":"inject","z":"8430daf6e32c541b","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":270,"y":720,"wires":[["10a1afba81ed9dfe"]]},{"id":"abe13261707f01ee","type":"function","z":"8430daf6e32c541b","name":"生成请求内容","func":"msg.url = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=317427de-2f37-4822-996d-bb673e36136d";//替换为自己的webhook\nmsg.payload = {\n    "msgtype": "text",\n    "text": {\n        "content": msg.payload\n    }\n}\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":740,"y":660,"wires":[["297c5af62f6e41f8","15b9c6883973d1ca"]]},{"id":"297c5af62f6e41f8","type":"http request","z":"8430daf6e32c541b","name":"","method":"POST","ret":"txt","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[],"x":720,"y":700,"wires":[["97ce85fe8382f47c"]]},{"id":"97ce85fe8382f47c","type":"debug","z":"8430daf6e32c541b","name":"http返回","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":720,"y":740,"wires":[]},{"id":"b39d6cfb9d50e92d","type":"inject","z":"8430daf6e32c541b","name":"周期","props":[],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":110,"y":1180,"wires":[["c61f712283dcde2f"]]},{"id":"c61f712283dcde2f","type":"api-current-state","z":"8430daf6e32c541b","name":"湿度","server":"c9ce0c5e564bed0a","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"sensor.esphome_web_107004_humidity","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"shidu","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"for":"0","forType":"num","forUnits":"seconds","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":230,"y":1180,"wires":[["1073555177843667"]]},{"id":"1073555177843667","type":"delay","z":"8430daf6e32c541b","name":"","pauseType":"delay","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":460,"y":980,"wires":[["9f54659e3bf8062a"]]},{"id":"1b868f8ac48c23b0","type":"switch","z":"8430daf6e32c541b","name":"湿度25_60高低","property":"shidu","propertyType":"msg","rules":[{"t":"gt","v":"60","vt":"str"},{"t":"lt","v":"25","vt":"str"},{"t":"btwn","v":"25","vt":"num","v2":"60","v2t":"num"}],"checkall":"true","repair":false,"outputs":3,"x":480,"y":1100,"wires":[["255a5830fbba321d","e95eea1c0186b777"],["5a167e75bafe1fd9","e95eea1c0186b777"],["2d2dcb0e5e2fa419"]]},{"id":"9f54659e3bf8062a","type":"rbe","z":"8430daf6e32c541b","name":"湿度差","func":"deadbandEq","gap":"10","start":"","inout":"in","septopics":true,"property":"shidu","topi":"topic","x":450,"y":1040,"wires":[["1b868f8ac48c23b0"]]},{"id":"255a5830fbba321d","type":"template","z":"8430daf6e32c541b","name":"超温提醒","field":"shidu","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"湿度 超出 警戒线,当前湿度,{{shidu}}%! ","output":"str","x":720,"y":1040,"wires":[["b885afe5ec29402a"]]},{"id":"5a167e75bafe1fd9","type":"template","z":"8430daf6e32c541b","name":"低温提醒","field":"shidu","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"湿度 低于 警戒线,当前湿度,{{shidu}}%! ","output":"str","x":720,"y":1080,"wires":[["b885afe5ec29402a"]]},{"id":"2d2dcb0e5e2fa419","type":"delay","z":"8430daf6e32c541b","name":"","pauseType":"delay","timeout":"3","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":720,"y":1160,"wires":[["4655725f50e72dff"]]},{"id":"4655725f50e72dff","type":"counter","z":"8430daf6e32c541b","name":"计数器重置","init":"0","step":"1","lower":"0","upper":"5","mode":"increment","outputs":"1","x":730,"y":1200,"wires":[["bab86f07c61e2c22"]]},{"id":"bab86f07c61e2c22","type":"switch","z":"8430daf6e32c541b","name":"限制次数","property":"count","propertyType":"msg","rules":[{"t":"lte","v":"2","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":720,"y":1260,"wires":[["2595e46cd285ed64"]]},{"id":"2595e46cd285ed64","type":"switch","z":"8430daf6e32c541b","name":"shidu不为空","property":"shidu","propertyType":"msg","rules":[{"t":"nnull"}],"checkall":"true","repair":false,"outputs":1,"x":730,"y":1320,"wires":[["f45e4fce7f2a7920"]]},{"id":"f45e4fce7f2a7920","type":"template","z":"8430daf6e32c541b","name":"当前湿度","field":"shidu","fieldType":"msg","format":"json","syntax":"mustache","template":"湿度 正常范围内,当前湿度,{{shidu}}%! ","output":"str","x":720,"y":1380,"wires":[["b885afe5ec29402a"]]},{"id":"cb3d9b7176f13fc6","type":"inject","z":"8430daf6e32c541b","name":"","props":[],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":110,"y":1100,"wires":[["e3e2787bc8f9c6e3"]]},{"id":"e3e2787bc8f9c6e3","type":"change","z":"8430daf6e32c541b","name":"39","rules":[{"t":"set","p":"shidu","pt":"msg","to":"39","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":230,"y":1100,"wires":[["1073555177843667"]]},{"id":"7fb0e2a6b28f6523","type":"change","z":"8430daf6e32c541b","name":"28","rules":[{"t":"set","p":"shidu","pt":"msg","to":"28","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":230,"y":1020,"wires":[["1073555177843667"]]},{"id":"8c0f1311786be15d","type":"change","z":"8430daf6e32c541b","name":"16","rules":[{"t":"set","p":"shidu","pt":"msg","to":"16","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":230,"y":900,"wires":[["1073555177843667"]]},{"id":"9e1de9b17a5df316","type":"inject","z":"8430daf6e32c541b","name":"","props":[],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":110,"y":900,"wires":[["8c0f1311786be15d"]]},{"id":"1186f35dc5024b8c","type":"inject","z":"8430daf6e32c541b","name":"","props":[],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":110,"y":1020,"wires":[["7fb0e2a6b28f6523"]]},{"id":"4eb9c6dfce476c3d","type":"change","z":"8430daf6e32c541b","name":"17","rules":[{"t":"set","p":"shidu","pt":"msg","to":"17","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":230,"y":940,"wires":[["1073555177843667"]]},{"id":"3a760529779e0b86","type":"inject","z":"8430daf6e32c541b","name":"","props":[],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":110,"y":940,"wires":[["4eb9c6dfce476c3d"]]},{"id":"a5dcd65917abd662","type":"inject","z":"8430daf6e32c541b","name":"","props":[],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":110,"y":1060,"wires":[["56863922eff652be"]]},{"id":"56863922eff652be","type":"change","z":"8430daf6e32c541b","name":"37","rules":[{"t":"set","p":"shidu","pt":"msg","to":"37","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":230,"y":1060,"wires":[["1073555177843667"]]},{"id":"23630e766973c251","type":"inject","z":"8430daf6e32c541b","name":"","props":[],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":110,"y":980,"wires":[["1fe262a1053da291"]]},{"id":"1fe262a1053da291","type":"change","z":"8430daf6e32c541b","name":"27","rules":[{"t":"set","p":"shidu","pt":"msg","to":"27","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":230,"y":980,"wires":[["1073555177843667"]]},{"id":"e95eea1c0186b777","type":"change","z":"8430daf6e32c541b","name":"发送重置","rules":[{"t":"set","p":"reset","pt":"msg","to":"count","tot":"str"},{"t":"delete","p":"payload","pt":"msg"},{"t":"delete","p":"shidu","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":460,"y":1200,"wires":[["4655725f50e72dff"]]},{"id":"b885afe5ec29402a","type":"change","z":"8430daf6e32c541b","name":"湿度替换","rules":[{"t":"move","p":"shidu","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1020,"y":1180,"wires":[["c32db5269a08c601","10a1afba81ed9dfe"]]},{"id":"c32db5269a08c601","type":"debug","z":"8430daf6e32c541b","name":"debug 57","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1220,"y":1180,"wires":[]},{"id":"39897bdfbd63159a","type":"link out","z":"8430daf6e32c541b","name":"link out 8","mode":"link","links":["b9808aeb6a1adb83"],"x":1055,"y":300,"wires":[]},{"id":"b9808aeb6a1adb83","type":"link in","z":"8430daf6e32c541b","name":"link in 6","links":["39897bdfbd63159a"],"x":295,"y":660,"wires":[["10a1afba81ed9dfe"]]},{"id":"a9794984be408a7a","type":"inject","z":"8430daf6e32c541b","name":"上午09点","props":[],"repeat":"","crontab":"00 09 * * *","once":false,"onceDelay":0.1,"topic":"","x":110,"y":1560,"wires":[["5ab7151c77c0d96a"]]},{"id":"2d5a6835696c462d","type":"api-current-state","z":"8430daf6e32c541b","name":"湿度","server":"c9ce0c5e564bed0a","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"sensor.esphome_web_107004_humidity","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"shidu","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"for":"0","forType":"num","forUnits":"seconds","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":310,"y":1660,"wires":[["2c559cac92d14e6c"]]},{"id":"5ab7151c77c0d96a","type":"api-current-state","z":"8430daf6e32c541b","name":"温度","server":"c9ce0c5e564bed0a","version":3,"outputs":1,"halt_if":"","halt_if_type":"num","halt_if_compare":"is","entity_id":"sensor.esphome_web_107004_temperature","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"wendu","propertyType":"msg","value":"","valueType":"entityState"}],"for":"0","forType":"num","forUnits":"seconds","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":310,"y":1580,"wires":[["2d5a6835696c462d"]]},{"id":"2c559cac92d14e6c","type":"delay","z":"8430daf6e32c541b","name":"","pauseType":"delay","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":520,"y":1580,"wires":[["abf7ad7473d8ac9f"]]},{"id":"abf7ad7473d8ac9f","type":"function","z":"8430daf6e32c541b","name":"加上时间","func":"// 获取当前时间\nvar now = new Date();\n// 将时间转换为北京时间(UTC+8)\nnow.setHours(now.getHours() + 8);\n// 格式化时间为 YYYY-MM-DD HH:mm:ss\nvar formattedDate = now.toISOString().replace('T', ' ').substring(0, 19);\n\n// 将格式化后的时间附加到消息负载\nmsg.payload = "定时提醒,当前温度" + msg.wendu + "度;当前湿度" + msg.shidu + "%;当前时间" + formattedDate;\n\n\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":520,"y":1660,"wires":[["ecfe47aae9ae4454"]]},{"id":"ecfe47aae9ae4454","type":"function","z":"8430daf6e32c541b","name":"生成请求内容","func":"msg.url = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=317427de-2f37-4822-996d-bb673e36136d";//替换为自己的webhook\nmsg.payload = {\n    "msgtype": "text",\n    "text": {\n        "content": msg.payload\n    }\n}\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":740,"y":1580,"wires":[["4eda728f9d296136","15b9c6883973d1ca"]]},{"id":"4eda728f9d296136","type":"http request","z":"8430daf6e32c541b","name":"","method":"POST","ret":"txt","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[],"x":720,"y":1640,"wires":[["8e7e2d5e475bb28c"]]},{"id":"8e7e2d5e475bb28c","type":"debug","z":"8430daf6e32c541b","name":"http返回","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":720,"y":1700,"wires":[]},{"id":"91a41f74fac9bfdf","type":"comment","z":"8430daf6e32c541b","name":"温度报警流程","info":"","x":90,"y":40,"wires":[]},{"id":"93d873aa4fe741f5","type":"comment","z":"8430daf6e32c541b","name":"生成微信消息上报","info":"","x":110,"y":620,"wires":[]},{"id":"5f77a85461e22256","type":"comment","z":"8430daf6e32c541b","name":"湿度报警流程","info":"","x":90,"y":860,"wires":[]},{"id":"f9a3472db5f7e05a","type":"comment","z":"8430daf6e32c541b","name":"正常温湿度提醒","info":"","x":100,"y":1480,"wires":[]},{"id":"3ea7349f873e01b7","type":"inject","z":"8430daf6e32c541b","name":"下午15点","props":[],"repeat":"","crontab":"00 15 * * *","once":false,"onceDelay":0.1,"topic":"","x":110,"y":1600,"wires":[["5ab7151c77c0d96a"]]},{"id":"b1b0564c0090d57d","type":"inject","z":"8430daf6e32c541b","name":"晚上10点","props":[],"repeat":"","crontab":"00 22 * * *","once":false,"onceDelay":0.1,"topic":"","x":110,"y":1640,"wires":[["5ab7151c77c0d96a"]]},{"id":"c82909b3e243cbf5","type":"comment","z":"8430daf6e32c541b","name":"测试传感器是否在线、","info":"","x":120,"y":1860,"wires":[]},{"id":"cc30945242abf155","type":"exec","z":"8430daf6e32c541b","command":"ping -c 4 192.168.31.72","addpay":"payload","append":"","useSpawn":"false","timer":"10","winHide":false,"oldrc":false,"name":"","x":270,"y":1920,"wires":[["718cab6fbedae811"],[],[]]},{"id":"4146438aa4f2b491","type":"inject","z":"8430daf6e32c541b","name":"","props":[],"repeat":"3600","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":90,"y":1920,"wires":[["cc30945242abf155"]]},{"id":"718cab6fbedae811","type":"function","z":"8430daf6e32c541b","name":"判断PING是否成功","func":"// 获取`exec`节点的输出\nvar output = msg.payload;\n\n// 解析`ping`命令的结果\nif (output.includes("0% packet loss")) {\n    // 如果没有丢包\n    msg.payload = "温湿度传感器:Ping成功: " + output;\n} else {\n    // 如果有丢包\n    msg.payload = "温湿度传感器:Ping失败: " + output;\n}\n\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":510,"y":1900,"wires":[["603c22b9273448a6"]]},{"id":"603c22b9273448a6","type":"switch","z":"8430daf6e32c541b","name":"Ping成功失败","property":"payload","propertyType":"msg","rules":[{"t":"cont","v":"Ping失败","vt":"str"},{"t":"cont","v":"Ping成功","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":500,"y":1960,"wires":[["3abcf77b4f97198f"],[]]},{"id":"3abcf77b4f97198f","type":"function","z":"8430daf6e32c541b","name":"加上时间","func":"// 获取当前时间\nvar now = new Date();\n// 将时间转换为北京时间(UTC+8)\nnow.setHours(now.getHours() + 8);\n// 格式化时间为 YYYY-MM-DD HH:mm:ss\nvar formattedDate = now.toISOString().replace('T', ' ').substring(0, 19);\n\n// 将格式化后的时间附加到消息负载\nmsg.payload = "当前时间" + formattedDate +";" + msg.payload;\n\n\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":760,"y":1900,"wires":[["b03598fb697a613d","1b8cec43c87a1490"]]},{"id":"b03598fb697a613d","type":"function","z":"8430daf6e32c541b","name":"生成请求内容","func":"msg.url = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=317427de-2f37-4822-996d-bb673e36136d";//替换为自己的webhook\nmsg.payload = {\n    "msgtype": "text",\n    "text": {\n        "content": msg.payload\n    }\n}\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":780,"y":1940,"wires":[["4eb5e83d97a774b8","15b9c6883973d1ca"]]},{"id":"4eb5e83d97a774b8","type":"http request","z":"8430daf6e32c541b","name":"","method":"POST","ret":"txt","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[],"x":760,"y":1980,"wires":[["96b1b60e17339f5d"]]},{"id":"96b1b60e17339f5d","type":"debug","z":"8430daf6e32c541b","name":"http返回","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":780,"y":2020,"wires":[]},{"id":"1b8cec43c87a1490","type":"debug","z":"8430daf6e32c541b","name":"debug 71","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":980,"y":1900,"wires":[]},{"id":"15b9c6883973d1ca","type":"file","z":"8430daf6e32c541b","name":"写入温度数据","filename":"/homeassistant/wendushuju/wendu.txt","filenameType":"str","appendNewline":true,"createDir":false,"overwriteFile":"false","encoding":"none","x":1200,"y":660,"wires":[["c6d5acb64053a1e4"]]},{"id":"c6d5acb64053a1e4","type":"debug","z":"8430daf6e32c541b","name":"debug 72","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1200,"y":720,"wires":[]},{"id":"9fc976716ad1afdc","type":"inject","z":"8430daf6e32c541b","name":"","props":[],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":90,"y":1520,"wires":[["5ab7151c77c0d96a"]]},{"id":"893f7a88e580a7df","type":"comment","z":"8430daf6e32c541b","name":"保存记录为TXT文件","info":"","x":1210,"y":620,"wires":[]},{"id":"c9ce0c5e564bed0a","type":"server","name":"Home Assistant","version":5,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":"30","areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"friendlyName","statusSeparator":": ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"default","statusTimeFormat":"h:m","enableGlobalContextStore":false}]






flows.zip

5.35 KB, 下载次数: 18

回复

使用道具 举报

2

主题

47

帖子

196

积分

注册会员

Rank: 2

积分
196
金钱
149
HASS币
0
发表于 2024-10-2 23:50:42 | 显示全部楼层
楼主,代码导入不了 出错了。
回复

使用道具 举报

5

主题

21

帖子

120

积分

注册会员

Rank: 2

积分
120
金钱
99
HASS币
0
 楼主| 发表于 2024-10-3 10:25:26 | 显示全部楼层
motohua 发表于 2024-10-2 23:50
楼主,代码导入不了 出错了。

语句不知道为什么会报错,上传了附件。
回复

使用道具 举报

2

主题

47

帖子

196

积分

注册会员

Rank: 2

积分
196
金钱
149
HASS币
0
发表于 2024-10-3 22:43:21 | 显示全部楼层
谢谢  学习一下
回复

使用道具 举报

10

主题

1372

帖子

4383

积分

论坛元老

Rank: 8Rank: 8

积分
4383
金钱
3011
HASS币
0
发表于 2024-10-4 12:09:58 | 显示全部楼层
寒夜吟 发表于 2024-10-3 10:25
语句不知道为什么会报错,上传了附件。

分享流尽量上传附件,直接上传代码,论坛会转义大小于号。
回复

使用道具 举报

0

主题

53

帖子

467

积分

中级会员

Rank: 3Rank: 3

积分
467
金钱
414
HASS币
0
发表于 2024-10-19 20:40:50 | 显示全部楼层
学习学习
      
回复

使用道具 举报

0

主题

21

帖子

64

积分

注册会员

Rank: 2

积分
64
金钱
43
HASS币
0
发表于 6 天前 | 显示全部楼层
学习学习
回复

使用道具 举报

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

本版积分规则

Archiver|手机版|小黑屋|Hassbian

GMT+8, 2024-12-22 12:05 , Processed in 0.056201 second(s), 31 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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