|
发表于 2024-3-28 15:45:48
|
显示全部楼层
我这个是控制散热器的
var status = msg.payload
var data = msg.data
if (status <= 28) {
msg.payload = {
"domain": "fan",
"service": "turn_off",
"target": {
"entity_id": "fan.n2_fan"
}
};
node.send(msg);
} else {
var targetPercentage = Math.round((status - 28) * 6.5) + 25;
targetPercentage = Math.min(100, Math.max(25, targetPercentage)); // 确保目标百分比在范围内
if (data.attributes.percentage !== targetPercentage) {
msg.payload = {
"domain": "fan",
"service": "set_percentage",
"data": {
"percentage": targetPercentage
},
"target": {
"entity_id": "fan.n2_fan"
}
};
node.send(msg);
}
}
|
评分
-
查看全部评分
|