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

 找回密码
 立即注册
楼主: raspberry0316

[进阶教程] 小爱同学控制HA设备-免费-无需破解-有手就行

  [复制链接]

1

主题

88

帖子

777

积分

高级会员

Rank: 4

积分
777
金钱
689
HASS币
0
发表于 2021-9-5 23:33:22 | 显示全部楼层

老哥。求流分享下!谢谢!
回复

使用道具 举报

0

主题

36

帖子

2010

积分

金牌会员

Rank: 6Rank: 6

积分
2010
金钱
1974
HASS币
0
发表于 2021-9-6 00:04:38 | 显示全部楼层
又学了一招,谢了
回复

使用道具 举报

11

主题

121

帖子

840

积分

论坛技术达人

积分
840
金钱
709
HASS币
60
发表于 2021-9-7 10:28:29 | 显示全部楼层
本帖最后由 yinzhennan 于 2021-9-8 10:26 编辑
karl321 发表于 2021-9-5 23:33
老哥。求流分享下!谢谢!
[{"id":"f1abf855.787a58","type":"link in","z":"414d4512.baec7c","name":"开空调","links":["d07bd3e3.8b222"],"x":35,"y":280,"wires":[["8f5b76c8.844c48"]]},{"id":"6dac8474.55203c","type":"debug","z":"414d4512.baec7c","name":"开关","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":630,"y":280,"wires":[]},{"id":"a4d026bb.5addc8","type":"comment","z":"414d4512.baec7c","name":"开关","info":"","x":70,"y":240,"wires":[]},{"id":"39f16712.916d68","type":"function","z":"414d4512.baec7c","name":"指令分析","func":"msg.payload = {\n    "data":{\n        "entity_id":msg.entity_id\n    }\n}\nflow.get("getCurStatus")(msg);\n\nvar msg_on_off;\nvar msg_temp;\nvar msg_wind;\n\nif(msg.commands[0]!=msg.curStatus[0]){\n    if(msg.commands[0]=="on"){\n        msg.just_turn_on=true;\n    }\n    msg_on_off = msg;\n}\nif(msg.commands[2] && msg.commands[2]!=msg.curStatus[2]){\n    msg.tempData={'temperature':msg.commands[2]};\n    msg_temp = msg;\n}\nif(msg.commands[3] && msg.commands[3]!=msg.curStatus[3]){\n    var windLevel=parseInt(msg.commands[3]);\n    msg.fan_modes=msg.data.attributes.fan_modes\n    var fan_mode = msg.fan_modes[windLevel]\n    msg.funModeData = {"fan_mode": fan_mode};\n    msg_wind = msg;\n}\n\nreturn [msg_on_off,msg_temp,msg_wind,msg];","outputs":4,"noerr":0,"initialize":"","finalize":"","libs":[],"x":520,"y":80,"wires":[["d07bd3e3.8b222"],["fb74f9aa.708818"],["8441cc3d.39822"],["b879321f.9d196"]],"icon":"node-red/switch.svg"},{"id":"d07bd3e3.8b222","type":"link out","z":"414d4512.baec7c","name":"开空调","links":["f1abf855.787a58"],"x":655,"y":40,"wires":[]},{"id":"f9fe3432.1a44b8","type":"mqtt in","z":"414d4512.baec7c","name":"主卧空调","topic":"zhuwokongtiao005","qos":"2","datatype":"auto","broker":"c42d0a5f.91f578","nl":false,"rap":true,"rh":0,"x":80,"y":20,"wires":[["51138dc8.6300f4"]]},{"id":"82eb6dd2.d40fa","type":"link in","z":"414d4512.baec7c","name":"风速","links":["8441cc3d.39822"],"x":35,"y":560,"wires":[["42bbc8fb.671ea8"]]},{"id":"3e9c9ce1.f355b4","type":"comment","z":"414d4512.baec7c","name":"风速","info":"","x":90,"y":520,"wires":[]},{"id":"34814b51.f9e484","type":"api-current-state","z":"414d4512.baec7c","name":"温度","server":"294e5026.81603","version":1,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"weather.wo_de_jia","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":230,"y":240,"wires":[["9a9129cc.d8adf8"]]},{"id":"9a9129cc.d8adf8","type":"function","z":"414d4512.baec7c","name":"模式","func":"if(msg.commands[0] == "off"){\n    msg.hvacData={"hvac_mode": "off"};\n    return msg;\n}\nif(msg.data.attributes.temperature>26){\n    msg.mode=2\n}else if(msg.data.attributes.temperature<18){\n    msg.mode=3\n}else{\n    msg.mode=5\n}\nswitch(msg.mode) {\n     case 0:\n        msg.havc="auto";\n        break;\n     case 2:\n        msg.havc="cool";\n        break;\n     case 3:\n        msg.havc="heat";\n        break;\n     case 4:\n        msg.havc="fan_only";\n        break;\n     case 5:\n        msg.havc="dry";\n        break;\n     default:\n        msg.havc="auto";\n}\nmsg.hvacData={"hvac_mode": msg.havc};\nmsg.payload = {\n    "data":{\n        "entity_id":msg.entity_id\n    }\n}\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":350,"y":280,"wires":[["adfaa35c.3e5bc"]]},{"id":"adfaa35c.3e5bc","type":"api-call-service","z":"414d4512.baec7c","name":"开关","server":"294e5026.81603","version":1,"debugenabled":false,"service_domain":"climate","service":"set_hvac_mode","entityId":"","data":"msg.hvacData","dataType":"jsonata","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":490,"y":280,"wires":[["6dac8474.55203c"]]},{"id":"b7a59ea0.79235","type":"mqtt in","z":"414d4512.baec7c","name":"客厅空调","topic":"ketingkongtiao005","qos":"2","datatype":"auto","broker":"c42d0a5f.91f578","nl":false,"rap":true,"rh":0,"x":80,"y":60,"wires":[["51138dc8.6300f4"]]},{"id":"8441cc3d.39822","type":"link out","z":"414d4512.baec7c","name":"","links":["82eb6dd2.d40fa"],"x":655,"y":120,"wires":[]},{"id":"eaffbedd.f7cf6","type":"debug","z":"414d4512.baec7c","name":"风速","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":630,"y":560,"wires":[]},{"id":"1adbdbbb.a2cf44","type":"api-call-service","z":"414d4512.baec7c","name":"调风速","server":"294e5026.81603","version":1,"debugenabled":false,"service_domain":"climate","service":"set_fan_mode","entityId":"climate.ge_li_kong_diao_9551201a000000","data":"msg.funModeData","dataType":"jsonata","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":490,"y":560,"wires":[["eaffbedd.f7cf6"]]},{"id":"fb74f9aa.708818","type":"link out","z":"414d4512.baec7c","name":"","links":["67b8986d.8a0278"],"x":655,"y":80,"wires":[]},{"id":"67b8986d.8a0278","type":"link in","z":"414d4512.baec7c","name":"调温","links":["fb74f9aa.708818"],"x":35,"y":420,"wires":[["f43e3f71.d9ba6"]]},{"id":"d31520ee.9b4e4","type":"comment","z":"414d4512.baec7c","name":"调温","info":"","x":90,"y":380,"wires":[]},{"id":"c1ccd2eb.00934","type":"debug","z":"414d4512.baec7c","name":"调温","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":630,"y":420,"wires":[]},{"id":"8f90a20b.fe763","type":"api-call-service","z":"414d4512.baec7c","name":"调温","server":"294e5026.81603","version":1,"debugenabled":false,"service_domain":"climate","service":"set_temperature","entityId":"","data":"msg.tempData","dataType":"jsonata","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":490,"y":420,"wires":[["c1ccd2eb.00934"]]},{"id":"a5035dd6.2f3c","type":"comment","z":"414d4512.baec7c","name":"开关","info":"","x":730,"y":40,"wires":[]},{"id":"ce891322.d53ca","type":"comment","z":"414d4512.baec7c","name":"风速","info":"","x":730,"y":120,"wires":[]},{"id":"c7fc0c8b.803aa","type":"comment","z":"414d4512.baec7c","name":"温度","info":"","x":730,"y":80,"wires":[]},{"id":"3bd5fdb2.f09142","type":"comment","z":"414d4512.baec7c","name":"mqtt更新巴法云","info":"","x":120,"y":640,"wires":[]},{"id":"8f5b76c8.844c48","type":"switch","z":"414d4512.baec7c","name":"开关","property":"commands[0]","propertyType":"msg","rules":[{"t":"eq","v":"on","vt":"str"},{"t":"eq","v":"off","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":110,"y":280,"wires":[["34814b51.f9e484"],["9a9129cc.d8adf8"]]},{"id":"51138dc8.6300f4","type":"function","z":"414d4512.baec7c","name":"entity_id","func":"msg.commands=msg.payload.split('#');\nmsg.entity_id = flow.get("getHassId")(msg.topic);\nmsg.payload = {\n    "entity_id":msg.entity_id,\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":240,"y":80,"wires":[["1373f1f2.94c03e"]],"icon":"font-awesome/fa-filter"},{"id":"1373f1f2.94c03e","type":"api-current-state","z":"414d4512.baec7c","name":"空调状态","server":"294e5026.81603","version":1,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is_not","override_topic":false,"entity_id":"","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":380,"y":80,"wires":[["39f16712.916d68","265aeed7.9f9e02"]]},{"id":"205797.208ef86a","type":"function","z":"414d4512.baec7c","name":"公用函数定义","func":"return msg;","outputs":1,"noerr":0,"initialize":"// 部署节点后,此处添加的代码将运行一次。 \n//获取空调当前状态\nflow.set("getCurStatus", (msg) => {\n    var attr = msg.data.attributes;\n    var fun_speed = attr.fan_modes.indexOf(attr.fan_mode)+'';\n    var on_off = msg.data.state == "off"? "off":"on";\n    var temperature = msg.data.attributes.temperature+''\n    msg.curStatus = [on_off,2,temperature,fun_speed];\n    return msg;\n});\n\nflow.set("topic_entityId_map",{\n    'zhuwokongtiao005':"climate.ge_li_kong_diao_9551201a000000",\n    'ketingkongtiao005':"climate.ge_li_kong_diao_96a1201a000000",\n    'ciwokongtiao005':"climate.ge_li_kong_diao_d75a221a000000",\n    'shufangkongtiao005':"climate.ge_li_kong_diao_fcf9411a000000",\n});\n\n//获取hass的entityId\nflow.set("getHassId", (mqttTopic) => {\n    return flow.get("topic_entityId_map")[mqttTopic];\n});","finalize":"","libs":[],"x":280,"y":20,"wires":[[]]},{"id":"b879321f.9d196","type":"debug","z":"414d4512.baec7c","name":"3","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":650,"y":160,"wires":[]},{"id":"a85df988.628468","type":"delay","z":"414d4512.baec7c","name":"","pauseType":"delay","timeout":"2","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":300,"y":440,"wires":[["8f90a20b.fe763"]]},{"id":"f43e3f71.d9ba6","type":"function","z":"414d4512.baec7c","name":"","func":"if(msg.just_turn_on){\n    return [null,msg];\n}\nreturn msg;","outputs":2,"noerr":0,"initialize":"","finalize":"","libs":[],"x":130,"y":420,"wires":[["8f90a20b.fe763"],["a85df988.628468"]]},{"id":"83a2de78.83bfa","type":"delay","z":"414d4512.baec7c","name":"","pauseType":"delay","timeout":"2","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":300,"y":580,"wires":[["1adbdbbb.a2cf44"]]},{"id":"42bbc8fb.671ea8","type":"function","z":"414d4512.baec7c","name":"","func":"if(msg.just_turn_on){\n    return [null,msg];\n}\nreturn msg;","outputs":2,"noerr":0,"initialize":"","finalize":"","libs":[],"x":130,"y":560,"wires":[["1adbdbbb.a2cf44"],["83a2de78.83bfa"]]},{"id":"6e9e1bbd.33dd14","type":"mqtt in","z":"414d4512.baec7c","name":"次卧空调","topic":"ciwokongtiao005","qos":"2","datatype":"auto","broker":"c42d0a5f.91f578","nl":false,"rap":true,"rh":0,"x":80,"y":100,"wires":[["51138dc8.6300f4"]]},{"id":"394de94d.ab16c6","type":"mqtt in","z":"414d4512.baec7c","name":"书房空调","topic":"shufangkongtiao005","qos":"2","datatype":"auto","broker":"c42d0a5f.91f578","nl":false,"rap":true,"rh":0,"x":80,"y":140,"wires":[["51138dc8.6300f4"]]},{"id":"a92604e5.abaa08","type":"inject","z":"414d4512.baec7c","name":"5秒刷新","props":[],"repeat":"5","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":100,"y":700,"wires":[["2227fdfe.7e93a2"]]},{"id":"2227fdfe.7e93a2","type":"function","z":"414d4512.baec7c","name":"4空调","func":"var teMap = flow.get("topic_entityId_map");\nvar msgs = Object.keys(teMap).map(key => { \n        return {\n            "payload":{\n                "entity_id":teMap[key]\n            },\n            "topic":key\n        }\n    });\nreturn msgs;","outputs":4,"noerr":0,"initialize":"","finalize":"","libs":[],"x":230,"y":700,"wires":[["d3796069.91747"],["d3796069.91747"],["d3796069.91747"],["d3796069.91747"]]},{"id":"1560cf84.17e17","type":"mqtt out","z":"414d4512.baec7c","name":"mqtt","topic":"","qos":"","retain":"","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"c42d0a5f.91f578","x":650,"y":700,"wires":[]},{"id":"d3796069.91747","type":"api-current-state","z":"414d4512.baec7c","name":"空调","server":"294e5026.81603","version":1,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is_not","override_topic":false,"entity_id":"","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":390,"y":700,"wires":[["2378389.5a672c8"]]},{"id":"2378389.5a672c8","type":"function","z":"414d4512.baec7c","name":"更新变化","func":"var attr = msg.data.attributes;\nvar fun_speed = attr.fan_modes.indexOf(attr.fan_mode);\nvar on_off = msg.data.state == "off"? "off":"on"\nmsg.payload=`${on_off}#2#${msg.data.attributes.temperature}#${fun_speed}#1#1#1`;\nmsg.entity_id = flow.get("getHassId")(msg.topic);\nmsg.entity_status = flow.get(msg.entity_id);\nif(msg.entity_status == msg.payload){\n    return null;\n}\nflow.set(msg.entity_id,msg.payload);\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":520,"y":700,"wires":[["1560cf84.17e17"]]},{"id":"6512da.bcc1cd28","type":"debug","z":"414d4512.baec7c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":580,"y":800,"wires":[]},{"id":"265aeed7.9f9e02","type":"debug","z":"414d4512.baec7c","name":"3","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":470,"y":180,"wires":[]},{"id":"c42d0a5f.91f578","type":"mqtt-broker","name":"巴法","broker":"bemfa.com","port":"9501","clientid":"改成你的","usetls":false,"protocolVersion":"4","keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","birthMsg":{},"closeTopic":"","closeQos":"0","closePayload":"","closeMsg":{},"willTopic":"","willQos":"0","willPayload":"","willMsg":{},"sessionExpiry":""},{"id":"294e5026.81603","type":"server","name":"Home Assistant","legacy":false,"addon":false,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]
回复

使用道具 举报

1

主题

88

帖子

777

积分

高级会员

Rank: 4

积分
777
金钱
689
HASS币
0
发表于 2021-9-7 22:29:30 | 显示全部楼层

感谢老哥。但是导入到node-red 显示语法错误。。
回复

使用道具 举报

11

主题

121

帖子

840

积分

论坛技术达人

积分
840
金钱
709
HASS币
60
发表于 2021-9-8 10:10:32 | 显示全部楼层
本帖最后由 yinzhennan 于 2021-9-8 10:26 编辑
karl321 发表于 2021-9-7 22:29
感谢老哥。但是导入到node-red 显示语法错误。。

[
  {
    "id": "414d4512.baec7c",
    "type": "tab",
    "label": "空调",
    "disabled": false,
    "info": ""
  },
  {
    "id": "f1abf855.787a58",
    "type": "link in",
    "z": "414d4512.baec7c",
    "name": "开空调",
    "links": [
      "d07bd3e3.8b222"
    ],
    "x": 35,
    "y": 280,
    "wires": [
      [
        "8f5b76c8.844c48"
      ]
    ]
  },
  {
    "id": "6dac8474.55203c",
    "type": "debug",
    "z": "414d4512.baec7c",
    "name": "开关",
    "active": true,
    "tosidebar": true,
    "console": false,
    "tostatus": false,
    "complete": "true",
    "targetType": "full",
    "statusVal": "",
    "statusType": "auto",
    "x": 630,
    "y": 280,
    "wires": []
  },
  {
    "id": "a4d026bb.5addc8",
    "type": "comment",
    "z": "414d4512.baec7c",
    "name": "开关",
    "info": "",
    "x": 70,
    "y": 240,
    "wires": []
  },
  {
    "id": "39f16712.916d68",
    "type": "function",
    "z": "414d4512.baec7c",
    "name": "指令分析",
    "func": "msg.payload = {\n    \"data\":{\n        \"entity_id\":msg.entity_id\n    }\n}\nflow.get(\"getCurStatus\")(msg);\n\nvar msg_on_off;\nvar msg_temp;\nvar msg_wind;\n\nif(msg.commands[0]!=msg.curStatus[0]){\n    if(msg.commands[0]==\"on\"){\n        msg.just_turn_on=true;\n    }\n    msg_on_off = msg;\n}\nif(msg.commands[2] && msg.commands[2]!=msg.curStatus[2]){\n    msg.tempData={'temperature':msg.commands[2]};\n    msg_temp = msg;\n}\nif(msg.commands[3] && msg.commands[3]!=msg.curStatus[3]){\n    var windLevel=parseInt(msg.commands[3]);\n    msg.fan_modes=msg.data.attributes.fan_modes\n    var fan_mode = msg.fan_modes[windLevel]\n    msg.funModeData = {\"fan_mode\": fan_mode};\n    msg_wind = msg;\n}\n\nreturn [msg_on_off,msg_temp,msg_wind,msg];",
    "outputs": 4,
    "noerr": 0,
    "initialize": "",
    "finalize": "",
    "libs": [],
    "x": 520,
    "y": 80,
    "wires": [
      [
        "d07bd3e3.8b222"
      ],
      [
        "fb74f9aa.708818"
      ],
      [
        "8441cc3d.39822"
      ],
      [
        "b879321f.9d196"
      ]
    ],
    "icon": "node-red/switch.svg"
  },
  {
    "id": "d07bd3e3.8b222",
    "type": "link out",
    "z": "414d4512.baec7c",
    "name": "开空调",
    "links": [
      "f1abf855.787a58"
    ],
    "x": 655,
    "y": 40,
    "wires": []
  },
  {
    "id": "f9fe3432.1a44b8",
    "type": "mqtt in",
    "z": "414d4512.baec7c",
    "name": "主卧空调",
    "topic": "zhuwokongtiao005",
    "qos": "2",
    "datatype": "auto",
    "broker": "c42d0a5f.91f578",
    "nl": false,
    "rap": true,
    "rh": 0,
    "x": 80,
    "y": 20,
    "wires": [
      [
        "51138dc8.6300f4"
      ]
    ]
  },
  {
    "id": "82eb6dd2.d40fa",
    "type": "link in",
    "z": "414d4512.baec7c",
    "name": "风速",
    "links": [
      "8441cc3d.39822"
    ],
    "x": 35,
    "y": 560,
    "wires": [
      [
        "42bbc8fb.671ea8"
      ]
    ]
  },
  {
    "id": "3e9c9ce1.f355b4",
    "type": "comment",
    "z": "414d4512.baec7c",
    "name": "风速",
    "info": "",
    "x": 90,
    "y": 520,
    "wires": []
  },
  {
    "id": "34814b51.f9e484",
    "type": "api-current-state",
    "z": "414d4512.baec7c",
    "name": "温度",
    "server": "294e5026.81603",
    "version": 1,
    "outputs": 1,
    "halt_if": "",
    "halt_if_type": "str",
    "halt_if_compare": "is",
    "override_topic": false,
    "entity_id": "weather.wo_de_jia",
    "state_type": "str",
    "state_location": "payload",
    "override_payload": "msg",
    "entity_location": "data",
    "override_data": "msg",
    "blockInputOverrides": false,
    "x": 230,
    "y": 240,
    "wires": [
      [
        "9a9129cc.d8adf8"
      ]
    ]
  },
  {
    "id": "9a9129cc.d8adf8",
    "type": "function",
    "z": "414d4512.baec7c",
    "name": "模式",
    "func": "if(msg.commands[0] == \"off\"){\n    msg.hvacData={\"hvac_mode\": \"off\"};\n    return msg;\n}\nif(msg.data.attributes.temperature>26){\n    msg.mode=2\n}else if(msg.data.attributes.temperature<18){\n    msg.mode=3\n}else{\n    msg.mode=5\n}\nswitch(msg.mode) {\n     case 0:\n        msg.havc=\"auto\";\n        break;\n     case 2:\n        msg.havc=\"cool\";\n        break;\n     case 3:\n        msg.havc=\"heat\";\n        break;\n     case 4:\n        msg.havc=\"fan_only\";\n        break;\n     case 5:\n        msg.havc=\"dry\";\n        break;\n     default:\n        msg.havc=\"auto\";\n}\nmsg.hvacData={\"hvac_mode\": msg.havc};\nmsg.payload = {\n    \"data\":{\n        \"entity_id\":msg.entity_id\n    }\n}\n\nreturn msg;",
    "outputs": 1,
    "noerr": 0,
    "initialize": "",
    "finalize": "",
    "libs": [],
    "x": 350,
    "y": 280,
    "wires": [
      [
        "adfaa35c.3e5bc"
      ]
    ]
  },
  {
    "id": "adfaa35c.3e5bc",
    "type": "api-call-service",
    "z": "414d4512.baec7c",
    "name": "开关",
    "server": "294e5026.81603",
    "version": 1,
    "debugenabled": false,
    "service_domain": "climate",
    "service": "set_hvac_mode",
    "entityId": "",
    "data": "msg.hvacData",
    "dataType": "jsonata",
    "mergecontext": "",
    "output_location": "",
    "output_location_type": "none",
    "mustacheAltTags": false,
    "x": 490,
    "y": 280,
    "wires": [
      [
        "6dac8474.55203c"
      ]
    ]
  },
  {
    "id": "b7a59ea0.79235",
    "type": "mqtt in",
    "z": "414d4512.baec7c",
    "name": "客厅空调",
    "topic": "ketingkongtiao005",
    "qos": "2",
    "datatype": "auto",
    "broker": "c42d0a5f.91f578",
    "nl": false,
    "rap": true,
    "rh": 0,
    "x": 80,
    "y": 60,
    "wires": [
      [
        "51138dc8.6300f4"
      ]
    ]
  },
  {
    "id": "8441cc3d.39822",
    "type": "link out",
    "z": "414d4512.baec7c",
    "name": "",
    "links": [
      "82eb6dd2.d40fa"
    ],
    "x": 655,
    "y": 120,
    "wires": []
  },
  {
    "id": "eaffbedd.f7cf6",
    "type": "debug",
    "z": "414d4512.baec7c",
    "name": "风速",
    "active": true,
    "tosidebar": true,
    "console": false,
    "tostatus": false,
    "complete": "true",
    "targetType": "full",
    "statusVal": "",
    "statusType": "auto",
    "x": 630,
    "y": 560,
    "wires": []
  },
  {
    "id": "1adbdbbb.a2cf44",
    "type": "api-call-service",
    "z": "414d4512.baec7c",
    "name": "调风速",
    "server": "294e5026.81603",
    "version": 1,
    "debugenabled": false,
    "service_domain": "climate",
    "service": "set_fan_mode",
    "entityId": "climate.ge_li_kong_diao_9551201a000000",
    "data": "msg.funModeData",
    "dataType": "jsonata",
    "mergecontext": "",
    "output_location": "",
    "output_location_type": "none",
    "mustacheAltTags": false,
    "x": 490,
    "y": 560,
    "wires": [
      [
        "eaffbedd.f7cf6"
      ]
    ]
  },
  {
    "id": "fb74f9aa.708818",
    "type": "link out",
    "z": "414d4512.baec7c",
    "name": "",
    "links": [
      "67b8986d.8a0278"
    ],
    "x": 655,
    "y": 80,
    "wires": []
  },
  {
    "id": "67b8986d.8a0278",
    "type": "link in",
    "z": "414d4512.baec7c",
    "name": "调温",
    "links": [
      "fb74f9aa.708818"
    ],
    "x": 35,
    "y": 420,
    "wires": [
      [
        "f43e3f71.d9ba6"
      ]
    ]
  },
  {
    "id": "d31520ee.9b4e4",
    "type": "comment",
    "z": "414d4512.baec7c",
    "name": "调温",
    "info": "",
    "x": 90,
    "y": 380,
    "wires": []
  },
  {
    "id": "c1ccd2eb.00934",
    "type": "debug",
    "z": "414d4512.baec7c",
    "name": "调温",
    "active": true,
    "tosidebar": true,
    "console": false,
    "tostatus": false,
    "complete": "true",
    "targetType": "full",
    "statusVal": "",
    "statusType": "auto",
    "x": 630,
    "y": 420,
    "wires": []
  },
  {
    "id": "8f90a20b.fe763",
    "type": "api-call-service",
    "z": "414d4512.baec7c",
    "name": "调温",
    "server": "294e5026.81603",
    "version": 1,
    "debugenabled": false,
    "service_domain": "climate",
    "service": "set_temperature",
    "entityId": "",
    "data": "msg.tempData",
    "dataType": "jsonata",
    "mergecontext": "",
    "output_location": "",
    "output_location_type": "none",
    "mustacheAltTags": false,
    "x": 490,
    "y": 420,
    "wires": [
      [
        "c1ccd2eb.00934"
      ]
    ]
  },
  {
    "id": "a5035dd6.2f3c",
    "type": "comment",
    "z": "414d4512.baec7c",
    "name": "开关",
    "info": "",
    "x": 730,
    "y": 40,
    "wires": []
  },
  {
    "id": "ce891322.d53ca",
    "type": "comment",
    "z": "414d4512.baec7c",
    "name": "风速",
    "info": "",
    "x": 730,
    "y": 120,
    "wires": []
  },
  {
    "id": "c7fc0c8b.803aa",
    "type": "comment",
    "z": "414d4512.baec7c",
    "name": "温度",
    "info": "",
    "x": 730,
    "y": 80,
    "wires": []
  },
  {
    "id": "3bd5fdb2.f09142",
    "type": "comment",
    "z": "414d4512.baec7c",
    "name": "mqtt更新巴法云",
    "info": "",
    "x": 120,
    "y": 640,
    "wires": []
  },
  {
    "id": "8f5b76c8.844c48",
    "type": "switch",
    "z": "414d4512.baec7c",
    "name": "开关",
    "property": "commands[0]",
    "propertyType": "msg",
    "rules": [
      {
        "t": "eq",
        "v": "on",
        "vt": "str"
      },
      {
        "t": "eq",
        "v": "off",
        "vt": "str"
      }
    ],
    "checkall": "true",
    "repair": false,
    "outputs": 2,
    "x": 110,
    "y": 280,
    "wires": [
      [
        "34814b51.f9e484"
      ],
      [
        "9a9129cc.d8adf8"
      ]
    ]
  },
  {
    "id": "51138dc8.6300f4",
    "type": "function",
    "z": "414d4512.baec7c",
    "name": "entity_id",
    "func": "msg.commands=msg.payload.split('#');\nmsg.entity_id = flow.get(\"getHassId\")(msg.topic);\nmsg.payload = {\n    \"entity_id\":msg.entity_id,\n}\nreturn msg;",
    "outputs": 1,
    "noerr": 0,
    "initialize": "",
    "finalize": "",
    "libs": [],
    "x": 240,
    "y": 80,
    "wires": [
      [
        "1373f1f2.94c03e"
      ]
    ],
    "icon": "font-awesome/fa-filter"
  },
  {
    "id": "1373f1f2.94c03e",
    "type": "api-current-state",
    "z": "414d4512.baec7c",
    "name": "空调状态",
    "server": "294e5026.81603",
    "version": 1,
    "outputs": 1,
    "halt_if": "",
    "halt_if_type": "str",
    "halt_if_compare": "is_not",
    "override_topic": false,
    "entity_id": "",
    "state_type": "str",
    "state_location": "payload",
    "override_payload": "msg",
    "entity_location": "data",
    "override_data": "msg",
    "blockInputOverrides": false,
    "x": 380,
    "y": 80,
    "wires": [
      [
        "39f16712.916d68",
        "265aeed7.9f9e02"
      ]
    ]
  },
  {
    "id": "205797.208ef86a",
    "type": "function",
    "z": "414d4512.baec7c",
    "name": "公用函数定义",
    "func": "return msg;",
    "outputs": 1,
    "noerr": 0,
    "initialize": "// 部署节点后,此处添加的代码将运行一次。 \n//获取空调当前状态\nflow.set(\"getCurStatus\", (msg) => {\n    var attr = msg.data.attributes;\n    var fun_speed = attr.fan_modes.indexOf(attr.fan_mode)+'';\n    var on_off = msg.data.state == \"off\"? \"off\":\"on\";\n    var temperature = msg.data.attributes.temperature+''\n    msg.curStatus = [on_off,2,temperature,fun_speed];\n    return msg;\n});\n\nflow.set(\"topic_entityId_map\",{\n    'zhuwokongtiao005':\"climate.ge_li_kong_diao_9551201a000000\",\n    'ketingkongtiao005':\"climate.ge_li_kong_diao_96a1201a000000\",\n    'ciwokongtiao005':\"climate.ge_li_kong_diao_d75a221a000000\",\n    'shufangkongtiao005':\"climate.ge_li_kong_diao_fcf9411a000000\",\n});\n\n//获取hass的entityId\nflow.set(\"getHassId\", (mqttTopic) => {\n    return flow.get(\"topic_entityId_map\")[mqttTopic];\n});",
    "finalize": "",
    "libs": [],
    "x": 280,
    "y": 20,
    "wires": [
      []
    ]
  },
  {
    "id": "b879321f.9d196",
    "type": "debug",
    "z": "414d4512.baec7c",
    "name": "3",
    "active": false,
    "tosidebar": true,
    "console": false,
    "tostatus": false,
    "complete": "true",
    "targetType": "full",
    "statusVal": "",
    "statusType": "auto",
    "x": 650,
    "y": 160,
    "wires": []
  },
  {
    "id": "a85df988.628468",
    "type": "delay",
    "z": "414d4512.baec7c",
    "name": "",
    "pauseType": "delay",
    "timeout": "2",
    "timeoutUnits": "seconds",
    "rate": "1",
    "nbRateUnits": "1",
    "rateUnits": "second",
    "randomFirst": "1",
    "randomLast": "5",
    "randomUnits": "seconds",
    "drop": false,
    "x": 300,
    "y": 440,
    "wires": [
      [
        "8f90a20b.fe763"
      ]
    ]
  },
  {
    "id": "f43e3f71.d9ba6",
    "type": "function",
    "z": "414d4512.baec7c",
    "name": "",
    "func": "if(msg.just_turn_on){\n    return [null,msg];\n}\nreturn msg;",
    "outputs": 2,
    "noerr": 0,
    "initialize": "",
    "finalize": "",
    "libs": [],
    "x": 130,
    "y": 420,
    "wires": [
      [
        "8f90a20b.fe763"
      ],
      [
        "a85df988.628468"
      ]
    ]
  },
  {
    "id": "83a2de78.83bfa",
    "type": "delay",
    "z": "414d4512.baec7c",
    "name": "",
    "pauseType": "delay",
    "timeout": "2",
    "timeoutUnits": "seconds",
    "rate": "1",
    "nbRateUnits": "1",
    "rateUnits": "second",
    "randomFirst": "1",
    "randomLast": "5",
    "randomUnits": "seconds",
    "drop": false,
    "x": 300,
    "y": 580,
    "wires": [
      [
        "1adbdbbb.a2cf44"
      ]
    ]
  },
  {
    "id": "42bbc8fb.671ea8",
    "type": "function",
    "z": "414d4512.baec7c",
    "name": "",
    "func": "if(msg.just_turn_on){\n    return [null,msg];\n}\nreturn msg;",
    "outputs": 2,
    "noerr": 0,
    "initialize": "",
    "finalize": "",
    "libs": [],
    "x": 130,
    "y": 560,
    "wires": [
      [
        "1adbdbbb.a2cf44"
      ],
      [
        "83a2de78.83bfa"
      ]
    ]
  },
  {
    "id": "6e9e1bbd.33dd14",
    "type": "mqtt in",
    "z": "414d4512.baec7c",
    "name": "次卧空调",
    "topic": "ciwokongtiao005",
    "qos": "2",
    "datatype": "auto",
    "broker": "c42d0a5f.91f578",
    "nl": false,
    "rap": true,
    "rh": 0,
    "x": 80,
    "y": 100,
    "wires": [
      [
        "51138dc8.6300f4"
      ]
    ]
  },
  {
    "id": "394de94d.ab16c6",
    "type": "mqtt in",
    "z": "414d4512.baec7c",
    "name": "书房空调",
    "topic": "shufangkongtiao005",
    "qos": "2",
    "datatype": "auto",
    "broker": "c42d0a5f.91f578",
    "nl": false,
    "rap": true,
    "rh": 0,
    "x": 80,
    "y": 140,
    "wires": [
      [
        "51138dc8.6300f4"
      ]
    ]
  },
  {
    "id": "a92604e5.abaa08",
    "type": "inject",
    "z": "414d4512.baec7c",
    "name": "5秒刷新",
    "props": [],
    "repeat": "5",
    "crontab": "",
    "once": false,
    "onceDelay": 0.1,
    "topic": "",
    "x": 100,
    "y": 700,
    "wires": [
      [
        "2227fdfe.7e93a2"
      ]
    ]
  },
  {
    "id": "2227fdfe.7e93a2",
    "type": "function",
    "z": "414d4512.baec7c",
    "name": "4空调",
    "func": "var teMap = flow.get(\"topic_entityId_map\");\nvar msgs = Object.keys(teMap).map(key => { \n        return {\n            \"payload\":{\n                \"entity_id\":teMap[key]\n            },\n            \"topic\":key\n        }\n    });\nreturn msgs;",
    "outputs": 4,
    "noerr": 0,
    "initialize": "",
    "finalize": "",
    "libs": [],
    "x": 230,
    "y": 700,
    "wires": [
      [
        "d3796069.91747"
      ],
      [
        "d3796069.91747"
      ],
      [
        "d3796069.91747"
      ],
      [
        "d3796069.91747"
      ]
    ]
  },
  {
    "id": "1560cf84.17e17",
    "type": "mqtt out",
    "z": "414d4512.baec7c",
    "name": "mqtt",
    "topic": "",
    "qos": "",
    "retain": "",
    "respTopic": "",
    "contentType": "",
    "userProps": "",
    "correl": "",
    "expiry": "",
    "broker": "c42d0a5f.91f578",
    "x": 650,
    "y": 700,
    "wires": []
  },
  {
    "id": "d3796069.91747",
    "type": "api-current-state",
    "z": "414d4512.baec7c",
    "name": "空调",
    "server": "294e5026.81603",
    "version": 1,
    "outputs": 1,
    "halt_if": "",
    "halt_if_type": "str",
    "halt_if_compare": "is_not",
    "override_topic": false,
    "entity_id": "",
    "state_type": "str",
    "state_location": "payload",
    "override_payload": "msg",
    "entity_location": "data",
    "override_data": "msg",
    "blockInputOverrides": false,
    "x": 390,
    "y": 700,
    "wires": [
      [
        "2378389.5a672c8"
      ]
    ]
  },
  {
    "id": "2378389.5a672c8",
    "type": "function",
    "z": "414d4512.baec7c",
    "name": "更新变化",
    "func": "var attr = msg.data.attributes;\nvar fun_speed = attr.fan_modes.indexOf(attr.fan_mode);\nvar on_off = msg.data.state == \"off\"? \"off\":\"on\"\nmsg.payload=`${on_off}#2#${msg.data.attributes.temperature}#${fun_speed}#1#1#1`;\nmsg.entity_id = flow.get(\"getHassId\")(msg.topic);\nmsg.entity_status = flow.get(msg.entity_id);\nif(msg.entity_status == msg.payload){\n    return null;\n}\nflow.set(msg.entity_id,msg.payload);\n\nreturn msg;",
    "outputs": 1,
    "noerr": 0,
    "initialize": "",
    "finalize": "",
    "libs": [],
    "x": 520,
    "y": 700,
    "wires": [
      [
        "1560cf84.17e17"
      ]
    ]
  },
  {
    "id": "6512da.bcc1cd28",
    "type": "debug",
    "z": "414d4512.baec7c",
    "name": "",
    "active": true,
    "tosidebar": true,
    "console": false,
    "tostatus": false,
    "complete": "true",
    "targetType": "full",
    "statusVal": "",
    "statusType": "auto",
    "x": 580,
    "y": 800,
    "wires": []
  },
  {
    "id": "265aeed7.9f9e02",
    "type": "debug",
    "z": "414d4512.baec7c",
    "name": "3",
    "active": true,
    "tosidebar": true,
    "console": false,
    "tostatus": false,
    "complete": "true",
    "targetType": "full",
    "statusVal": "",
    "statusType": "auto",
    "x": 470,
    "y": 180,
    "wires": []
  },
  {
    "id": "c42d0a5f.91f578",
    "type": "mqtt-broker",
    "name": "巴法",
    "broker": "bemfa.com",
    "port": "9501",
    "clientid": "改成你的",
    "usetls": false,
    "protocolVersion": "4",
    "keepalive": "60",
    "cleansession": true,
    "birthTopic": "",
    "birthQos": "0",
    "birthPayload": "",
    "birthMsg": {},
    "closeTopic": "",
    "closeQos": "0",
    "closePayload": "",
    "closeMsg": {},
    "willTopic": "",
    "willQos": "0",
    "willPayload": "",
    "willMsg": {},
    "sessionExpiry": ""
  },
  {
    "id": "294e5026.81603",
    "type": "server",
    "name": "Home Assistant",
    "legacy": false,
    "addon": false,
    "rejectUnauthorizedCerts": true,
    "ha_boolean": "y|yes|true|on|home|open",
    "connectionDelay": true,
    "cacheJson": true
  }
]


回复

使用道具 举报

11

主题

121

帖子

840

积分

论坛技术达人

积分
840
金钱
709
HASS币
60
发表于 2021-9-8 10:15:37 | 显示全部楼层
karl321 发表于 2021-9-7 22:29
感谢老哥。但是导入到node-red 显示语法错误。。

这网站贴代码,会把 \" 转成 ",  无语...
直接贴文本是ok的
回复

使用道具 举报

11

主题

121

帖子

840

积分

论坛技术达人

积分
840
金钱
709
HASS币
60
发表于 2021-9-8 10:28:28 | 显示全部楼层
karl321 发表于 2021-9-7 22:29
感谢老哥。但是导入到node-red 显示语法错误。。

需要改的只有 公用函数定义 那个function节点 里的设置,里面的mqtt topic 和 hass里的entity_id对应关系, 改成你自己的entity_id
另外还有mqtt的broker里的客户端id要改成你的
1631067823112.jpg
回复

使用道具 举报

12

主题

106

帖子

529

积分

高级会员

Rank: 4

积分
529
金钱
423
HASS币
0
发表于 2021-9-9 09:20:59 | 显示全部楼层
测试了可以 ..
回复

使用道具 举报

45

主题

638

帖子

3813

积分

论坛元老

Rank: 8Rank: 8

积分
3813
金钱
3175
HASS币
0
发表于 2021-9-9 18:16:51 | 显示全部楼层
已成功 特来感谢
回复

使用道具 举报

1

主题

88

帖子

777

积分

高级会员

Rank: 4

积分
777
金钱
689
HASS币
0
发表于 2021-9-12 00:59:46 | 显示全部楼层
nice兄弟!搞定了!谢谢!
回复

使用道具 举报

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

本版积分规则

Archiver|手机版|小黑屋|Hassbian

GMT+8, 2024-11-22 05:25 , Processed in 0.412829 second(s), 32 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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