Hello,
I´m trying to compare two temperature values via function.
Unfortunately the result is wrong and I have no clue which mistake I did
The result is always 0. I would be glad if you can point at my mistake.
Thanks in advance
[
{
"id": "1f3aaf64d6d89107",
"type": "ioBroker in",
"z": "e7ed6021e07b8f49",
"name": "Outdoor air °C",
"topic": "valloxmv.0.A_CYC_TEMP_OUTDOOR_AIR",
"payloadType": "value",
"onlyack": "",
"func": "all",
"gap": "",
"fireOnStart": "true",
"outFormat": "MQTT",
"x": 960,
"y": 520,
"wires": [
[
"4d84e2a6b189976e"
]
]
},
{
"id": "207a224b46be658d",
"type": "ioBroker in",
"z": "e7ed6021e07b8f49",
"name": "Extract air °C",
"topic": "valloxmv.0.A_CYC_TEMP_EXTRACT_AIR",
"payloadType": "value",
"onlyack": "",
"func": "all",
"gap": "",
"fireOnStart": "true",
"outFormat": "MQTT",
"x": 970,
"y": 440,
"wires": [
[
"4d84e2a6b189976e"
]
]
},
{
"id": "4d84e2a6b189976e",
"type": "join",
"z": "e7ed6021e07b8f49",
"name": "",
"mode": "custom",
"build": "object",
"property": "payload",
"propertyType": "msg",
"key": "topic",
"joiner": "\\n",
"joinerType": "str",
"accumulate": true,
"timeout": "",
"count": "2",
"reduceRight": false,
"reduceExp": "",
"reduceInit": "",
"reduceInitType": "",
"reduceFixup": "",
"x": 1210,
"y": 460,
"wires": [
[
"0085ff6df7522a24",
"62da71443895c02b"
]
]
},
{
"id": "0085ff6df7522a24",
"type": "function",
"z": "e7ed6021e07b8f49",
"name": "function 3",
"func": "var outdoor = msg.payload[\"valloxmv/0/A_CYC_TEMP_OUTDOOR_AIR\"] + 3;\nvar extract = msg.payload[\"valloxmv/0/A_CYC_TEMP_EXTRACT_AIR\"];\n\nif (outdoor <= extract) {\n msg.payload = 1;\n}\nif (outdoor > extract) {\n msg.payload = 2;\n}\nelse {\n msg.payload = 0;\n}\nreturn msg",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 1480,
"y": 460,
"wires": [
[
"236315c5ea9435ed"
]
]
},
{
"id": "62da71443895c02b",
"type": "debug",
"z": "e7ed6021e07b8f49",
"name": "debug 2",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 1300,
"y": 300,
"wires": []
},
{
"id": "236315c5ea9435ed",
"type": "debug",
"z": "e7ed6021e07b8f49",
"name": "debug 4",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 1720,
"y": 460,
"wires": []
}
]
Function code:
var outdoor = msg.payload["valloxmv/0/A_CYC_TEMP_OUTDOOR_AIR"] + 3;
var extract = msg.payload["valloxmv/0/A_CYC_TEMP_EXTRACT_AIR"];
if (outdoor <= extract) {
msg.payload = 1;
}
else if (outdoor > extract) {
msg.payload = 2;
}
else {
msg.payload = 0;
}
return msg