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

 找回密码
 立即注册

[教程系列] 沉迷NR无法自拔第一帖:使用函数简化程序

  [复制链接]

0

主题

187

帖子

1191

积分

金牌会员

Rank: 6Rank: 6

积分
1191
金钱
1004
HASS币
0
发表于 2019-7-21 21:21:38 | 显示全部楼层
学习一下
回复

使用道具 举报

20

主题

348

帖子

2541

积分

金牌会员

Rank: 6Rank: 6

积分
2541
金钱
2193
HASS币
0
发表于 2019-7-22 07:54:33 | 显示全部楼层
这个挺高级
回复

使用道具 举报

2

主题

59

帖子

217

积分

论坛积极会员

积分
217
金钱
158
HASS币
0
发表于 2019-7-23 18:33:09 | 显示全部楼层
感谢分享 学习                                          
回复

使用道具 举报

2

主题

287

帖子

996

积分

论坛积极会员

积分
996
金钱
709
HASS币
0
发表于 2019-7-23 20:14:49 | 显示全部楼层
简化成这样厉害了
回复

使用道具 举报

0

主题

21

帖子

88

积分

注册会员

Rank: 2

积分
88
金钱
67
HASS币
0
发表于 2019-7-26 13:10:27 | 显示全部楼层
感谢作者
回复

使用道具 举报

26

主题

304

帖子

1670

积分

金牌会员

Rank: 6Rank: 6

积分
1670
金钱
1366
HASS币
0
发表于 2019-7-28 16:10:09 | 显示全部楼层
学习学习!!
回复

使用道具 举报

0

主题

18

帖子

134

积分

注册会员

Rank: 2

积分
134
金钱
116
HASS币
0
发表于 2019-7-29 09:17:38 来自手机 | 显示全部楼层
感谢楼主分享
回复

使用道具 举报

0

主题

69

帖子

483

积分

中级会员

Rank: 3Rank: 3

积分
483
金钱
414
HASS币
0
发表于 2019-7-29 11:22:32 | 显示全部楼层

感謝樓主分享~~~~~
回复

使用道具 举报

0

主题

32

帖子

114

积分

注册会员

Rank: 2

