我平时比较少用空调,控制流程可能存在bug,如有问题或更优方式欢迎交流,以下直入主题
必要条件:
- X12刷入IRMQTT:X12 移动空调伴侣红外遥控插座改IRMQTT(分界线开始,无分享者不予审核)
- 接入泛艺智能:小爱同学(免破解免拆机)<-泛艺->米家-NodeRed虚拟设备自定义节点使用教程
流:
[{"id":"53ade57d.7f06ac","type":"tab","label":"空调","disabled":false,"info":""},{"id":"d70f054.d76b5f8","type":"mqtt in","z":"53ade57d.7f06ac","name":"当前模式","topic":"CMCC_1/ac/stat/mode","qos":"2","datatype":"auto","broker":"a1a10263.37476","x":75,"y":45,"wires":[["f38a755f.4c1ac8"]]},{"id":"6fb631b2.619d8","type":"mqtt in","z":"53ade57d.7f06ac","name":"扫风状态","topic":"CMCC_1/ac/stat/swingv","qos":"2","datatype":"auto","broker":"a1a10263.37476","x":75,"y":195,"wires":[["216ec59b.a82b3a"]]},{"id":"333e50d7.78784","type":"mqtt in","z":"53ade57d.7f06ac","name":"设定温度","topic":"CMCC_1/ac/stat/temp","qos":"2","datatype":"auto","broker":"a1a10263.37476","x":75,"y":95,"wires":[["2ef2d4cd.768d7c"]]},{"id":"5a1d6aab.2c0314","type":"mqtt in","z":"53ade57d.7f06ac","name":"设定风速","topic":"CMCC_1/ac/stat/fanspeed","qos":"2","datatype":"auto","broker":"a1a10263.37476","x":75,"y":145,"wires":[["1f800bc6.b671a4"]]},{"id":"7b9d0cb9.826d34","type":"SmartHome-Bot","z":"53ade57d.7f06ac","name":"空调","account":"a54ea4a2.b25908","jsonConfig":"6e96d7ad.b1bc48","deviceId":"DeviceId","auto":true,"x":70,"y":455,"wires":[[],["9969159c.06e638"]]},{"id":"c8ca4bf3.1f3788","type":"switch","z":"53ade57d.7f06ac","name":"","property":"payload","propertyType":"msg","rules":[{"t":"hask","v":"on","vt":"str"},{"t":"hask","v":"mode","vt":"str"},{"t":"hask","v":"target-temperature","vt":"str"},{"t":"hask","v":"sleep-mode","vt":"str"},{"t":"hask","v":"fan-level","vt":"str"},{"t":"hask","v":"horizontal-swing","vt":"str"}],"checkall":"true","repair":false,"outputs":6,"x":820,"y":455,"wires":[["ca5ff07f.70007"],["49ad2708.5a0b08"],["39829e.e9454d62"],["f928ed3f.7d015"],["fd139de8.a1b45"],["fb0ecb2c.319b88"]]},{"id":"92b063a6.934b2","type":"switch","z":"53ade57d.7f06ac","name":"模式","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"auto","vt":"str"},{"t":"eq","v":"cool","vt":"str"},{"t":"eq","v":"heat","vt":"str"},{"t":"eq","v":"fan_only","vt":"str"},{"t":"eq","v":"dry","vt":"str"}],"checkall":"true","repair":false,"outputs":5,"x":1130,"y":335,"wires":[["57d1a9be.f24e58"],["e03f7dcf.fd2da"],["b80da73d.90a268"],["2a4bf949.a82ff6"],["2ad28aab.250116"]]},{"id":"5c4efb24.e28664","type":"switch","z":"53ade57d.7f06ac","name":"风速","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"str"},{"t":"eq","v":"1","vt":"str"},{"t":"eq","v":"2","vt":"str"},{"t":"eq","v":"3","vt":"str"}],"checkall":"true","repair":false,"outputs":4,"x":1125,"y":560,"wires":[["623bfba9.644ab4"],["b9d7d4.e8be083"],["20f09e20.3ad1d2"],["51b7e8e4.abaa18"]]},{"id":"a8eea2ba.824a5","type":"mqtt out","z":"53ade57d.7f06ac","name":"温度调节","topic":"CMCC_1/ac/cmnd/temp","qos":"","retain":"","broker":"a1a10263.37476","x":1140,"y":435,"wires":[]},{"id":"39829e.e9454d62","type":"change","z":"53ade57d.7f06ac","name":"温度","rules":[{"t":"move","p":"payload.target-temperature","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1010,"y":435,"wires":[["a8eea2ba.824a5"]]},{"id":"57d1a9be.f24e58","type":"mqtt out","z":"53ade57d.7f06ac","name":"自动","topic":"CMCC_1/ac/cmnd/mode","qos":"","retain":"","broker":"a1a10263.37476","x":1295,"y":235,"wires":[]},{"id":"49ad2708.5a0b08","type":"change","z":"53ade57d.7f06ac","name":"模式","rules":[{"t":"move","p":"payload.mode","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1010,"y":335,"wires":[["92b063a6.934b2"]]},{"id":"e03f7dcf.fd2da","type":"mqtt out","z":"53ade57d.7f06ac","name":"制冷","topic":"CMCC_1/ac/cmnd/mode","qos":"","retain":"","broker":"a1a10263.37476","x":1295,"y":285,"wires":[]},{"id":"b80da73d.90a268","type":"mqtt out","z":"53ade57d.7f06ac","name":"制热","topic":"CMCC_1/ac/cmnd/mode","qos":"","retain":"","broker":"a1a10263.37476","x":1295,"y":335,"wires":[]},{"id":"2a4bf949.a82ff6","type":"mqtt out","z":"53ade57d.7f06ac","name":"送风","topic":"CMCC_1/ac/cmnd/mode","qos":"","retain":"","broker":"a1a10263.37476","x":1295,"y":385,"wires":[]},{"id":"2ad28aab.250116","type":"mqtt out","z":"53ade57d.7f06ac","name":"除湿","topic":"CMCC_1/ac/cmnd/mode","qos":"","retain":"","broker":"a1a10263.37476","x":1295,"y":435,"wires":[]},{"id":"fb55e3ff.f854b","type":"mqtt out","z":"53ade57d.7f06ac","name":"睡眠开关","topic":"CMCC_1/ac/cmnd/sleepmode","qos":"","retain":"","broker":"a1a10263.37476","x":1140,"y":485,"wires":[]},{"id":"f928ed3f.7d015","type":"change","z":"53ade57d.7f06ac","name":"睡眠","rules":[{"t":"move","p":"payload.sleep-mode","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1010,"y":485,"wires":[["fb55e3ff.f854b"]]},{"id":"fd139de8.a1b45","type":"change","z":"53ade57d.7f06ac","name":"风速","rules":[{"t":"move","p":"payload.fan-level","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1005,"y":560,"wires":[["5c4efb24.e28664"]]},{"id":"623bfba9.644ab4","type":"mqtt out","z":"53ade57d.7f06ac","name":"自动","topic":"CMCC_1/ac/cmnd/mode","qos":"","retain":"","broker":"a1a10263.37476","x":1300,"y":485,"wires":[]},{"id":"b9d7d4.e8be083","type":"mqtt out","z":"53ade57d.7f06ac","name":"低速","topic":"CMCC_1/ac/cmnd/mode","qos":"","retain":"","broker":"a1a10263.37476","x":1300,"y":535,"wires":[]},{"id":"20f09e20.3ad1d2","type":"mqtt out","z":"53ade57d.7f06ac","name":"中速","topic":"CMCC_1/ac/cmnd/mode","qos":"","retain":"","broker":"a1a10263.37476","x":1300,"y":585,"wires":[]},{"id":"51b7e8e4.abaa18","type":"mqtt out","z":"53ade57d.7f06ac","name":"高速","topic":"CMCC_1/ac/cmnd/mode","qos":"","retain":"","broker":"a1a10263.37476","x":1300,"y":635,"wires":[]},{"id":"d8fff43d.235d98","type":"comment","z":"53ade57d.7f06ac","name":"未支持","info":"","x":1150,"y":485,"wires":[]},{"id":"fb0ecb2c.319b88","type":"change","z":"53ade57d.7f06ac","name":"扫风","rules":[{"t":"move","p":"payload.horizontal-swing","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1005,"y":620,"wires":[["a5f157a0.67dac8"]]},{"id":"a5f157a0.67dac8","type":"mqtt out","z":"53ade57d.7f06ac","name":"扫风开关","topic":"CMCC_1/ac/cmnd/swingv","qos":"","retain":"","broker":"a1a10263.37476","x":1135,"y":620,"wires":[]},{"id":"ca5ff07f.70007","type":"switch","z":"53ade57d.7f06ac","name":"开关","property":"payload.on","propertyType":"msg","rules":[{"t":"true"},{"t":"false"}],"checkall":"true","repair":false,"outputs":2,"x":1010,"y":160,"wires":[["2f3d4171.184ede"],["99b50f5a.23801"]]},{"id":"5b84ce7e.d01b4","type":"mqtt out","z":"53ade57d.7f06ac","name":"自动","topic":"CMCC_1/ac/cmnd/power","qos":"","retain":"","broker":"a1a10263.37476","x":1295,"y":135,"wires":[]},{"id":"cf949a90.af1978","type":"mqtt out","z":"53ade57d.7f06ac","name":"自动","topic":"CMCC_1/ac/cmnd/power","qos":"","retain":"","broker":"a1a10263.37476","x":1300,"y":185,"wires":[]},{"id":"2f3d4171.184ede","type":"change","z":"53ade57d.7f06ac","name":"模式","rules":[{"t":"set","p":"payload","pt":"msg","to":"ON","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1160,"y":135,"wires":[["5b84ce7e.d01b4"]]},{"id":"99b50f5a.23801","type":"change","z":"53ade57d.7f06ac","name":"模式","rules":[{"t":"set","p":"payload","pt":"msg","to":"OFF","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1160,"y":185,"wires":[["cf949a90.af1978"]]},{"id":"777625fa.afec1c","type":"file in","z":"53ade57d.7f06ac","name":"","filename":"空调.ini","format":"utf8","chunk":false,"sendError":false,"encoding":"utf8","x":280,"y":355,"wires":[["d892784a.38e5f8"]]},{"id":"564c135.5dabfec","type":"switch","z":"53ade57d.7f06ac","name":"","property":"payload.on","propertyType":"msg","rules":[{"t":"false"}],"checkall":"true","repair":false,"outputs":1,"x":550,"y":355,"wires":[["9408696d.bad3e8"]]},{"id":"d79b882.4735078","type":"function","z":"53ade57d.7f06ac","name":"开机","func":"var FullJson = msg.payload;\n\nFullJson[\"on\"] = true;\n/*\nswitch(msg.payload.mode){\n case \"auto\":\n FullJson[\"mode\"] = 0;\n break;\n case \"cool\":\n FullJson[\"mode\"] = 1;\n break;\n case \"heat\":\n FullJson[\"mode\"] = 2;\n break;\n case \"fan_only\":\n FullJson[\"mode\"] = 3;\n break;\n case \"dry\":\n FullJson[\"mode\"] = 4;\n break;\n default:\n FullJson[\"mode\"] = 1;\n}\n*/\nswitch(msg.payload[2]){\n case \"Auto\":\n FullJson[\"fan-level\"] = 0;\n break;\n case \"Low\":\n FullJson[\"fan-level\"] = 1;\n break;\n case \"Medium\":\n FullJson[\"fan-level\"] = 2;\n break;\n case \"High\":\n FullJson[\"fan-level\"] = 3;\n break;\n case \"Min\":\n FullJson[\"fan-level\"] = 1;\n break;\n case \"Max\":\n FullJson[\"fan-level\"] = 3;\n break;\n default:\n FullJson[\"fan-level\"] = 1;\n}\nswitch(msg.payload[3]){\n case \"Auto\":\n FullJson[\"horizontal-swing\"]=true;\n break;\n case \"Off\":\n FullJson[\"horizontal-swing\"]=false;\n}\nmsg.payload=FullJson;\nreturn msg;","outputs":1,"noerr":0,"x":815,"y":355,"wires":[["49ad2708.5a0b08","39829e.e9454d62","ca5ff07f.70007","fd139de8.a1b45","fb0ecb2c.319b88"]]},{"id":"c3f73f6f.f0cb1","type":"inject","z":"53ade57d.7f06ac","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":100,"y":355,"wires":[["777625fa.afec1c"]]},{"id":"2ef2d4cd.768d7c","type":"function","z":"53ade57d.7f06ac","name":"","func":"//var json={};\n//json[\"targettemperature\"]=msg.payload;\n//msg.json = json;\n//return msg;\nmsg.json = \"target-temperature:\" + msg.payload;\nreturn msg;","outputs":1,"noerr":0,"x":220,"y":95,"wires":[["16b90bf1.398ac4"]]},{"id":"f38a755f.4c1ac8","type":"function","z":"53ade57d.7f06ac","name":"","func":"//var json={};\n//json[\"mode\"]=msg.payload;\n//msg.json = json;\nmsg.json = \"mode:\" + msg.payload;\nreturn msg;","outputs":1,"noerr":0,"x":220,"y":45,"wires":[["c28f5334.8d77f"]]},{"id":"1f800bc6.b671a4","type":"function","z":"53ade57d.7f06ac","name":"","func":"//var json={};\n//json[\"fanspeed\"]=msg.payload;\n//msg.json = json;\n//return msg;\nmsg.json = \"fan-level:\" + msg.payload;\nreturn msg;","outputs":1,"noerr":0,"x":220,"y":145,"wires":[["16b90bf1.398ac4"]]},{"id":"216ec59b.a82b3a","type":"function","z":"53ade57d.7f06ac","name":"","func":"//var json={};\n//json[\"swingv\"]=msg.payload;\n//msg.json = json;\n//return msg;\nmsg.json = \"horizontal-swing:\" + msg.payload;\nreturn msg;","outputs":1,"noerr":0,"x":220,"y":195,"wires":[["16b90bf1.398ac4"]]},{"id":"748ff500.de92dc","type":"catch","z":"53ade57d.7f06ac","name":"文件不存在","scope":["244c0956.b1dc96","16b90bf1.398ac4"],"uncaught":false,"x":80,"y":250,"wires":[["331ab7ae.102fb8"]]},{"id":"244c0956.b1dc96","type":"function","z":"53ade57d.7f06ac","name":"","func":"var FullJson={};\nvar Key=msg.json.split(\":\")[0];\nFullJson=JSON.parse(msg.payload);\nif(Key==\"mode\" & msg.json.split(\":\")[1]==\"off\"){\n FullJson[\"on\"]=false;\n}else{\n FullJson[Key]=msg.json.split(\":\")[1];\n FullJson[\"on\"]=true;\n}\nmsg.payload=FullJson;\nreturn msg;","outputs":1,"noerr":0,"x":545,"y":120,"wires":[["32a80783.5a2fe8"]]},{"id":"16b90bf1.398ac4","type":"file in","z":"53ade57d.7f06ac","name":"","filename":"空调.ini","format":"utf8","chunk":false,"sendError":false,"encoding":"utf8","x":400,"y":120,"wires":[["244c0956.b1dc96"]]},{"id":"f28e482c.d336b8","type":"file","z":"53ade57d.7f06ac","name":"","filename":"空调.ini","appendNewline":false,"createDir":false,"overwriteFile":"true","encoding":"utf8","x":350,"y":250,"wires":[["16b90bf1.398ac4"]]},{"id":"331ab7ae.102fb8","type":"change","z":"53ade57d.7f06ac","name":"初始化","rules":[{"t":"set","p":"payload","pt":"msg","to":"{\"mode\":\"auto\",\"target-temperature\":25,\"fan-level\":\"Min\",\"horizontal-swing\":true,\"on\":false}","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":220,"y":250,"wires":[["f28e482c.d336b8"]]},{"id":"32a80783.5a2fe8","type":"file","z":"53ade57d.7f06ac","name":"","filename":"空调.ini","appendNewline":false,"createDir":false,"overwriteFile":"true","encoding":"utf8","x":695,"y":120,"wires":[["2b3bb291.85bc9e"]]},{"id":"d892784a.38e5f8","type":"function","z":"53ade57d.7f06ac","name":"","func":"var FullJson={};\nFullJson=JSON.parse(msg.payload);\nif(msg.temp>0){\n FullJson[\"target-temperature\"]=msg.temp;\n}\nmsg.payload=FullJson;\nreturn msg;","outputs":1,"noerr":0,"x":415,"y":355,"wires":[["564c135.5dabfec"]]},{"id":"9408696d.bad3e8","type":"change","z":"53ade57d.7f06ac","name":"打开","rules":[{"t":"change","p":"payload.on","pt":"msg","from":"false","fromt":"bool","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":680,"y":355,"wires":[["d79b882.4735078"]]},{"id":"c28f5334.8d77f","type":"delay","z":"53ade57d.7f06ac","name":"50ms","pauseType":"delay","timeout":"50","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":345,"y":45,"wires":[["16b90bf1.398ac4"]]},{"id":"6d9380c6.c74f","type":"switch","z":"53ade57d.7f06ac","name":"","property":"payload","propertyType":"msg","rules":[{"t":"hask","v":"target-temperature","vt":"str"},{"t":"hask","v":"mode","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":3,"x":295,"y":435,"wires":[["375c8a2f.ab3276"],["56614a75.d7bc24"],["ce2f331d.bfb72"]]},{"id":"b301de23.181b3","type":"change","z":"53ade57d.7f06ac","name":"温度","rules":[{"t":"set","p":"temp","pt":"msg","to":"payload.target-temperature","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":110,"y":315,"wires":[["777625fa.afec1c"]]},{"id":"56614a75.d7bc24","type":"link out","z":"53ade57d.7f06ac","name":"","links":["c1ebc43b.ead4b8"],"x":385,"y":435,"wires":[]},{"id":"c1ebc43b.ead4b8","type":"link in","z":"53ade57d.7f06ac","name":"","links":["56614a75.d7bc24"],"x":935,"y":290,"wires":[["31d12385.390b2c"]]},{"id":"2b3bb291.85bc9e","type":"debug","z":"53ade57d.7f06ac","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":845,"y":120,"wires":[]},{"id":"31d12385.390b2c","type":"function","z":"53ade57d.7f06ac","name":"","func":"var FullJson = msg.payload;\nswitch(msg.payload.mode){\n case 0:\n FullJson[\"mode\"] = \"auto\";\n break;\n case 1:\n FullJson[\"mode\"] = \"cool\";\n break;\n case 2:\n FullJson[\"mode\"] = \"heat\";\n break;\n case 3:\n FullJson[\"mode\"] = \"fan_only\";\n break;\n case 4:\n FullJson[\"mode\"] = \"dry\";\n}\nreturn msg;","outputs":1,"noerr":0,"x":1010,"y":290,"wires":[["49ad2708.5a0b08"]]},{"id":"9969159c.06e638","type":"link out","z":"53ade57d.7f06ac","name":"","links":["f67a8b07.caaf18","737986b0.1c3118"],"x":145,"y":455,"wires":[]},{"id":"f67a8b07.caaf18","type":"link in","z":"53ade57d.7f06ac","name":"","links":["9969159c.06e638"],"x":730,"y":455,"wires":[["c8ca4bf3.1f3788"]]},{"id":"737986b0.1c3118","type":"link in","z":"53ade57d.7f06ac","name":"","links":["9969159c.06e638"],"x":225,"y":435,"wires":[["6d9380c6.c74f"]]},{"id":"ce2f331d.bfb72","type":"link out","z":"53ade57d.7f06ac","name":"","links":["ffbc5252.e214f"],"x":385,"y":470,"wires":[]},{"id":"ffbc5252.e214f","type":"link in","z":"53ade57d.7f06ac","name":"","links":["ce2f331d.bfb72"],"x":145,"y":395,"wires":[["777625fa.afec1c"]]},{"id":"375c8a2f.ab3276","type":"link out","z":"53ade57d.7f06ac","name":"","links":["6997ac94.eba714"],"x":385,"y":400,"wires":[]},{"id":"6997ac94.eba714","type":"link in","z":"53ade57d.7f06ac","name":"","links":["375c8a2f.ab3276"],"x":35,"y":315,"wires":[["b301de23.181b3"]]},{"id":"a1a10263.37476","type":"mqtt-broker","z":"","name":"","broker":"192.168.50.121","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"a54ea4a2.b25908","type":"SmartHome-Bot-Account","z":"","name":"默认配置"},{"id":"6e96d7ad.b1bc48","type":"SmartHome-Bot-Config","z":"","name":"空调","jsonConfig":"{\n \"2\": {\n \"1\": \"on\",\n \"2\": \"mode\",\n \"3\": \"fault\",\n \"4\": \"target-temperature\",\n \"5\": \"status\",\n \"6\": \"target-humidity\",\n \"7\": \"eco\",\n \"9\": \"heater\",\n \"10\": \"dryer\",\n \"11\": \"sleep-mode\"\n },\n \"3\": {\n \"1\": \"on\",\n \"2\": \"fan-level\",\n \"3\": \"horizontal-swing\",\n \"4\": \"vertical-swing\"\n },\n \"4\": {\n \"7\": \"temperature\",\n \"1\": \"relative-humidity\",\n \"4\": \"pm2.5-density\",\n \"6\": \"atmospheric-pressure\"\n },\n \"6\": {\n \"1\": \"on\"\n }\n}"}]
预览图