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

 找回密码
 立即注册
查看: 1989|回复: 5

[求助] 关于日立空调接入HA的一些问题

[复制链接]

36

主题

135

帖子

1039

积分

金牌会员

Rank: 6Rank: 6

积分
1039
金钱
904
HASS币
0
发表于 2023-4-9 21:15:21 | 显示全部楼层 |阅读模式
1.首先第一步通过MQQT climate 创建了空调实体,
mqtt:
  climate:
      - unique_id: rilikongtiao1
        name: rilikongtiao1
        modes:
          - "off"
          - "heat"
          - "dry"
          - "cool"
          - "fan_only"
        fan_modes:
          - "high"
          - "medium"
          - "low"
          - "auto"
          - "silent"
        power_command_topic: "homeassistant/climate/zhonghong/1-1/power/set"
        mode_command_topic: "homeassistant/climate/zhonghong/1-1/mode/set"
        current_temperature_topic: "homeassistant/climate/zhonghong/1-1/cur_temp/state"
        mode_state_topic: "homeassistant/climate/zhonghong/1-1/mode/state"
        temperature_command_topic: "homeassistant/climate/zhonghong/1-1/temp/set"
        temperature_state_topic: "homeassistant/climate/zhonghong/1-1/temp/state"
        fan_mode_command_topic: "homeassistant/climate/zhonghong/1-1/fan/set"
        fan_mode_state_topic: "homeassistant/climate/zhonghong/1-1/fan/state"
        precision: 1.0

                               
登录/注册后可看大图


