找回密码
 立即注册
搜索
查看: 2045|回复: 9

[技术探讨] 求教怎样用function控制call service节点

[复制链接]

12

主题

263

回帖

2126

积分

金牌会员

积分
2126
金钱
1851
HASS币
10
QQ
发表于 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);
  }
}

评分

参与人数 1金钱 +12 收起 理由
隔壁的王叔叔 + 12 感谢楼主分享!

查看全部评分

回复

使用道具 举报

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

本版积分规则

Archiver|手机版|小黑屋|Hassbian ( 晋ICP备17001384号-1 )

GMT+8, 2025-6-30 12:38 , Processed in 0.073014 second(s), 26 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

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