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

 找回密码
 立即注册
查看: 1716|回复: 6

[流程系列] 如何判断5个温度实体的温度值

[复制链接]

8

主题

220

帖子

1666

积分

金牌会员

Rank: 6Rank: 6

积分
1666
金钱
1446
HASS币
0
发表于 2023-9-24 22:53:55 | 显示全部楼层 |阅读模式
请问想判断5个温度实体的温度值,以判断某个位置是否没有关空调,在node-red中应如何实现,一直没弄好。







[{"id":"8e1c0dcad409ff41","type":"server-state-changed","z":"6082b4a4fd16afa4","name":"主卧灯关","server":"7dc8fb2a.fc0804","version":4,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"switch.zimi_dhkg05_3c92_left_switch_service","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"off","halt_if_type":"str","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"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":140,"y":280,"wires":[[],[]]},{"id":"9ae8ed072d3a9ce4","type":"api-current-state","z":"6082b4a4fd16afa4","name":"客厅温度","server":"7dc8fb2a.fc0804","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"sensor.tuyatec_1wzznw9a_rh3052_temperature","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":340,"y":100,"wires":[["a44cd7387f1367ef"]]},{"id":"a44cd7387f1367ef","type":"change","z":"6082b4a4fd16afa4","name":"","rules":[{"t":"move","p":"payload","pt":"msg","to":"state1","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":550,"y":100,"wires":[["3249ea27f314e7b4"]]},{"id":"26eae7278fcaf62a","type":"api-current-state","z":"6082b4a4fd16afa4","name":"主卧温度","server":"7dc8fb2a.fc0804","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"sensor.tuyatec_1wzznw9a_rh3052_temperature_3","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":340,"y":160,"wires":[["f65a332c4c2ce344"]]},{"id":"f65a332c4c2ce344","type":"change","z":"6082b4a4fd16afa4","name":"","rules":[{"t":"move","p":"payload","pt":"msg","to":"state2","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":550,"y":160,"wires":[["3249ea27f314e7b4"]]},{"id":"7bf0ca7882dedba2","type":"api-current-state","z":"6082b4a4fd16afa4","name":"卧室温度","server":"7dc8fb2a.fc0804","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"sensor.tuyatec_1wzznw9a_rh3052_temperature_4","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":340,"y":220,"wires":[["31adbdbb3da8c435"]]},{"id":"31adbdbb3da8c435","type":"change","z":"6082b4a4fd16afa4","name":"","rules":[{"t":"move","p":"payload","pt":"msg","to":"state3","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":550,"y":220,"wires":[[]]},{"id":"5822f56ca3458101","type":"api-current-state","z":"6082b4a4fd16afa4","name":"次卧温度","server":"7dc8fb2a.fc0804","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"sensor.tuyatec_1wzznw9a_rh3052_temperature_2","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":340,"y":280,"wires":[["2266b907fbf037ec"]]},{"id":"2266b907fbf037ec","type":"change","z":"6082b4a4fd16afa4","name":"","rules":[{"t":"move","p":"payload","pt":"msg","to":"state4","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":550,"y":280,"wires":[["6864b512036e2b47","9577506488a65169"]]},{"id":"6864b512036e2b47","type":"api-current-state","z":"6082b4a4fd16afa4","name":"标准温度","server":"7dc8fb2a.fc0804","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"sensor.miaomiaoce_t1_08ae_temperature_humidity_sensor","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":340,"y":340,"wires":[["702cacb188d2e71f"]]},{"id":"702cacb188d2e71f","type":"change","z":"6082b4a4fd16afa4","name":"","rules":[{"t":"move","p":"payload","pt":"msg","to":"state","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":550,"y":340,"wires":[["a57d2c90fa78f8bc","3249ea27f314e7b4"]]},{"id":"3249ea27f314e7b4","type":"function","z":"6082b4a4fd16afa4","name":"","func":"/*\nif ((flow.get('state') - flow.get('state1')) > 2){\n    msg.payload = '主人,客厅温度偏低,可能没有关空调哦'\n}\nif ((flow.get('state') - flow.get('state2')) > 2) {\n    msg.payload = '主人,客厅温度偏低,可能没有关空调哦'\n}\nif ((flow.get('state') - flow.get('state3')) > 2) {\n    msg.payload = '主人,客厅温度偏低,可能没有关空调哦'\n}\n*/\nif ((flow.get('state') - flow.get('state4')) > 2) {\n    msg.payload = '主人,客厅温度偏低,可能没有关空调哦'\n}else { \n//    msg.state1 = flow.get('state1'); \n //   msg.state2 = flow.get('state2'); \n//    msg.state3 = flow.get('state3'); \n    msg.state4 = flow.get('state4'); \n    msg.state = flow.get('state'); \n    return msg; \n}\nreturn msg; \n\n\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":870,"y":220,"wires":[["c04305e4e356b7af","aeb417f54a8a9951"]]},{"id":"7dc8fb2a.fc0804","type":"server","name":"Jason Home Assistant","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,"credentials":{}}]

海鲜市场:jasona3
回复

使用道具 举报

1

主题

170

帖子

1161

积分

金牌会员

Rank: 6Rank: 6

积分
1161
金钱
991
HASS币
0
发表于 2023-9-25 09:20:34 | 显示全部楼层
我是用template来判断的,对比室内外的温度和湿度
嗯哼,有论坛签名了
回复

使用道具 举报

25

主题

272

帖子

1858

积分

金牌会员

Rank: 6Rank: 6

积分
1858
金钱
1586
HASS币
0
发表于 2023-9-25 10:43:10 | 显示全部楼层
用插座功率来判断不更直接
回复

使用道具 举报

8

主题

220

帖子

1666

积分

金牌会员

Rank: 6Rank: 6

积分
1666
金钱
1446
HASS币
0
 楼主| 发表于 2023-9-25 13:27:58 | 显示全部楼层
wpw72 发表于 2023-9-25 10:43
用插座功率来判断不更直接

中央空调,普通开关。
海鲜市场:jasona3
回复

使用道具 举报

19

主题

190

帖子

1300

积分

金牌会员

Rank: 6Rank: 6

积分
1300
金钱
1110
HASS币
0
发表于 2023-9-25 15:39:04 | 显示全部楼层
LaunchTomorrow 发表于 2023-9-25 09:20
我是用template来判断的,对比室内外的温度和湿度

能发出来看以下吗?
回复

使用道具 举报

1

主题

170

帖子

1161

积分

金牌会员

Rank: 6Rank: 6

积分
1161
金钱
991
HASS币
0
发表于 2023-9-26 11:25:32 | 显示全部楼层
xfyisheng 发表于 2023-9-25 15:39
能发出来看以下吗?
template:
  - binary_sensor:
      - name: "ac assumed"
        unique_id: ac_assumed
        device_class: power
        #通过室内外温差判断室内是否开空调,室外低于26为off,室内高于28.5为off,室外-室内>2.5为on
        state: >
          {% set outdoor = states('sensor.0x001wef2hj05e1gbb_temperature') | float %}
          {% set indoor = states('sensor.zhimi_airpurifier_m1_temperature') | float %}
          {% if outdoor < 26 %}
            off
          {% elif indoor > 28.5 %}
            off
          {% elif outdoor - indoor > 2.5 %}
            on
          {% else %}
            off
          {% endif %}
嗯哼,有论坛签名了
回复

使用道具 举报

8

主题

220

帖子

1666

积分

金牌会员

Rank: 6Rank: 6

积分
1666
金钱
1446
HASS币
0
 楼主| 发表于 2023-9-26 15:52:57 | 显示全部楼层
应该是可以了。

Image1.jpg

[{"id":"8e1c0dcad409ff41","type":"server-state-changed","z":"6082b4a4fd16afa4","name":"主卧灯关","server":"7dc8fb2a.fc0804","version":4,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"switch.zimi_dhkg05_3c92_left_switch_service","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"off","halt_if_type":"str","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"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":120,"y":80,"wires":[["d5c4be9f63b44b47"],[]]},{"id":"aeb417f54a8a9951","type":"debug","z":"6082b4a4fd16afa4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1030,"y":320,"wires":[]},{"id":"dc80635a56711a87","type":"inject","z":"6082b4a4fd16afa4","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":130,"y":140,"wires":[["d5c4be9f63b44b47"]]},{"id":"d5c4be9f63b44b47","type":"api-current-state","z":"6082b4a4fd16afa4","name":"客厅温度","server":"7dc8fb2a.fc0804","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"sensor.tuyatec_1wzznw9a_rh3052_temperature","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":320,"y":80,"wires":[["3514ebd19f21c012"]]},{"id":"9ed6557e47e7d921","type":"api-current-state","z":"6082b4a4fd16afa4","name":"主卧温度","server":"7dc8fb2a.fc0804","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"sensor.tuyatec_1wzznw9a_rh3052_temperature_3","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":320,"y":140,"wires":[["15ea924598c1203b"]]},{"id":"0e894d4c433f309f","type":"api-current-state","z":"6082b4a4fd16afa4","name":"卧室温度","server":"7dc8fb2a.fc0804","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"sensor.tuyatec_1wzznw9a_rh3052_temperature_4","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":320,"y":200,"wires":[["75e30f947727eddf"]]},{"id":"d5a88713da6940aa","type":"api-current-state","z":"6082b4a4fd16afa4","name":"次卧温度","server":"7dc8fb2a.fc0804","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"sensor.tuyatec_1wzznw9a_rh3052_temperature_2","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":320,"y":260,"wires":[["b02fbe62079eef4f"]]},{"id":"3514ebd19f21c012","type":"change","z":"6082b4a4fd16afa4","name":"","rules":[{"t":"move","p":"payload","pt":"msg","to":"state1","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":530,"y":80,"wires":[["9ed6557e47e7d921"]]},{"id":"15ea924598c1203b","type":"change","z":"6082b4a4fd16afa4","name":"","rules":[{"t":"move","p":"payload","pt":"msg","to":"state2","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":530,"y":140,"wires":[["0e894d4c433f309f"]]},{"id":"a51059eda9233301","type":"debug","z":"6082b4a4fd16afa4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":890,"y":200,"wires":[]},{"id":"001f0a390214dd70","type":"function","z":"6082b4a4fd16afa4","name":"赋值","func":"msg.state1 = flow.get('state1'); \nmsg.state2 = flow.get('state2'); \nmsg.state3 = flow.get('state3'); \nmsg.state4 = flow.get('state4');\n//msg.state = flow.get('state');\nreturn msg; \n\n/*\nif ((flow.get('state') - flow.get('state1')) > 2){\n    msg.payload = '主人,客厅温度偏低,可能没有关空调哦'\n}\nif ((flow.get('state') - flow.get('state2')) > 2) {\n    msg.payload = '主人,客厅温度偏低,可能没有关空调哦'\n}\nif ((flow.get('state') - flow.get('state3')) > 2) {\n    msg.payload = '主人,客厅温度偏低,可能没有关空调哦'\n}\n*/\n/*\nif ((flow.get('state') - flow.get('state4')) > 2) {\n    msg.payload = '主人,客厅温度偏低,可能没有关空调哦'\n}else { \n//    msg.state1 = flow.get('state1'); \n //   msg.state2 = flow.get('state2'); \n//    msg.state3 = flow.get('state3'); \n    msg.state4 = flow.get('state4'); \n    msg.state = flow.get('state'); \n    return msg; \n}\nreturn msg; \n*/\n\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":730,"y":260,"wires":[["902db897806d74de","a51059eda9233301"]]},{"id":"75e30f947727eddf","type":"change","z":"6082b4a4fd16afa4","name":"","rules":[{"t":"move","p":"payload","pt":"msg","to":"state3","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":530,"y":200,"wires":[["d5a88713da6940aa"]]},{"id":"b02fbe62079eef4f","type":"change","z":"6082b4a4fd16afa4","name":"","rules":[{"t":"move","p":"payload","pt":"msg","to":"state4","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":530,"y":260,"wires":[["001f0a390214dd70"]]},{"id":"902db897806d74de","type":"function","z":"6082b4a4fd16afa4","name":"判断温度","func":"var max = Math.max(msg.state1, msg.state2, msg.state3, msg.state4);\nvar extracted = [];\n\n// 遍历每个温度值,并将比最大值小1的值提取出来\nif (msg.state1 < max - 2) {\n    extracted.push({ name: \"客厅温度\", value: msg.state1 });\n}\nif (msg.state2 < max - 2) {\n    extracted.push({ name: \"主卧温度\", value: msg.state2 });\n}\nif (msg.state3 < max - 2) {\n    extracted.push({ name: \"卧室温度\", value: msg.state3 });\n}\nif (msg.state4 < max - 2) {\n    extracted.push({ name: \"次卧温度\", value: msg.state4 });\n}\n// 将提取的温度数据发送到输出\nmsg.payload = extracted;\nreturn msg;\n\n\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":880,"y":260,"wires":[["29bb995582f47899","aeb417f54a8a9951"]]},{"id":"29bb995582f47899","type":"function","z":"6082b4a4fd16afa4","name":"播报格式","func":"if (msg.payload.length === 1) {\n    msg.payload = msg.payload[0].name + '为' + msg.payload[0].value + '摄氏度,可能没有关空调。';\n} else if (msg.payload.length === 2) {\n    msg.payload = msg.payload[0].name + '为' + msg.payload[0].value + '摄氏度,' + msg.payload[1].name + '为' + msg.payload[1].value + '摄氏度,可能没有关空调。';\n} else if (msg.payload.length === 3) {\n    msg.payload = msg.payload[0].name + '为' + msg.payload[0].value + '摄氏度,' + msg.payload[1].name + '为' + \n        msg.payload[1].value + '摄氏度,' + msg.payload[2].name + '为' + msg.payload[2].value + '摄氏度,可能没有关空调。';\n} else {\n    msg.payload = \"\"; // 当msg.payload数组的长度为0时返回空\n}\nreturn msg;\n\n\n/*if (msg.payload && msg.payload.length > 0) \nif (msg.payload.length == 1) \n    msg.payload = msg.payload[0].name + ',为' + msg.payload[0].value + '摄氏度,可能没有关空调。'\nif (msg.payload.length == 2)\n    msg.payload = msg.payload[0].name + ',为' + msg.payload[0].value + msg.payload[1].name + ',为' + msg.payload[1].value + '摄氏度,可能没有关空调。'\nif (msg.payload.length == 3)\n    msg.payload = msg.payload[0].name + ',为' + msg.payload[0].value + msg.payload[2].name + \n    ',为' + msg.payload[3].value + msg.payload[2].name + ',为' + msg.payload[3].value + '摄氏度,可能没有关空调。'\n//if (msg.payload.length = 4)\n//    msg.payload = msg.payload[0].name + ',为' + msg.payload[0].value + msg.payload[2].name +\n//        ',为' + msg.payload[3].value + msg.payload[2].name + ',为' + msg.payload[3].value + \n//        + msg.payload[4].value + msg.payload[4].name + ',为' + msg.payload[4].value +'摄氏度,可能没有关空调。'\nreturn msg;\n*/","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1040,"y":260,"wires":[["c04305e4e356b7af","5374732819612303"]]},{"id":"5374732819612303","type":"xiaoai-tts","z":"6082b4a4fd16afa4","name":"","xiaoai":"","tts":"","device":"","x":1190,"y":200,"wires":[[],[]]},{"id":"7dc8fb2a.fc0804","type":"server","name":"Jason Home Assistant","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}]
海鲜市场:jasona3
回复

使用道具 举报

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

本版积分规则

Archiver|手机版|小黑屋|Hassbian

GMT+8, 2024-11-22 08:58 , Processed in 1.255480 second(s), 31 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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