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

 找回密码
 立即注册
查看: 852|回复: 8

[技术探讨] nodered 空调 callservice怎么设置多个属性

[复制链接]

11

主题

179

帖子

1366

积分

金牌会员

Rank: 6Rank: 6

积分
1366
金钱
1187
HASS币
10
发表于 2023-8-10 10:30:22 | 显示全部楼层 |阅读模式
本帖最后由 360341024 于 2023-8-10 10:36 编辑

微信截图_20230810102744.jpg

使用场景:打算自动化联动开启空调,到半夜后设置调高温度调低风速,


上图方法,由几个call service组成,手动触发,空调不开启,换成单个call service手动触发又没问题


还是说 多个call service之间要加delay做缓冲呢?


因为需要设置到比较多属性,如温度 风速 摆风等, 有什么方法可以把属性设置在一起,然后统一call service吗
回复

使用道具 举报

3

主题

18

帖子

62

积分

注册会员

Rank: 2

积分
62
金钱
44
HASS币
0
发表于 2023-8-10 14:29:05 | 显示全部楼层
借鉴学习
回复

使用道具 举报

13

主题

398

帖子

2423

积分

金牌会员

Rank: 6Rank: 6

积分
2423
金钱
2025
HASS币
0
发表于 2023-8-11 11:21:48 来自手机 | 显示全部楼层
写data里写json
当然,写个fuction再调用更过一些,我一般这样做
回复

使用道具 举报

11

主题

179

帖子

1366

积分

金牌会员

Rank: 6Rank: 6

积分
1366
金钱
1187
HASS币
10
 楼主| 发表于 2023-8-11 14:47:07 | 显示全部楼层
ylilike 发表于 2023-8-11 11:21
写data里写json
当然,写个fuction再调用更过一些,我一般这样做

小白完全不明白
回复

使用道具 举报

10

主题

85

帖子

1132

积分

金牌会员

Rank: 6Rank: 6

积分
1132
金钱
1047
HASS币
0
发表于 2023-8-11 14:51:34 | 显示全部楼层
本帖最后由 ssspp 于 2023-8-11 14:53 编辑

空调如果是MQTT的就直接发送MQTT命令,要调用服务可以写个函数把多个服务命令写成JOSN数组,一起提交给一个空的CALL服务就可以一次配置了!
回复

使用道具 举报

0

主题

54

帖子

539

积分

高级会员

Rank: 4

积分
539
金钱
485
HASS币
0
发表于 2023-8-12 09:28:21 | 显示全部楼层
给你一个我自己写的
[{"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}]
回复

使用道具 举报

21

主题

304

帖子

1128

积分

金牌会员

Rank: 6Rank: 6

积分
1128
金钱
824
HASS币
10
发表于 2023-8-12 10:03:56 | 显示全部楼层
xzmcft 发表于 2023-8-12 09:28
给你一个我自己写的

导不进去,提示有问题
SyntaxError: Expected ',' or '}' after property value in JSON at position 1857
n_mode === "low") {\n   
回复

使用道具 举报

11

主题

179

帖子

1366

积分

金牌会员

Rank: 6Rank: 6

积分
1366
金钱
1187
HASS币
10
 楼主| 发表于 2023-8-12 10:49:34 | 显示全部楼层
kkk123 发表于 2023-8-12 10:03
导不进去,提示有问题

哈哈 我也是
回复

使用道具 举报

7

主题

196

帖子

1079

积分

金牌会员

Rank: 6Rank: 6

积分
1079
金钱
883
HASS币
0
发表于 2023-8-12 15:44:28 | 显示全部楼层
本帖最后由 fay000fay 于 2023-8-12 15:46 编辑
[{"id":"2bface7e91a1ad05","type":"inject","z":"9092dc8ec6a54d35","name":"凌晨1点以后","props":[{"p":"payload"}],"repeat":"","crontab":"00 01 * * *","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":100,"y":500,"wires":[["a2932ba9f68a56b5"]]},{"id":"6d29bcc2e227db0b","type":"api-call-service","z":"9092dc8ec6a54d35","name":"则设置送风模式","server":"70a6b1f4.22b43","version":5,"debugenabled":false,"domain":"climate","service":"set_hvac_mode","areaId":[],"deviceId":[],"entityId":["climate.gree_ac_192_168_100_248"],"data":"{\t  "entity_id": "your_climate_entity_id",\t  "hvac_mode": "fan_only"\t}\t","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":640,"y":500,"wires":[["4322f3a45d430a73"]]},{"id":"4322f3a45d430a73","type":"delay","z":"9092dc8ec6a54d35","name":"","pauseType":"delay","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":820,"y":500,"wires":[["93f8c929dbfbb533"]]},{"id":"93f8c929dbfbb533","type":"api-call-service","z":"9092dc8ec6a54d35","name":"设置低风low","server":"70a6b1f4.22b43","version":5,"debugenabled":false,"domain":"climate","service":"set_fan_mode","areaId":[],"deviceId":[],"entityId":["climate.gree_ac_192_168_100_248"],"data":"{\t  "entity_id": "your_climate_entity_id",\t  "fan_mode": "low"\t}\t","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":990,"y":500,"wires":[[]]},{"id":"a2932ba9f68a56b5","type":"api-current-state","z":"9092dc8ec6a54d35","name":"你空调状态","server":"70a6b1f4.22b43","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":290,"y":500,"wires":[["8f48a9279675544f"]]},{"id":"8f48a9279675544f","type":"switch","z":"9092dc8ec6a54d35","name":"若为制冷","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"cool","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":460,"y":500,"wires":[["6d29bcc2e227db0b"]]},{"id":"70a6b1f4.22b43","type":"server","name":"Home Assistant","addon":false,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":false,"heartbeat":false,"heartbeatInterval":"","statusSeparator":"","enableGlobalContextStore":false}]


666.png
回复

使用道具 举报

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

本版积分规则

Archiver|手机版|小黑屋|Hassbian

GMT+8, 2024-4-28 05:55 , Processed in 0.057261 second(s), 33 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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