var entityId = “climate.sl_cp_dn_a3qaaaauackzrzayndaxnq_80ef”;
var targetTemp = msg.hap.allChars[“Target Temperature”];
var currentTemp = msg.hap.allChars[“Current Temperature”];
var p = msg.hap.allChars[“Target Heating Cooling State”];
if (p == 3 || currentTemp <= 20) {
ac = {
domain: "climate",
service: "turn_on",
data: {
entity_id: entityId
}
}
} else if (p == 2 || currentTemp <= 20) {
ac = {
domain: "climate",
service: "turn_oaa",
data: {
entity_id: entityId
}
}
} else if (p == 1 || currentTemp <= 20) {
ac = {
domain: "climate",
service: "turn_ogg",
data: {
entity_id: entityId
}
}
} else if (p == 0) {
ac = {
domain: "climate",
service: "turn_off",
data: {
entity_id: entityId
}
}
}
msg.payload = ac
return msg;
======================================
以上是一段function关于空调开关的判断,真实中TargetHeatingCoolingState总计有0、1、2、3四个值,如何以这四个值来写语法,分析执行相关命令,并且得在当前室温都在20摄氏度下才执行。
这个写法正确与否?!
这对老鸟来说简直就是幼儿园级别的提问,但对我这种新菜来说资料却无处可查,请有空的大佬指导指导,谢了!