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

 找回密码
 立即注册
查看: 4625|回复: 0

[流程系列] 发布写的第一个流程,小米墙贴控制小米窗帘开合

[复制链接]

20

主题

218

帖子

1466

积分

论坛DIY达人

积分
1466
金钱
1223
HASS币
100
发表于 2021-8-13 19:25:56 | 显示全部楼层 |阅读模式
本帖最后由 zro22 于 2021-8-13 19:29 编辑

在米家里面墙贴和窗帘关联之后 墙贴按一下窗帘开,在运行中再按会停止,再按一下窗帘会关闭。习惯了这个逻辑后转到HA自动化控制可以用窗帘是否再running状态决定打开,关闭,还是停止。
最近又搞上了node-red。
把这个流程用node-red实现了一下。
并把它做成了一个子程序,这样家里有多个窗帘的不用每个都复制修改一遍了。

里面每个窗帘对应有一个input_boolean的变量,这是在HA里面用的辅助变量,在NR里面直接用了,在NR里面弄全局变量也是可以实现的。

另外我家的窗户是内开窗,开窗之后如果打开关闭窗帘,有可能把窗帘卡在窗子里卡坏,所以流程里面增加了对是否开窗的判断,不需要的时候把两个变量保持空就可以了。

PIC20210813191622001.jpg
使用上很简单,双击流程把几个ID填到变量里面就行了,cover1_id 对应右键单击要控制的窗帘,cover2_id对应左键要控制的窗帘 bool1_id 和 bool2_id事先在HA里面创建好。
window1 window2是窗子感应,不需要保持为空就行。
另外如果想增加别的命令,自己修改子流程就好了,在switch里面加上去就行。
PIC20210813191826001.jpg
flows.json (13.98 KB, 下载次数: 13)
[{"id":"9ff8a6d747974ff6","type":"subflow","name":"墙贴控制窗帘","info":"","category":"","in":[{"x":180,"y":120,"wires":[]}],"out":[],"env":[{"name":"switch_id","type":"str","value":""},{"name":"cover1_id","type":"str","value":""},{"name":"bool1_id","type":"str","value":""},{"name":"cover2_id","type":"str","value":""},{"name":"bool2_id","type":"str","value":""},{"name":"control_id","type":"bool","value":"true"},{"name":"window1_id","type":"str","value":""},{"name":"window2_id","type":"str","value":""}],"meta":{},"color":"#DDAA99"},{"id":"d2bc37ad7db533bb","type":"server-state-changed","z":"9ff8a6d747974ff6","name":"墙贴动作","server":"3df55419.f637dc","version":3,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"${switch_id}","entityidfiltertype":"substring","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":false,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":220,"y":240,"wires":[["cfc420b976c63d48"]]},{"id":"cfc420b976c63d48","type":"switch","z":"9ff8a6d747974ff6","name":"右单击 \\n  左单击 \\n 左右一起","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"single_right","vt":"str"},{"t":"eq","v":"single_left","vt":"str"},{"t":"eq","v":"single_both","vt":"str"}],"checkall":"true","repair":false,"outputs":3,"x":380,"y":240,"wires":[["0dab354f0abfc76d"],["9e2333a19e0f85a6"],["124e9de73a0d9759","3debc7146877b9a9"]]},{"id":"9180646ad5e77e99","type":"api-call-service","z":"9ff8a6d747974ff6","name":"关cover1","server":"3df55419.f637dc","version":3,"debugenabled":false,"service_domain":"cover","service":"close_cover","entityId":"${cover1_id}","data":"","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1400,"y":60,"wires":[[]]},{"id":"8745ecc524c511a4","type":"api-current-state","z":"9ff8a6d747974ff6","name":"变量ON","server":"3df55419.f637dc","version":2,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","entity_id":"${bool1_id}","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":1200,"y":100,"wires":[["9180646ad5e77e99","646be2a9abc67fa1"],["8556cfac1e700f79","f43b2bdb906290c9"]]},{"id":"8556cfac1e700f79","type":"api-call-service","z":"9ff8a6d747974ff6","name":"开cover1","server":"3df55419.f637dc","version":3,"debugenabled":false,"service_domain":"cover","service":"open_cover","entityId":"${cover1_id}","data":"","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1400,"y":100,"wires":[[]]},{"id":"0dab354f0abfc76d","type":"api-current-state","z":"9ff8a6d747974ff6","name":"cover1是否运行","server":"3df55419.f637dc","version":2,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"${cover1_id}","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":580,"y":160,"wires":[["f69469c7b065c0fc"]]},{"id":"f69469c7b065c0fc","type":"switch","z":"9ff8a6d747974ff6","name":"","property":"data.attributes.running","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"str"},{"t":"eq","v":"1","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":695,"y":160,"wires":[["1b3e91d3313e8ed2"],["124e9de73a0d9759"]],"l":false},{"id":"124e9de73a0d9759","type":"api-call-service","z":"9ff8a6d747974ff6","name":"cover1停","server":"3df55419.f637dc","version":3,"debugenabled":false,"service_domain":"cover","service":"stop_cover","entityId":"${cover1_id}","data":"","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":820,"y":200,"wires":[[]]},{"id":"646be2a9abc67fa1","type":"api-call-service","z":"9ff8a6d747974ff6","name":"","server":"3df55419.f637dc","version":3,"debugenabled":false,"service_domain":"input_boolean","service":"turn_off","entityId":"${bool1_id}","data":"","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1460,"y":20,"wires":[[]]},{"id":"f43b2bdb906290c9","type":"api-call-service","z":"9ff8a6d747974ff6","name":"","server":"3df55419.f637dc","version":3,"debugenabled":false,"service_domain":"input_boolean","service":"turn_on","entityId":"${bool1_id}","data":"","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1460,"y":140,"wires":[[]]},{"id":"9e2333a19e0f85a6","type":"api-current-state","z":"9ff8a6d747974ff6","name":"cover2是否运行","server":"3df55419.f637dc","version":2,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"${cover2_id}","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":580,"y":340,"wires":[["51d5ac6faa167196"]]},{"id":"51d5ac6faa167196","type":"switch","z":"9ff8a6d747974ff6","name":"运行","property":"data.attributes.running","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"str"},{"t":"eq","v":"1","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":695,"y":340,"wires":[["335ba59daf68efca"],["3debc7146877b9a9"]],"l":false},{"id":"3ed077e0167e132a","type":"api-current-state","z":"9ff8a6d747974ff6","name":"变量ON","server":"3df55419.f637dc","version":2,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","entity_id":"${bool2_id}","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":1200,"y":300,"wires":[["ffe24767fa6bdedd","e4a2284e1586db94"],["f13fb0c746192ec3","f52d2d766f52883a"]]},{"id":"3debc7146877b9a9","type":"api-call-service","z":"9ff8a6d747974ff6","name":"cover2停","server":"3df55419.f637dc","version":3,"debugenabled":false,"service_domain":"cover","service":"stop_cover","entityId":"${cover2_id}","data":"","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":820,"y":400,"wires":[[]]},{"id":"f52d2d766f52883a","type":"api-call-service","z":"9ff8a6d747974ff6","name":"","server":"3df55419.f637dc","version":3,"debugenabled":false,"service_domain":"input_boolean","service":"turn_on","entityId":"${bool2_id}","data":"","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1460,"y":340,"wires":[[]]},{"id":"f13fb0c746192ec3","type":"api-call-service","z":"9ff8a6d747974ff6","name":"开cover2","server":"3df55419.f637dc","version":3,"debugenabled":false,"service_domain":"cover","service":"open_cover","entityId":"${cover2_id}","data":"","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1400,"y":300,"wires":[[]]},{"id":"ffe24767fa6bdedd","type":"api-call-service","z":"9ff8a6d747974ff6","name":"关cover2","server":"3df55419.f637dc","version":3,"debugenabled":false,"service_domain":"cover","service":"close_cover","entityId":"${cover2_id}","data":"","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1400,"y":260,"wires":[[]]},{"id":"e4a2284e1586db94","type":"api-call-service","z":"9ff8a6d747974ff6","name":"","server":"3df55419.f637dc","version":3,"debugenabled":false,"service_domain":"input_boolean","service":"turn_off","entityId":"${bool2_id}","data":"","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1460,"y":220,"wires":[[]]},{"id":"1b3e91d3313e8ed2","type":"function","z":"9ff8a6d747974ff6","name":"","func":"var window1_id = env.get("window1_id");\nif(window1_id.length>8)\n    msg.payload = 1;\nelse\n    msg.payload = 0;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":810,"y":100,"wires":[["5917f4950e4a0765"]]},{"id":"5917f4950e4a0765","type":"switch","z":"9ff8a6d747974ff6","name":"window1?","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"str"},{"t":"eq","v":"1","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":895,"y":100,"wires":[["8745ecc524c511a4"],["5a4e2f7e0bad7a13"]],"l":false},{"id":"5a4e2f7e0bad7a13","type":"api-current-state","z":"9ff8a6d747974ff6","name":"window1","server":"3df55419.f637dc","version":2,"outputs":2,"halt_if":"off","halt_if_type":"str","halt_if_compare":"is","entity_id":"${window1_id}","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":1000,"y":120,"wires":[["16bba4166c198d5d"],[]]},{"id":"16bba4166c198d5d","type":"function","z":"9ff8a6d747974ff6","name":"","func":"var window1_id = env.get("window2_id");\nif(window1_id.length>8)\n    msg.payload = 1;\nelse\n    msg.payload = 0;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":990,"y":160,"wires":[["919660324f5dd971"]]},{"id":"919660324f5dd971","type":"switch","z":"9ff8a6d747974ff6","name":"window1?","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"str"},{"t":"eq","v":"1","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":1075,"y":160,"wires":[["8745ecc524c511a4"],["8c8148c393eca10c"]],"l":false},{"id":"8c8148c393eca10c","type":"api-current-state","z":"9ff8a6d747974ff6","name":"window2","server":"3df55419.f637dc","version":2,"outputs":2,"halt_if":"off","halt_if_type":"str","halt_if_compare":"is","entity_id":"${window2_id}","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":1200,"y":160,"wires":[["8745ecc524c511a4"],[]]},{"id":"335ba59daf68efca","type":"function","z":"9ff8a6d747974ff6","name":"","func":"var window1_id = env.get("window1_id");\nif(window1_id.length>8)\n    msg.payload = 1;\nelse\n    msg.payload = 0;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":810,"y":300,"wires":[["a026b0acd4961e93"]]},{"id":"a026b0acd4961e93","type":"switch","z":"9ff8a6d747974ff6","name":"window1?","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"str"},{"t":"eq","v":"1","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":895,"y":300,"wires":[["3ed077e0167e132a"],["9fc1679c87e0957a"]],"l":false},{"id":"9fc1679c87e0957a","type":"api-current-state","z":"9ff8a6d747974ff6","name":"window1","server":"3df55419.f637dc","version":2,"outputs":2,"halt_if":"off","halt_if_type":"str","halt_if_compare":"is","entity_id":"${window1_id}","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":1000,"y":320,"wires":[["7688b73685449881"],[]]},{"id":"7688b73685449881","type":"function","z":"9ff8a6d747974ff6","name":"","func":"var window1_id = env.get("window2_id");\nif(window1_id.length>8)\n    msg.payload = 1;\nelse\n    msg.payload = 0;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":990,"y":360,"wires":[["40101865cbe72279"]]},{"id":"40101865cbe72279","type":"switch","z":"9ff8a6d747974ff6","name":"window1?","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"str"},{"t":"eq","v":"1","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":1075,"y":360,"wires":[["3ed077e0167e132a"],["f34ec8363768d63d"]],"l":false},{"id":"f34ec8363768d63d","type":"api-current-state","z":"9ff8a6d747974ff6","name":"window2","server":"3df55419.f637dc","version":2,"outputs":2,"halt_if":"off","halt_if_type":"str","halt_if_compare":"is","entity_id":"${window2_id}","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":1200,"y":360,"wires":[["3ed077e0167e132a"],[]]},{"id":"3df55419.f637dc","type":"server","name":"Home Assistant","version":1,"legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":false},{"id":"5f3aea8641fbab53","type":"subflow:9ff8a6d747974ff6","z":"a04dd43c.b52b18","name":"","x":1150,"y":340,"wires":[]}]



回复

使用道具 举报

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

本版积分规则

Archiver|手机版|小黑屋|Hassbian

GMT+8, 2024-12-22 16:56 , Processed in 0.063488 second(s), 25 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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