第二 通过node-red modbus 组件 与空调网关通信(空调网关可同时支持 ZigBee 及 485协议),具体流程及代码
[{"id":"5ae3ca12152d6384","type":"tab","label":"流程 2","disabled":false,"info":"","env":[]},{"id":"604dd75493635a55","type":"modbus-flex-write","z":"5ae3ca12152d6384","name":"日立网关","showStatusActivities":false,"showErrors":false,"showWarnings":true,"server":"7e689472fa890182","emptyMsgOnFail":false,"keepMsgProperties":false,"delayOnStart":false,"startDelayTime":"","x":760,"y":740,"wires":[[],[]]},{"id":"d2d656c4313ead04","type":"mqtt in","z":"5ae3ca12152d6384","name":"运行模式","topic":"homeassistant/climate/zhonghong/+/mode/set","qos":"0","datatype":"auto-detect","broker":"cc150b3a.bacbc8","nl":false,"rap":true,"rh":0,"inputs":0,"x":300,"y":700,"wires":[["8fc95f92c1e953bb"]]},{"id":"8fc95f92c1e953bb","type":"function","z":"5ae3ca12152d6384","name":"function 5","func":"// 获取主题\nconst topic = msg.topic;\nconst msg_0=msg.payload ;\nlet msg_1;\nlet registerAddress;\n// 使用正则表达式匹配出 "1-1"\nconst match = /\\/(\\d+-\\d+)\\/mode\\/set$/.exec(topic);\n// 如果匹配成功,则将匹配结果存储在 payload 中\nif (match) {\n    const acNumber = match[1];\n    if (acNumber === "1-1") {\n        registerAddress = 4134;\n    } else if (acNumber === "1-2") {\n        registerAddress = 4138;\n    } else if (acNumber === "2-1") {\n        registerAddress = 4142;\n    } else if (acNumber === "2-2") {\n        registerAddress = 4146;\n    }\n}\nif (msg_0 == "cool") \n   { msg_1 = 1};\nif (msg_0 == "dry") \n  {msg_1 = 2};\nif (msg_0 == "fan_only") \n   {msg_1 = 4};\nif (msg_0 == "off") \n   { msg.payload = null };\nmsg.payload = { 'value': msg_1, 'fc': 6, 'unitid': 1, 'address': registerAddress, 'quantity': 1 };\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":540,"y":700,"wires":[["604dd75493635a55"]]},{"id":"96db700c2db5a657","type":"mqtt in","z":"5ae3ca12152d6384","name":"开关机","topic":"homeassistant/climate/zhonghong/+/power/set","qos":"0","datatype":"auto-detect","broker":"cc150b3a.bacbc8","nl":false,"rap":true,"rh":0,"inputs":0,"x":290,"y":620,"wires":[["a914cf9733c34b9e"]]},{"id":"503bed9be84443dc","type":"mqtt in","z":"5ae3ca12152d6384","name":"风速","topic":"homeassistant/climate/zhonghong/+/fan/set","qos":"0","datatype":"auto-detect","broker":"cc150b3a.bacbc8","nl":false,"rap":true,"rh":0,"inputs":0,"x":290,"y":780,"wires":[["4e636cb9963f95f2"]]},{"id":"a914cf9733c34b9e","type":"function","z":"5ae3ca12152d6384","name":"function 6","func":"// 获取主题\nconst topic = msg.topic;\nconst msg_0=msg.payload ;\nlet msg_1;\nlet registerAddress;\n// 使用正则表达式匹配出 "1-1"\nconst match = /\\/(\\d+-\\d+)\\/power\\/set$/.exec(topic);\n// 如果匹配成功,则将匹配结果存储在 payload 中\nif (match) {\n    const acNumber = match[1];\n    if (acNumber === "1-1") {\n        registerAddress = 4132;\n    } else if (acNumber === "1-2") {\n        registerAddress = 4136;\n    } else if (acNumber === "2-1") {\n        registerAddress = 4140;\n    } else if (acNumber === "2-2") {\n        registerAddress = 4144;\n    }\n}\nif (msg_0=="ON")\n  { msg_1= 1};\nif (msg_0 == "OFF")\n  { msg_1 = 0};\nmsg.payload = { 'value': msg_1, 'fc': 6, 'unitid': 1, 'address': registerAddress, 'quantity': 1 };\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":540,"y":620,"wires":[["604dd75493635a55"]]},{"id":"4e636cb9963f95f2","type":"function","z":"5ae3ca12152d6384","name":"function 7","func":"// 获取主题\nconst topic = msg.topic;\nconst msg_0 = msg.payload;\nlet msg_1;\nlet registerAddress;\n// 使用正则表达式匹配出 "1-1"\nconst match = /\\/(\\d+-\\d+)\\/fan\\/set$/.exec(topic);\n// 如果匹配成功,则将匹配结果存储在 payload 中\nif (match) {\n    const acNumber = match[1];\n    if (acNumber === "1-1") {\n        registerAddress = 4135;\n    } else if (acNumber === "1-2") {\n        registerAddress = 4139;\n    } else if (acNumber === "2-1") {\n        registerAddress = 4143;\n    } else if (acNumber === "2-2") {\n        registerAddress = 4147;\n    }\n}\nif (msg_0 == "high") \n   { msg_1 = 1 };\nif (msg_0 == "medium") \n   { msg_1 = 2 };\nif (msg_0 == "low") \n   { msg_1 = 4 };\nmsg.payload = { 'value': msg_1, 'fc': 6, 'unitid': 1, 'address': registerAddress, 'quantity': 1 };\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":540,"y":780,"wires":[["604dd75493635a55"]]},{"id":"f64c24af608752e5","type":"mqtt in","z":"5ae3ca12152d6384","name":"温度设定","topic":"homeassistant/climate/zhonghong/+/temp/set","qos":"0","datatype":"auto-detect","broker":"cc150b3a.bacbc8","nl":false,"rap":true,"rh":0,"inputs":0,"x":300,"y":860,"wires":[["b70b97c6ba7049ee"]]},{"id":"b70b97c6ba7049ee","type":"function","z":"5ae3ca12152d6384","name":"function 8","func":"// 获取主题\nconst topic = msg.topic;\nconst msg_0=msg.payload ;\nlet msg_1 ;\nlet registerAddress;\n// 使用正则表达式匹配出 "1-1"\nconst match = /\\/(\\d+-\\d+)\\/temp\\/set$/.exec(topic);\n// 如果匹配成功,则将匹配结果存储在 payload 中\nif (match) {\n    const acNumber = match[1];\n    if (acNumber === "1-1") {\n        registerAddress = 4133;\n    } else if (acNumber === "1-2") {\n        registerAddress = 4137;\n    } else if (acNumber === "2-1") {\n        registerAddress = 4141;\n    } else if (acNumber === "2-2") {\n        registerAddress = 4145;\n    }\n}\nif (msg_0< 19)\n    {\n    msg_1=19;\n    msg.payload = { 'value': msg_1, 'fc': 6, 'unitid': 1, 'address': registerAddress, 'quantity': 1 };\n    }\nelse if(msg_0 >30)\n   {  \n      msg_1 = 30; \n      msg.payload = { 'value': msg_1, 'fc': 6, 'unitid': 1, 'address': registerAddress, 'quantity': 1 };\n    }\nelse \n{\n    msg.payload = { 'value': msg_0, 'fc': 6, 'unitid': 1, 'address': registerAddress, 'quantity': 1 };\n };\nreturn msg ;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":540,"y":860,"wires":[["604dd75493635a55"]]},{"id":"5605b6bfcfa63a32","type":"modbus-read","z":"5ae3ca12152d6384","name":"读取日立网关数据","topic":"","showStatusActivities":false,"logIOActivities":false,"showErrors":false,"showWarnings":true,"unitid":"1","dataType":"HoldingRegister","adr":"198","quantity":"6","rate":"1","rateUnit":"s","delayOnStart":false,"startDelayTime":"","server":"7e689472fa890182","useIOFile":false,"ioFile":"","useIOForPayload":false,"emptyMsgOnFail":false,"x":270,"y":280,"wires":[["b246650bb0e8d632","ff4925a7789d6a61","d651c18160b66ffd"],[]]},{"id":"b246650bb0e8d632","type":"function","z":"5ae3ca12152d6384","name":"temperature","func":"const msg_0 = msg.payload;\nmsg.payload = msg_0[1];\nmsg.topic ="homeassistant/climate/zhonghong/1-1/temp/state"\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":570,"y":380,"wires":[["50b4f45eb615ae6f"]]},{"id":"ff4925a7789d6a61","type":"function","z":"5ae3ca12152d6384","name":"mode","func":"\nconst msg_0 = msg.payload;\nvar  msg_1 = ""\nswitch (msg_0[2]) {\n  case 1:\n    msg_1 = 'cool';\n    break;\n  case 2:\n    msg_1 = 'dry';\n    break;\n  case 4:\n    msg_1 = 'fan_only';\n    break;\n  case 8:\n    msg_1 = 'heat';\n    break;\n  default:\n    msg_1 = 'off';\n}\nif (msg_0[0]==0) {\n  msg_1 = 'off';}\nmsg.topic ="homeassistant/climate/zhonghong/1-1/mode/state";\nmsg.payload = msg_1;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":570,"y":440,"wires":[["273ce04bd36d52cb"]]},{"id":"d651c18160b66ffd","type":"function","z":"5ae3ca12152d6384","name":"FAN","func":"const msg_0 = msg.payload;\nvar msg_1 =""\nswitch (msg_0[3]) {\n   case 1:\n      msg_1 = 'high';\n      break;\n   case 2:\n      msg_1 = 'medium';\n      break;\n   case 4:\n      msg_1 = 'low';\n      break;\n   default:\n      msg_1 = 'auto';\n}\nmsg.payload = msg_1\nmsg.topic = "homeassistant/climate/zhonghong/1-1/fan/state";\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":570,"y":500,"wires":[["1b03feb66e13c417"]]},{"id":"50b4f45eb615ae6f","type":"mqtt out","z":"5ae3ca12152d6384","name":"temp/state","topic":"","qos":"0","retain":"","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"cc150b3a.bacbc8","x":810,"y":380,"wires":[]},{"id":"273ce04bd36d52cb","type":"mqtt out","z":"5ae3ca12152d6384","name":"mode/state","topic":"","qos":"0","retain":"","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"cc150b3a.bacbc8","x":810,"y":440,"wires":[]},{"id":"1b03feb66e13c417","type":"mqtt out","z":"5ae3ca12152d6384","name":"fan/state","topic":"","qos":"0","retain":"","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"cc150b3a.bacbc8","x":800,"y":500,"wires":[]},{"id":"7e689472fa890182","type":"modbus-client","name":"日立空调网关","clienttype":"tcp","bufferCommands":true,"stateLogEnabled":false,"queueLogEnabled":false,"failureLogEnabled":true,"tcpHost":"10.1.200.248","tcpPort":"1030","tcpType":"DEFAULT","serialPort":"/dev/ttyUSB","serialType":"RTU-BUFFERD","serialBaudrate":"9600","serialDatabits":"8","serialStopbits":"1","serialParity":"none","serialConnectionDelay":"100","serialAsciiResponseStartDelimiter":"0x3A","unit_id":"1","commandDelay":"1","clientTimeout":"1000","reconnectOnTimeout":true,"reconnectTimeout":"2000","parallelUnitIdsAllowed":true,"showWarnings":true,"showLogs":true},{"id":"cc150b3a.bacbc8","type":"mqtt-broker","name":"","broker":"10.1.200.251","port":"1883","clientid":"","autoConnect":true,"usetls":false,"protocolVersion":"4","keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","birthMsg":{},"closeTopic":"","closePayload":"","closeMsg":{},"willTopic":"","willQos":"0","willPayload":"","willMsg":{},"userProps":"","sessionExpiry":""}]


                               
登录/注册后可看大图

通过涂鸦APP 控制 空调的 开关 模式  温度 等操作  MQQT climate 实体都可以接受到信息并改变实体状态,但通过MQQT climate 实体 去控制空调时 问题就来了,可以控制空调,但MQQT climate 实体状态不会改变,还是默认状态,而且过一会 空调的状态也会变为MQQT climate 实体的默认状态。


请各位大佬帮忙解惑,我对MQQT 原理不是很熟悉。



回复

使用道具 举报

13

主题

95

帖子

1302

积分

金牌会员

Rank: 6Rank: 6

积分
1302
金钱
1207
HASS币
0
发表于 2023-12-1 09:38:06 | 显示全部楼层
nodered代码好像不正确,没有倒全
说说我的理解,其实MQTT只是用来连接HA和nodered程序的,
所有的控制代码都是在Nodered程序来实现的,然后设备的结果也是反馈到NA程序。NA程序在根据MQTT规定的格式代码,将相关数据反馈给HA显示出来。反过来,HA的控制方面也是通过MQTT发送到NA,在NA转换成485命令去执行。


想问一下,有日立空调485的控制码吗?
回复

使用道具 举报

36

主题

135

帖子

1039

积分

金牌会员

Rank: 6Rank: 6

积分
1039
金钱
904
HASS币
0
 楼主| 发表于 2023-12-1 11:10:44 | 显示全部楼层
梅林听风 发表于 2023-12-1 09:38
nodered代码好像不正确,没有倒全
说说我的理解,其实MQTT只是用来连接HA和nodered程序的,
所有的控制代码 ...

有的 但是要有中央空调的中控网关
回复

使用道具 举报

13

主题

95

帖子

1302

积分

金牌会员

Rank: 6Rank: 6

积分
1302
金钱
1207
HASS币
0
发表于 2023-12-1 12:57:12 | 显示全部楼层
user1075 发表于 2023-12-1 11:10
有的 但是要有中央空调的中控网关

中控网关是啥型号呀
回复

使用道具 举报

36

主题

135

帖子

1039

积分

金牌会员

Rank: 6Rank: 6

积分
1039
金钱
904
HASS币
0
 楼主| 发表于 2023-12-1 20:43:20 | 显示全部楼层
我明天拍照发给你
回复

使用道具 举报

2

主题

132

帖子

947

积分

高级会员

Rank: 4

积分
947
金钱
815
HASS币
0
发表于 2024-6-25 23:43:47 | 显示全部楼层
老大,复制代码提示错误
回复

使用道具 举报

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

本版积分规则

Archiver|手机版|小黑屋|Hassbian

GMT+8, 2024-11-23 09:25 , Processed in 0.060776 second(s), 28 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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