分享homeassistant平台下米家无线开关(aqara)接入nodered的一种简单方法

最近想在nodered里面写一个米家无线开关通过单击、双击和长按分别控制不同设备的流程,由于未部署zigbee2mqtt,直接使用“events.state”只能识别长按控制,自己摸索得出以下一种可行的方法:

通过“events. all”获取所有响应,然后利用“switch”筛选得到米家无线开关的三种操作,然后控制相应设备。

直接将以下流程导入nodered,修改home assistant节点,将3个“debug”节点改为所需控制的设备即可。

1

[{"id":"78565084.ee811","type":"server-events","z":"c664d627.55cbd8","name":"","server":"164d90f8.13f0ff","event_type":"","exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"x":110,"y":830,"wires":[["99e60e2.006d7f"]]},{"id":"99e60e2.006d7f","type":"switch","z":"c664d627.55cbd8","name":"","property":"payload.event_type","propertyType":"msg","rules":[{"t":"eq","v":"xiaomi_aqara.click","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":245,"y":830,"wires":[["cc22f929.4ee3d8"]]},{"id":"cc22f929.4ee3d8","type":"switch","z":"c664d627.55cbd8","name":"","property":"payload.event.click_type","propertyType":"msg","rules":[{"t":"eq","v":"single","vt":"str"},{"t":"eq","v":"double","vt":"str"},{"t":"eq","v":"hold","vt":"str"}],"checkall":"true","repair":false,"outputs":3,"x":375,"y":830,"wires":[["b8f0a200.fa301"],["348d780.05dda88"],["5d3dbd88.d6e994"]]},{"id":"b8f0a200.fa301","type":"debug","z":"c664d627.55cbd8","name":"单击操作","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":515,"y":795,"wires":[]},{"id":"348d780.05dda88","type":"debug","z":"c664d627.55cbd8","name":"双击操作","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":515,"y":830,"wires":[]},{"id":"5d3dbd88.d6e994","type":"debug","z":"c664d627.55cbd8","name":"长按操作","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":515,"y":865,"wires":[]},{"id":"164d90f8.13f0ff","type":"server","z":"","name":"Home Assistant","legacy":false,"addon":false,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]

2020-5-23 更新超级接入方式,实现无限可能
image
需要安装节点:node-red-contrib-stoptimer2
其中操作间隔可以在“1秒内继续操作”节点内调整,如需添加更多操作方式, 直接在“操作”节点内添加即可,操作分隔符为“|”,流如下:

[{"id":"6d37bac.4698c44","type":"switch","z":"8ca1187f.d27658","name":"","property":"payload.entity_id","propertyType":"msg","rules":[{"t":"eq","v":"binary_sensor.switch_158d000251a6d7","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":235,"y":1070,"wires":[["b3f9373c.a8f6c8"]]},{"id":"b3f9373c.a8f6c8","type":"switch","z":"8ca1187f.d27658","name":"","property":"payload.event.click_type","propertyType":"msg","rules":[{"t":"eq","v":"single","vt":"str"},{"t":"eq","v":"double","vt":"str"},{"t":"eq","v":"hold","vt":"str"}],"checkall":"true","repair":false,"outputs":3,"x":360,"y":1070,"wires":[["bcb5890e.9808f8"],["bcb5890e.9808f8"],["bcb5890e.9808f8"]]},{"id":"1cc67554.bc007b","type":"server-events","z":"8ca1187f.d27658","name":"","server":"2b9fcf19.b8098","event_type":"","exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"x":100,"y":1070,"wires":[["6d37bac.4698c44"]]},{"id":"701ae7fa.8e5bf8","type":"stoptimer2","z":"8ca1187f.d27658","duration":"1","durationType":"num","units":"Second","payloadtype":"num","payloadval":"","name":"1秒内继续操作","x":675,"y":1070,"wires":[["7ad96635.bb8cc8","a1c6e849.ba97a8"],[]]},{"id":"bcb5890e.9808f8","type":"function","z":"8ca1187f.d27658","name":"","func":"var click_type_temp = global.get('click_type_temp')||\"\";\nclick_type_temp = click_type_temp + msg.payload.event.click_type + \"|\";\nglobal.set('click_type_temp',click_type_temp);\nmsg.payload = click_type_temp;\nnode.status({fill:\"green\",shape:\"dot\",text:msg.payload});\nreturn msg;","outputs":1,"noerr":0,"x":510,"y":1070,"wires":[["701ae7fa.8e5bf8"]]},{"id":"7ad96635.bb8cc8","type":"change","z":"8ca1187f.d27658","name":"重置","rules":[{"t":"delete","p":"click_type_temp","pt":"global"}],"action":"","property":"","from":"","to":"","reg":false,"x":830,"y":1010,"wires":[[]]},{"id":"a1c6e849.ba97a8","type":"switch","z":"8ca1187f.d27658","name":"操作","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"single|","vt":"str"},{"t":"eq","v":"double|","vt":"str"},{"t":"eq","v":"hold|","vt":"str"},{"t":"eq","v":"double|double|","vt":"str"}],"checkall":"true","repair":false,"outputs":4,"x":830,"y":1070,"wires":[["7a6b56a5.8ed678"],["cd594fcd.cc3f3"],["9412c592.3f5a18"],["1cc6463c.73a7ca"]]},{"id":"7a6b56a5.8ed678","type":"debug","z":"8ca1187f.d27658","name":"单击","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":985,"y":1030,"wires":[]},{"id":"cd594fcd.cc3f3","type":"debug","z":"8ca1187f.d27658","name":"双击","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":985,"y":1070,"wires":[]},{"id":"9412c592.3f5a18","type":"debug","z":"8ca1187f.d27658","name":"长按","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":985,"y":1110,"wires":[]},{"id":"1cc6463c.73a7ca","type":"debug","z":"8ca1187f.d27658","name":"双击+双击(双击后1秒内再次双击)","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":1085,"y":1150,"wires":[]},{"id":"2b9fcf19.b8098","type":"server","z":"","name":"Home Assistant","legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]

感谢大神分享。
不知道第一个switch节点是否可以不用呢?直接把 xiaomi_aqara.click 这个填入event:all里边的event type栏里应该就可以把?

请问一下如果是其他品牌的无线开关,那event type 要写什么?这个要怎么知道写什么才能控制相应的设备?