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

 找回密码
 立即注册
查看: 6023|回复: 10

[流程系列] 开门播报温湿度及唐诗

[复制链接]

4

主题

56

帖子

1226

积分

金牌会员

Rank: 6Rank: 6

积分
1226
金钱
1170
HASS币
0
QQ
发表于 2021-3-19 10:17:11 | 显示全部楼层 |阅读模式
学习了L大神的帖子https://bbs.hassbian.com/thread-6424-1-2.html,依葫芦画瓢,修改了几处,现在可以正常播报温湿度及唐诗(可以更改其他API),1,开门先检测人体【避免了离家及其他时间触发】,
2,再进行温湿度获取,,
3,判断光照是否开灯,
4,延时提醒门是否关闭,,
5,发送邮箱获取唐诗,

[{"id":"7c197322.4a461c","type":"tab","label":"开门播报温湿度","disabled":false,"info":""},{"id":"7f426214.3934ac","type":"api-current-state","z":"7c197322.4a461c","name":"获取室内温度","server":"5d51d3bd.9c86fc","version":1,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"sensor.4c65a8d0b061_temperature","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":980,"y":220,"wires":[["3be3eef7.4d5332"]]},{"id":"48b9cd54.e89c84","type":"api-current-state","z":"7c197322.4a461c","name":"获取室内湿度","server":"5d51d3bd.9c86fc","version":1,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"sensor.4c65a8d0b061_humidity","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":980,"y":280,"wires":[["d1a55952.33b9d8"]]},{"id":"3be3eef7.4d5332","type":"function","z":"7c197322.4a461c","name":"温度","func":"var result='';\nif(msg.data.state>=23){\n  result = msg.data.state + '摄氏度,炎热'; \n}\nelse if(msg.data.state>=18 && msg.data.state<=23){\n  result = msg.data.state + '摄氏度,舒适'; \n}\nelse if(msg.data.state>12 && msg.data.state<18){\n    result = msg.data.state + '摄氏度,较冷';\n}\nelse{\n    result = msg.data.state + '摄氏度,寒冷,请注意保暖';\n}\n\nmsg.payload = {"temperature":result};\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1170,"y":220,"wires":[["d1c941a9.52593"]]},{"id":"d1a55952.33b9d8","type":"function","z":"7c197322.4a461c","name":"湿度","func":"var result='';\nif(msg.data.state>=60){\n  result = msg.data.state + '潮湿'; \n}\nelse if(msg.data.state>30 && msg.data.state<60){\n    result = msg.data.state + '适中';\n}\nelse{\n    result = msg.data.state + '干燥';\n}\nmsg.payload = {"humidity":result};\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1170,"y":280,"wires":[["d1c941a9.52593"]]},{"id":"a583519b.c8397","type":"api-call-service","z":"7c197322.4a461c","name":"小爱播报","server":"5d51d3bd.9c86fc","version":1,"debugenabled":false,"service_domain":"hello_miai","service":"force_send","entityId":"","data":"","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":1500,"y":280,"wires":[["7c69c737.cca0f8"]]},{"id":"1bfadb64.9eb5a5","type":"function","z":"7c197322.4a461c","name":"播报内容","func":"var wisdom = flow.get('wisdom');\n\n\nvar message = `欢迎回家:现在室内温度${msg.payload.temperature},湿度为百分之${msg.payload.humidity}。${wisdom}`;\nmsg.payload = {};\nmsg.payload.data = {"message":message};\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1340,"y":280,"wires":[["a583519b.c8397"]]},{"id":"d1c941a9.52593","type":"join","z":"7c197322.4a461c","name":"合并对象","mode":"custom","build":"merged","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":1320,"y":240,"wires":[["1bfadb64.9eb5a5"]]},{"id":"7051732.489678c","type":"server-state-changed","z":"7c197322.4a461c","name":"监测大门状态","server":"5d51d3bd.9c86fc","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"binary_sensor.e4aaec372d90_contact","entityidfiltertype":"exact","outputinitially":true,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":false,"for":"","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"x":70,"y":340,"wires":[["b0d0837f.90c33"]]},{"id":"f2134b3d.fcfde8","type":"switch","z":"7c197322.4a461c","name":"大门新状态为开启","property":"data.new_state.state","propertyType":"msg","rules":[{"t":"eq","v":"on","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":450,"y":340,"wires":[["2deae646.e72e1a"]]},{"id":"b0d0837f.90c33","type":"switch","z":"7c197322.4a461c","name":"大门原状态为关闭","property":"data.old_state.state","propertyType":"msg","rules":[{"t":"eq","v":"off","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":250,"y":340,"wires":[["f2134b3d.fcfde8"]]},{"id":"45d250f3.aa2a6","type":"api-current-state","z":"7c197322.4a461c","name":"获取客厅光照度","server":"5d51d3bd.9c86fc","version":1,"outputs":2,"halt_if":"20","halt_if_type":"num","halt_if_compare":"lte","override_topic":false,"entity_id":"sensor.0x4cf8cdf3c7cbe0b_illuminance","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":980,"y":360,"wires":[["14bf6c6a.b51f94"],[]]},{"id":"80610ff5.d5bb8","type":"api-call-service","z":"7c197322.4a461c","name":"打开客厅灯","server":"5d51d3bd.9c86fc","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.74a34ad52dc8_light","data":"","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":1430,"y":360,"wires":[["7c69c737.cca0f8"]]},{"id":"9c104446.36be18","type":"api-call-service","z":"7c197322.4a461c","name":"小爱提醒门未关","server":"5d51d3bd.9c86fc","version":1,"debugenabled":false,"service_domain":"hello_miai","service":"add2msgqueue","entityId":"","data":"{"miai_num":0,"message":"大门未关,请查看"}","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":1220,"y":460,"wires":[["7c69c737.cca0f8"]]},{"id":"ea2db4d3.5c92b8","type":"comment","z":"7c197322.4a461c","name":"开门播报室内温湿度","info":"","x":110,"y":260,"wires":[]},{"id":"2deae646.e72e1a","type":"switch","z":"7c197322.4a461c","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"on","vt":"str"},{"t":"eq","v":"off","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":610,"y":340,"wires":[["413cdd72.968574","d6d351d1.e332e"],[]]},{"id":"14bf6c6a.b51f94","type":"api-current-state","z":"7c197322.4a461c","name":"判断客厅灯是否关闭","server":"5d51d3bd.9c86fc","version":1,"outputs":2,"halt_if":"off","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"light.74a34ad52dc8_light","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":1220,"y":360,"wires":[["80610ff5.d5bb8"],[]]},{"id":"d6d351d1.e332e","type":"api-current-state","z":"7c197322.4a461c","name":"判断家中是否有人","server":"5d51d3bd.9c86fc","version":1,"outputs":2,"halt_if":"off","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"binary_sensor.54ef44e1ec2d_motion","state_type":"str","state_location":"","override_payload":"none","entity_location":"","override_data":"none","blockInputOverrides":false,"x":730,"y":260,"wires":[["7f426214.3934ac","48b9cd54.e89c84","45d250f3.aa2a6"],[]]},{"id":"7c69c737.cca0f8","type":"e-mail","z":"7c197322.4a461c","server":"192.168.1.8","port":"25","secure":false,"tls":false,"name":"[email protected]","dname":"群晖node-red通知","x":1490,"y":640,"wires":[]},{"id":"29ae6f58.2f92f","type":"function","z":"7c197322.4a461c","name":"保存格言到flow变量","func":"flow.set('wisdom',msg.payload.title + msg.payload.author + msg.payload.lines);\nreturn null;","outputs":0,"noerr":0,"initialize":"","finalize":"","x":730,"y":80,"wires":[]},{"id":"7a8303dc.d7df8c","type":"inject","z":"7c197322.4a461c","name":"每小时获取一次唐诗","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"0 8-19 * * *","once":true,"onceDelay":0.1,"topic":"","payload":"{}","payloadType":"json","x":140,"y":80,"wires":[["79bdc8e1.b0ba18"]]},{"id":"73abf441.99b68c","type":"comment","z":"7c197322.4a461c","name":"获取名言flow变量","info":"flow变量名为 token\n获取方法 msg.access_token = flow.get('token');","x":97.83332824707031,"y":35.666561126708984,"wires":[]},{"id":"79bdc8e1.b0ba18","type":"http request","z":"7c197322.4a461c","name":"名言api","method":"GET","ret":"txt","paytoqs":"ignore","url":"http://gxy.me/tangshi?format=json","tls":"","persist":false,"proxy":"","authType":"","x":360,"y":80,"wires":[["af48674b.0d7588"]]},{"id":"af48674b.0d7588","type":"json","z":"7c197322.4a461c","name":"","property":"payload","action":"","pretty":false,"x":550,"y":80,"wires":[["29ae6f58.2f92f"]]},{"id":"1c19043d.30928c","type":"api-call-service","z":"7c197322.4a461c","name":"小爱TTS","server":"5d51d3bd.9c86fc","version":1,"debugenabled":false,"service_domain":"hello_miai","service":"add2msgqueue","entityId":"","data":"","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":1240,"y":540,"wires":[[]]},{"id":"246f0a69.091b56","type":"function","z":"7c197322.4a461c","name":"推送内容","func":"var message = flow.get('wisdom');\n\nmsg.payload = {};\nmsg.payload.data = {"message":message,"miai_num":"0"};\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1060,"y":540,"wires":[["1c19043d.30928c"]]},{"id":"413cdd72.968574","type":"delay","z":"7c197322.4a461c","name":"延迟8分钟","pauseType":"delay","timeout":"8","timeoutUnits":"minutes","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":710,"y":460,"wires":[["c239513e.34649"]]},{"id":"c239513e.34649","type":"api-current-state","z":"7c197322.4a461c","name":"大门","server":"5d51d3bd.9c86fc","version":1,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"binary_sensor.e4aaec372d90_contact","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":850,"y":460,"wires":[["3ca39684.91a6da"]]},{"id":"3ca39684.91a6da","type":"switch","z":"7c197322.4a461c","name":"大门状态","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"off","vt":"str"},{"t":"eq","v":"on","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":980,"y":460,"wires":[["9c104446.36be18"],[]]},{"id":"89c5efbc.d34ae","type":"server-state-changed","z":"7c197322.4a461c","name":"客厅无人状态","server":"5d51d3bd.9c86fc","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"binary_sensor.54ef44e1ec2d_motion","entityidfiltertype":"exact","outputinitially":true,"state_type":"str","haltifstate":"off","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"for":"10","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"x":90,"y":640,"wires":[["c80ad7f.cad7828"],[]]},{"id":"c80ad7f.cad7828","type":"api-current-state","z":"7c197322.4a461c","name":"判断客厅灯是否开启","server":"5d51d3bd.9c86fc","version":1,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"light.74a34ad52dc8_light","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":280,"y":640,"wires":[["8a9a9950.d0afa8"],[]]},{"id":"3d076971.47cab6","type":"api-call-service","z":"7c197322.4a461c","name":"客厅灯关闭","server":"5d51d3bd.9c86fc","version":1,"debugenabled":false,"service_domain":"light","service":"turn_off","entityId":"light.74a34ad52dc8_light","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":750,"y":640,"wires":[["7c69c737.cca0f8"]]},{"id":"8a9a9950.d0afa8","type":"api-current-state","z":"7c197322.4a461c","name":"再次判断是否有人","server":"5d51d3bd.9c86fc","version":1,"outputs":2,"halt_if":"off","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"binary_sensor.54ef44e1ec2d_motion","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":530,"y":640,"wires":[["3d076971.47cab6"],[]]},{"id":"5d51d3bd.9c86fc","type":"server","name":"金星中央城","legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]



整体图

整体图
下载 (1).png
下载 (2).png
回复

使用道具 举报

59

主题

731

帖子

4221

积分

论坛元老

Rank: 8Rank: 8

积分
4221
金钱
3485
HASS币
20
发表于 2021-3-19 11:49:37 | 显示全部楼层
奇怪了,我怎么导入不了
微信截图_20210319114904.png
回复

使用道具 举报

4

主题

56

帖子

1226

积分

金牌会员

Rank: 6Rank: 6

积分
1226
金钱
1170
HASS币
0
QQ
 楼主| 发表于 2021-3-19 14:49:12 | 显示全部楼层
guitengyue 发表于 2021-3-19 11:49
奇怪了,我怎么导入不了

之前我遇到同样问题,先把有问题的地方删除掉,导入后再编辑就可以了
回复

使用道具 举报

16

主题

222

帖子

1701

积分

金牌会员

Rank: 6Rank: 6

积分
1701
金钱
1479
HASS币
0
发表于 2021-3-19 18:05:12 | 显示全部楼层
本帖最后由 mengyu 于 2021-3-19 18:06 编辑
756641156 发表于 2021-3-19 14:49
之前我遇到同样问题,先把有问题的地方删除掉,导入后再编辑就可以了

一直删都有问题,能不能把你没问题的节点代码发出来研究一下,就想想上面那段获取名言的节点代码
回复

使用道具 举报

4

主题

56

帖子

1226

积分

金牌会员

Rank: 6Rank: 6

积分
1226
金钱
1170
HASS币
0
QQ
 楼主| 发表于 2021-3-19 21:00:54 | 显示全部楼层
mengyu 发表于 2021-3-19 18:05
一直删都有问题,能不能把你没问题的节点代码发出来研究一下,就想想上面那段获取名言的节点代码 ...

[{"id":"29ae6f58.2f92f","type":"function","z":"7c197322.4a461c","name":"保存格言到flow变量","func":"flow.set('wisdom',msg.payload.title + msg.payload.author + msg.payload.lines);\nreturn null;","outputs":0,"noerr":0,"initialize":"","finalize":"","x":750,"y":80,"wires":[]},{"id":"7a8303dc.d7df8c","type":"inject","z":"7c197322.4a461c","name":"每小时获取一次唐诗","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"0 8-19 * * *","once":false,"onceDelay":0.1,"topic":"","payload":"{}","payloadType":"json","x":140,"y":80,"wires":[["79bdc8e1.b0ba18"]]},{"id":"73abf441.99b68c","type":"comment","z":"7c197322.4a461c","name":"获取名言flow变量","info":"flow变量名为 token\n获取方法 msg.access_token = flow.get('token');","x":97.83332824707031,"y":35.666561126708984,"wires":[]},{"id":"79bdc8e1.b0ba18","type":"http request","z":"7c197322.4a461c","name":"API唐诗获取","method":"GET","ret":"txt","paytoqs":"ignore","url":"http://gxy.me/tangshi?format=json","tls":"","persist":false,"proxy":"","authType":"","x":330,"y":80,"wires":[["af48674b.0d7588"]]},{"id":"af48674b.0d7588","type":"json","z":"7c197322.4a461c","name":"JSON字符串与对象互转","property":"payload","action":"","pretty":false,"x":530,"y":80,"wires":[["29ae6f58.2f92f"]]}]
回复

使用道具 举报

32

主题

1993

帖子

5067

积分

论坛元老

Rank: 8Rank: 8

积分
5067
金钱
3074
HASS币
50
QQ
发表于 2021-3-19 22:56:39 | 显示全部楼层
学习了,谢谢分享。
我不生产技术,我只是技术的搬运工。
回复

使用道具 举报

16

主题

222

帖子

1701

积分

金牌会员

Rank: 6Rank: 6

积分
1701
金钱
1479
HASS币
0
发表于 2021-3-20 02:33:55 | 显示全部楼层
756641156 发表于 2021-3-19 21:00
[{"id":"29ae6f58.2f92f","type":"function","z":"7c197322.4a461c","name":"保存格言到flow变量","func" ...

谢了,哥们
回复

使用道具 举报

0

主题

11

帖子

118

积分

注册会员

Rank: 2

积分
118
金钱
107
HASS币
0
发表于 2021-9-2 22:54:59 | 显示全部楼层
新版本的nodered里  msg.payload = {"temperature":result} 这种格式导入不了了,得在剪贴板里改成 msg.payload = {\"temperature\":result} 才行
回复

使用道具 举报

0

主题

138

帖子

1295

积分

金牌会员

Rank: 6Rank: 6

积分
1295
金钱
1157
HASS币
0
发表于 2022-5-20 11:09:50 | 显示全部楼层
756641156 发表于 2021-3-19 21:00
[{"id":"29ae6f58.2f92f","type":"function","z":"7c197322.4a461c","name":"保存格言到flow变量","func" ...

你好能不呢把语音播报温度哪部分也分享一下好吗
回复

使用道具 举报

0

主题

17

帖子

206

积分

中级会员

Rank: 3Rank: 3

积分
206
金钱
189
HASS币
0
发表于 2023-5-20 17:27:34 来自手机 | 显示全部楼层
参考一下
回复

使用道具 举报

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

本版积分规则

Archiver|手机版|小黑屋|Hassbian

GMT+8, 2024-4-26 12:42 , Processed in 0.063243 second(s), 35 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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