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

 找回密码
 立即注册
查看: 1219|回复: 0

[流程系列] NR轮询电量实体,通过钉钉消息发出。

[复制链接]

22

主题

610

帖子

2749

积分

金牌会员

Rank: 6Rank: 6

积分
2749
金钱
2139
HASS币
0
发表于 2023-9-14 10:06:33 | 显示全部楼层 |阅读模式
本人不懂编程,所以通过AI写了好几个NR流,通过调试发现在数据处理节点处无法正确处理出需要的数据出来流转给钉钉消息节点。

是准备写一个NR流判断HA的电量实体中,小于设定值或者最小值的实体通过钉钉消息发出,但调试过程中总是无法得等需要消息,通过判断,钉钉消息节点配置没有问题的,应该在轮询实体后处理得到的数据节点不对,请大神门帮忙分析下。
以下是一个轮询所有电量实体,得到数据后找出最小值的实体通过消息发送的流,帮忙看看有什么问题。
[{"id":"c429b7e20e810b79","type":"function","z":"43c4ac0f789b8957","name":"获取最小电量实体信息","func":"var entities = msg.payload;\nvar minPowerConsumption = Infinity;\nvar minPowerEntity = null;\n\n// 遍历所有实体,找到电量最低的实体\nfor (var i = 0; i < entities.length; i++) {\n    var entity = entities[i];\n    var entityId = entity.entity_id;\n    var powerConsumption = parseFloat(entity.state);\n    if (powerConsumption < minPowerConsumption) {\n        minPowerConsumption = powerConsumption;\n        minPowerEntity = entity;\n    }\n}\n\n// 如果找到了最小电量实体,则发送钉钉消息\nif (minPowerEntity) {\n    msg.payload = minPowerEntity;\n    return msg;\n}\nelse {\n    return null;\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":540,"y":840,"wires":[["5abc141b338836ce","2534eb8fc02baff1"]]},{"id":"5abc141b338836ce","type":"function","z":"43c4ac0f789b8957","name":"构建消息内容","func":"var entity = msg.payload;\nvar entityId = entity.entity_id;\nvar powerConsumption = entity.state;\nvar message = `实体ID:${entityId}\n电量:${powerConsumption}`;\n\nmsg.payload = {\n    data: {\n        message: message\n    }\n};\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":760,"y":840,"wires":[["084f612255f56782","74a524341fb7eb74"]]},{"id":"084f612255f56782","type":"api-call-service","z":"43c4ac0f789b8957","name":"发送钉钉消息","server":"98872d0b.46fd6","version":5,"debugenabled":false,"domain":"notify","service":"dingtalk","areaId":[],"deviceId":[],"entityId":[],"data":"","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","output_location":"","output_location_type":"none","x":960,"y":840,"wires":[["a0da4f2b4840c287"]]},{"id":"a0da4f2b4840c287","type":"debug","z":"43c4ac0f789b8957","name":"debug 44","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1140,"y":840,"wires":[]},{"id":"2e60d5500b242e3e","type":"server-state-changed","z":"43c4ac0f789b8957","name":"","server":"98872d0b.46fd6","version":4,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"sensor.*battery","entityidfiltertype":"regex","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"for":"1","forType":"num","forUnits":"hours","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":250,"y":840,"wires":[["c429b7e20e810b79","2751c96cb893f20e"]]},{"id":"98872d0b.46fd6","type":"server","name":"Home Assistant","addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"","connectionDelay":false,"cacheJson":false,"heartbeat":false,"heartbeatInterval":"","statusSeparator":"","enableGlobalContextStore":false}]


回复

使用道具 举报

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

本版积分规则

Archiver|手机版|小黑屋|Hassbian

GMT+8, 2024-11-22 10:02 , Processed in 1.261979 second(s), 22 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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