trphoenix
2025-07-14 8da8ab334734f381bb5f6aad5bfa11df5cd36ff8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// 处理来自集中供液系统的数据
const deviceId = "central_liquid_supply";
const topic = msg.topic;
const value = msg.payload;
 
// 根据 topic 确定实体类型和 ID
let entityType = "sensor";
let entityId = "";
let stateTopic = "";
 
if (topic.includes("温度")) {
    entityId = "temperature";
    stateTopic = `${deviceId}/sensor/${entityId}/state`;
} else if (topic.includes("PH")) {
    entityId = "ph_value";
    stateTopic = `${deviceId}/sensor/${entityId}/state`;
} else if (topic.includes("电导率")) {
    entityId = "conductivity";
    stateTopic = `${deviceId}/sensor/${entityId}/state`;
} else if (topic.includes("配液当前液位")) {
    entityId = "mixing_level";
    stateTopic = `${deviceId}/sensor/${entityId}/state`;
} else if (topic.includes("储液当前液位")) {
    entityId = "storage_level";
    stateTopic = `${deviceId}/sensor/${entityId}/state`;
} else if (topic.includes("供液一压力")) {
    entityId = "supply_pressure_1";
    stateTopic = `${deviceId}/sensor/${entityId}/state`;
} else if (topic.includes("供液二压力")) {
    entityId = "supply_pressure_2";
    stateTopic = `${deviceId}/sensor/${entityId}/state`;
} else if (topic.includes("工作状态")) {
    entityType = "binary_sensor";
    entityId = "work_status";
    stateTopic = `${deviceId}/binary_sensor/${entityId}/state`;
} else if (topic.includes("报警状态")) {
    entityType = "binary_sensor";
    entityId = "alarm_status";
    stateTopic = `${deviceId}/binary_sensor/${entityId}/state`;
} else {
    node.warn(`未知的数据类型: ${topic}`);
    return null;
}
 
// 记录数据处理信息
node.warn(`处理数据: ${topic} = ${value} -> ${stateTopic}`);
 
// 创建输出消息
const outputMsg = {
    topic: stateTopic,
    payload: String(value),
    retain: false
};
 
return outputMsg;