积分
114
金钱
82
HASS币
0
发表于 2019-8-1 12:18:29 | 显示全部楼层
[{"id":"a3997102.a99ae","type":"function","z":"bdf6fb07.64fd48","name":"保存格言到flow变量","func":"flow.set('wisdom',msg.payload.info + msg.payload.author);\nreturn null;","outputs":0,"noerr":0,"x":2530,"y":4220,"wires":[]},{"id":"f06e376.5aeb3c8","type":"inject","z":"bdf6fb07.64fd48","name":"每小时获取一次名言","topic":"","payload":"{}","payloadType":"json","repeat":"3600","crontab":"","once":true,"onceDelay":0.1,"x":1920,"y":4220,"wires":[["7cb2402.cc4ffc"]]},{"id":"2059008f.5f398","type":"comment","z":"bdf6fb07.64fd48","name":"获取名言flow变量","info":"flow变量名为 token\n获取方法 msg.access_token = flow.get('token');","x":1897.8333282470703,"y":4175.666561126709,"wires":[]},{"id":"7cb2402.cc4ffc","type":"http request","z":"bdf6fb07.64fd48","name":"名言api","method":"GET","ret":"txt","url":"http://api.bunian.cn/yulu/?fun=json","tls":"","x":2160,"y":4220,"wires":[["890e20cf.7c3a8"]]},{"id":"890e20cf.7c3a8","type":"json","z":"bdf6fb07.64fd48","name":"","property":"payload","action":"","pretty":false,"x":2350,"y":4220,"wires":[["a3997102.a99ae"]]},{"id":"7f426214.3934ac","type":"api-current-state","z":"bdf6fb07.64fd48","name":"获取室内温度","server":"94f0c0a9.629b6","outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":true,"entity_id":"sensor.temperature_158d0000fd539c","state_type":"str","override_payload":true,"override_data":true,"x":2880,"y":4320,"wires":[["3be3eef7.4d5332","aa8942b8.c7e5c"]]},{"id":"48b9cd54.e89c84","type":"api-current-state","z":"bdf6fb07.64fd48","name":"获取室内湿度","server":"94f0c0a9.629b6","outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":true,"entity_id":"sensor.humidity_158d0000fd539c","state_type":"str","override_payload":true,"override_data":true,"x":2880,"y":4380,"wires":[["d1a55952.33b9d8"]]},{"id":"3be3eef7.4d5332","type":"function","z":"bdf6fb07.64fd48","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,"x":3070,"y":4320,"wires":[["d1c941a9.52593"]]},{"id":"d1a55952.33b9d8","type":"function","z":"bdf6fb07.64fd48","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,"x":3070,"y":4380,"wires":[["d1c941a9.52593"]]},{"id":"a583519b.c8397","type":"api-call-service","z":"bdf6fb07.64fd48","name":"小爱TTS","server":"94f0c0a9.629b6","service_domain":"hello_miai","service":"add2msgqueue","data":"","render_data":false,"mergecontext":"","output_location":"payload","output_location_type":"msg","x":3640,"y":4360,"wires":[[]]},{"id":"1bfadb64.9eb5a5","type":"function","z":"bdf6fb07.64fd48","name":"TTS内容","func":"var wisdom = flow.get('wisdom');\n\n\nvar message = `欢迎回家:现在室内温度${msg.payload.temperature},湿度为百分之${msg.payload.humidity}。${wisdom}`;\nmsg.payload = {};\nmsg.payload.data = {"message":message,"miai_num":"0"};\nreturn msg;","outputs":1,"noerr":0,"x":3420,"y":4360,"wires":[["a583519b.c8397","71d25351.12058c"]]},{"id":"d1c941a9.52593","type":"join","z":"bdf6fb07.64fd48","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":3270,"y":4360,"wires":[["1bfadb64.9eb5a5"]]},{"id":"71d25351.12058c","type":"debug","z":"bdf6fb07.64fd48","name":"调式信息","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":3620,"y":4420,"wires":[]},{"id":"7051732.489678c","type":"server-state-changed","z":"bdf6fb07.64fd48","name":"监测大门状态","server":"94f0c0a9.629b6","entityidfilter":"binary_sensor.door_window_sensor_158d0000d6de14","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"x":1870,"y":4400,"wires":[["b0d0837f.90c33"]]},{"id":"f2134b3d.fcfde8","type":"switch","z":"bdf6fb07.64fd48","name":"大门新状态为开启","property":"data.new_state.state","propertyType":"msg","rules":[{"t":"eq","v":"on","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":2330,"y":4400,"wires":[["3ae5dab8.d82b16"]]},{"id":"b0d0837f.90c33","type":"switch","z":"bdf6fb07.64fd48","name":"大门原状态为关闭","property":"data.old_state.state","propertyType":"msg","rules":[{"t":"eq","v":"off","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":2110,"y":4400,"wires":[["f2134b3d.fcfde8"]]},{"id":"45d250f3.aa2a6","type":"api-current-state","z":"bdf6fb07.64fd48","name":"获取客厅光照度","server":"94f0c0a9.629b6","outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":true,"entity_id":"sensor.illumination_158d0001a2520d","state_type":"str","override_payload":true,"override_data":true,"x":2880,"y":4440,"wires":[["c72b5594.329e38"]]},{"id":"c72b5594.329e38","type":"switch","z":"bdf6fb07.64fd48","name":"低于20lx","property":"payload","propertyType":"msg","rules":[{"t":"lt","v":"20.0","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":3100,"y":4440,"wires":[["80610ff5.d5bb8"]]},{"id":"80610ff5.d5bb8","type":"api-call-service","z":"bdf6fb07.64fd48","name":"打开客厅灯","server":"94f0c0a9.629b6","service_domain":"switch","service":"turn_on","data":"{"entity_id":"switch.wall_switch_right_158d00014cf47a"}","render_data":false,"mergecontext":"","x":3290,"y":4440,"wires":[[]]},{"id":"9c104446.36be18","type":"api-call-service","z":"bdf6fb07.64fd48","name":"小爱TTS","server":"94f0c0a9.629b6","service_domain":"hello_miai","service":"add2msgqueue","data":"","render_data":false,"mergecontext":"","x":3220,"y":4540,"wires":[[]]},{"id":"44aea020.1882d","type":"function","z":"bdf6fb07.64fd48","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,"x":2880,"y":4540,"wires":[["83b8982b.a5dae8"]]},{"id":"83b8982b.a5dae8","type":"trigger","z":"bdf6fb07.64fd48","op1":"","op2":"","op1type":"pay","op2type":"nul","duration":"10","extend":false,"units":"min","reset":"","bytopic":"all","name":"","x":3050,"y":4540,"wires":[["9c104446.36be18"]]},{"id":"ea2db4d3.5c92b8","type":"comment","z":"bdf6fb07.64fd48","name":"开门播报室内温湿度","info":"","x":1897.7777709960938,"y":4334.4443359375,"wires":[]},{"id":"3ae5dab8.d82b16","type":"api-current-state","z":"bdf6fb07.64fd48","name":"防盗门状态","server":"94f0c0a9.629b6","outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":true,"entity_id":"binary_sensor.door_window_sensor_158d0001f34db6","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":2490,"y":4320,"wires":[["2deae646.e72e1a"]]},{"id":"2deae646.e72e1a","type":"switch","z":"bdf6fb07.64fd48","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":2630,"y":4380,"wires":[["7f426214.3934ac","48b9cd54.e89c84","45d250f3.aa2a6"],["44aea020.1882d"]]},{"id":"aa8942b8.c7e5c","type":"debug","z":"bdf6fb07.64fd48","name":"调式信息","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":3040,"y":4260,"wires":[]},{"id":"94f0c0a9.629b6","type":"server","z":"","name":"Home Assistant","legacy":true,"hassio":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open"}]
回复

使用道具 举报

8

主题

152

帖子

649

积分

论坛技术达人

积分
649
金钱
497
HASS币
0
发表于 2019-8-18 22:15:14 | 显示全部楼层
牛逼了,学习一下这个
回复

使用道具 举报

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

本版积分规则

Archiver|手机版|小黑屋|Hassbian

GMT+8, 2024-11-15 15:54 , Processed in 0.177813 second(s), 30 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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