[{"id":"cf6628bc83210caf","type":"change","z":"d91aafae8af6b790","name":"设置室内想要保持的温度","rules":[{"t":"set","p":"cantingtemp","pt":"msg","to":"27.5","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":410,"y":2020,"wires":[["11e525a0dc2b9175"]]},{"id":"ea4538de158a3d6e","type":"time-range-switch","z":"d91aafae8af6b790","name":"上半夜","lat":"","lon":"","startTime":"20:30","endTime":"00:30","startOffset":0,"endOffset":0,"x":219,"y":2026,"wires":[["cf6628bc83210caf"],[]]},{"id":"73a342b180ba2866","type":"time-range-switch","z":"d91aafae8af6b790","name":"白天","lat":"","lon":"","startTime":"07:31","endTime":"20:29","startOffset":0,"endOffset":0,"x":217,"y":2086,"wires":[["3a93a4c273df8ae5"],[]]},{"id":"3a93a4c273df8ae5","type":"change","z":"d91aafae8af6b790","name":"设置室内想要保持的温度","rules":[{"t":"set","p":"cantingtemp","pt":"msg","to":"27","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":409,"y":2080,"wires":[["11e525a0dc2b9175"]]},{"id":"cc019ba7818815df","type":"change","z":"d91aafae8af6b790","name":"设置室内想要保持的温度","rules":[{"t":"set","p":"cantingtemp","pt":"msg","to":"28","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":408,"y":2050,"wires":[["11e525a0dc2b9175"]]},{"id":"81b58310cec8091d","type":"time-range-switch","z":"d91aafae8af6b790","name":"下半夜","lat":"","lon":"","startTime":"00:31","endTime":"07:30","startOffset":0,"endOffset":0,"x":216,"y":2056,"wires":[["cc019ba7818815df"],[]]},{"id":"f387322c06a097c5","type":"function","z":"d91aafae8af6b790","name":"计算目标设置温度和风速","func":"// 计算 calculated_target_temperature 并将其存储在 msg.calculated_target_temperature 中\nmsg.calculated_target_temperature = Math.floor((parseFloat(msg.target_temperature) + parseFloat(msg.calculated_adjustment)) * 2) / 2;\n// 判断当前 fan_mode 的值并设置对应的 low_fan_mode 和 high_fan_mode\nif (msg.fan_mode === "low") {\n msg.low_fan_mode = "low";\n msg.high_fan_mode = "higher low";\n} else if (msg.fan_mode === "higher low") {\n msg.low_fan_mode = "low";\n msg.high_fan_mode = "middle";\n} else if (msg.fan_mode === "middle") {\n msg.low_fan_mode = "higher low";\n msg.high_fan_mode = "really middle";\n} else if (msg.fan_mode === "really middle") {\n msg.low_fan_mode = "middle";\n msg.high_fan_mode = "medium";\n} else if (msg.fan_mode === "medium") {\n msg.low_fan_mode = "really middle";\n msg.high_fan_mode = "lower high";\n} else if (msg.fan_mode === "lower high") {\n msg.low_fan_mode = "medium";\n msg.high_fan_mode = "high";\n} else if (msg.fan_mode === "high") {\n msg.low_fan_mode = "lower high";\n msg.high_fan_mode = "high";\n} else if (msg.fan_mode === "auto") {\n msg.low_fan_mode = "middle";\n msg.high_fan_mode = "high";\n}\n\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1150,"y":2009,"wires":[["9217639feba8de61"]]},{"id":"50707f7883a21619","type":"switch","z":"d91aafae8af6b790","name":"温差范围","property":"calculated_adjustment","propertyType":"msg","rules":[{"t":"gte","v":"0.4","vt":"num"},{"t":"btwn","v":"-0.4","vt":"num","v2":"-1","v2t":"num"},{"t":"lt","v":"-1","vt":"num"}],"checkall":"true","repair":false,"outputs":3,"x":1071,"y":2075,"wires":[["2adfa365e91a2586"],["2adfa365e91a2586"],["b0b3f510a22f584f"]]},{"id":"9217639feba8de61","type":"switch","z":"d91aafae8af6b790","name":"比较空调设置温度是否变化","property":"calculated_target_temperature","propertyType":"msg","rules":[{"t":"neq","v":"set_target_temperature","vt":"msg"}],"checkall":"true","repair":false,"outputs":1,"x":864,"y":2075,"wires":[["50707f7883a21619"]]},{"id":"613fc22e6e8e8bd2","type":"api-current-state","z":"d91aafae8af6b790","name":"空调已设置温度","server":"706191c4.02846","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"climate.ke_ting_meidi_kong_diao","state_type":"num","blockInputOverrides":false,"outputProperties":[{"property":"data","propertyType":"msg","value":"","valueType":"entity"},{"property":"calculated_adjustment","propertyType":"msg","value":" msg.target_temperature - msg.actual_temperature","valueType":"jsonata"},{"property":"set_target_temperature","propertyType":"msg","value":"data.attributes.temperature","valueType":"jsonata"},{"property":"fan_mode","propertyType":"msg","value":"data.attributes.fan_mode","valueType":"jsonata"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":929,"y":2009,"wires":[["f387322c06a097c5"]]},{"id":"5c4d9de92af62b86","type":"api-call-service","z":"d91aafae8af6b790","name":"调温度","server":"706191c4.02846","version":5,"debugenabled":false,"domain":"climate","service":"set_temperature","areaId":[],"deviceId":[],"entityId":["climate.ke_ting_meidi_kong_diao"],"data":"{"temperature":calculated_target_temperature}","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1640,"y":2067,"wires":[[]]},{"id":"d7435492c5e238c7","type":"api-current-state","z":"d91aafae8af6b790","name":"空调开","server":"706191c4.02846","version":3,"outputs":2,"halt_if":"off","halt_if_type":"str","halt_if_compare":"is_not","entity_id":"climate.ke_ting_meidi_kong_diao","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":770,"y":2016,"wires":[["613fc22e6e8e8bd2"],[]]},{"id":"2adfa365e91a2586","type":"switch","z":"d91aafae8af6b790","name":"低风区分","property":"fan_mode","propertyType":"msg","rules":[{"t":"eq","v":"low","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":1218,"y":2060,"wires":[["5c4d9de92af62b86"],["892bb5a8e90fb866"]]},{"id":"af6a3fed21d3aec2","type":"delay","z":"d91aafae8af6b790","name":"3S","pauseType":"delay","timeout":"3","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":1512,"y":2068,"wires":[["5c4d9de92af62b86"]]},{"id":"892bb5a8e90fb866","type":"api-call-service","z":"d91aafae8af6b790","name":"调低风速","server":"706191c4.02846","version":5,"debugenabled":false,"domain":"climate","service":"set_fan_mode","areaId":[],"deviceId":[],"entityId":["climate.ke_ting_meidi_kong_diao"],"data":"{"fan_mode":low_fan_mode}","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1364,"y":2037,"wires":[["af6a3fed21d3aec2"]]},{"id":"b0b3f510a22f584f","type":"switch","z":"d91aafae8af6b790","name":"高风区分","property":"fan_mode","propertyType":"msg","rules":[{"t":"eq","v":"high","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":1220,"y":2088,"wires":[["5c4d9de92af62b86"],["1d6bb2579adc0307"]]},{"id":"1d6bb2579adc0307","type":"api-call-service","z":"d91aafae8af6b790","name":"调高风速","server":"706191c4.02846","version":5,"debugenabled":false,"domain":"climate","service":"set_fan_mode","areaId":[],"deviceId":[],"entityId":["climate.ke_ting_meidi_kong_diao"],"data":"{"fan_mode":high_fan_mode}","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1364,"y":2098,"wires":[["af6a3fed21d3aec2"]]},{"id":"5ddecd4b44904b61","type":"server-state-changed","z":"d91aafae8af6b790","name":"把某某调到某某度","server":"706191c4.02846","version":4,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"sensor.xiaomi.[A-Za-z0-9_]*_conversation","entityidfiltertype":"regex","outputinitially":false,"state_type":"str","haltifstate":"把餐厅调到(.*?)度","halt_if_type":"re","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"for":"0","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"}],"x":91,"y":2120,"wires":[["4d947d30329274e0"],[]]},{"id":"4d947d30329274e0","type":"function","z":"d91aafae8af6b790","name":"房间和温度值","func":"var a = msg.payload;\nvar b = a.indexOf('把');\nvar c = a.indexOf('调');\nvar e = a.indexOf('到');\nvar f = a.indexOf('度');\nif (b >= 0) {\n var d = a.substring(e + 1, f);\n msg.d = d; //msg.d=d; 前面是转数字,后面是转字符串\n var g = a.substring(b + 1, c);\n msg.g = g; //msg.d=d; 前面是转数字,后面是转字符串\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":290,"y":2113,"wires":[["7425319e0b3935dc"]]},{"id":"7425319e0b3935dc","type":"function","z":"d91aafae8af6b790","name":"转换温度","func":"// 将汉字数字转换为阿拉伯数字\nfunction convertChineseToArabic(chineseNumber) {\n const chineseMap = {\n 零: 0,\n 一: 1,\n 二: 2,\n 三: 3,\n 四: 4,\n 五: 5,\n 六: 6,\n 七: 7,\n 八: 8,\n 九: 9,\n 十: 10,\n };\n\n let result = 0;\n let cantingtemp = 0;\n let isDecimal = false;\n let decimalUnit = 1;\n\n for (let i = 0; i < chineseNumber.length; i++) {\n const char = chineseNumber[i];\n const value = chineseMap[char];\n\n if (value !== undefined) {\n if (value >= 10) {\n if (cantingtemp === 0) {\n cantingtemp = 1;\n }\n cantingtemp *= value;\n result += cantingtemp;\n cantingtemp = 0;\n } else {\n if (isDecimal) {\n decimalUnit *= 0.1;\n cantingtemp += value * decimalUnit;\n } else {\n cantingtemp = value;\n }\n }\n } else if (char === '点') {\n isDecimal = true;\n }\n }\n\n result += cantingtemp;\n return result.toFixed(isDecimal ? 1 : 0); // 根据是否有小数部分决定保留几位小数\n}\n\n// 在Node-RED中使用该函数\nmsg.cantingtemp = convertChineseToArabic(msg.d);\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":460,"y":2113,"wires":[["11e525a0dc2b9175"]]},{"id":"11e525a0dc2b9175","type":"change","z":"d91aafae8af6b790","name":"目标温度","rules":[{"t":"set","p":"cantingtemp","pt":"global","to":"cantingtemp","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":613,"y":2075,"wires":[["1b1ad39f78caa59c"]]},{"id":"a37e11c83bfd5882","type":"server-state-changed","z":"d91aafae8af6b790","name":"空调开启","server":"706191c4.02846","version":4,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"climate.ke_ting_meidi_kong_diao","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"off","halt_if_type":"str","halt_if_compare":"is_not","outputs":2,"output_only_on_state_change":true,"for":"0","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"}],"x":74,"y":2059,"wires":[["ea4538de158a3d6e","81b58310cec8091d","73a342b180ba2866"],[]]},{"id":"1b1ad39f78caa59c","type":"function","z":"d91aafae8af6b790","name":"转为数字","func":"// 将字符串变量转换为阿拉伯数字\nfunction convertToArabicNumber(stringNumber) {\n // 移除空格和其他非数字字符\n const cleanedString = stringNumber.replace(/[^\\d.]/g, '');\n // 将字符串解析为浮点数\n const arabicNumber = parseFloat(cleanedString);\n return arabicNumber;\n}\n\n// 在Node-RED中使用该函数\nconst cantingtemp = global.get("cantingtemp");\nconst targetTemperature = convertToArabicNumber(cantingtemp);\n\nmsg.target_temperature = targetTemperature;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":634,"y":2016,"wires":[["d7435492c5e238c7"]]},{"id":"a5e2e58e79690e13","type":"server-state-changed","z":"d91aafae8af6b790","name":"温度变化","server":"706191c4.02846","version":4,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"sensor.b460ed8db0c3_temperature","entityidfiltertype":"exact","outputinitially":false,"state_type":"num","haltifstate":"","halt_if_type":"num","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"for":"0","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"actual_temperature","propertyType":"msg","value":"","valueType":"entityState"}],"x":456,"y":1971,"wires":[["1b1ad39f78caa59c"]]},{"id":"5a63b85c6acf8b82","type":"comment","z":"d91aafae8af6b790","name":"餐厅","info":"","x":46,"y":1991,"wires":[]},{"id":"706191c4.02846","type":"server","name":"HAOS","version":5,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":"30","areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"friendlyName","statusSeparator":"at: ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"h23","statusTimeFormat":"h:m","enableGlobalContextStore":true}]