Hey All,
I'm building a solar hot water heater and I'm measuring the temperature of the output water. I want to know what the hottest and lowest temps are in a day and reset those numbers at midnight.
So far I've created 2 flow variables currentExitTemp and lastHighTemp. I'm trying to compare them in a function node but something isn't right. The debug shows up as undefined.
How can I make the comparison and record the daily highs and lows?
this is the function
let currentTemp = parseFloat(msg.payload[0]);
let lastHighTemp = parseFloat(msg.payload[1]);
if (currentTemp >= lastHighTemp) {
msg.payload = msg.payload[0];
flow.set("lastHighTemp", msg.payload[0]);
}
else {
msg.payload = msg.payload[1];
}
return msg;
and the flow
[
{
"id": "1830970fbab5a9be",
"type": "function",
"z": "560c131af0c0df4d",
"name": "function 19",
"func": "let currentTemp = parseFloat(msg.payload[0]);\nlet lastHighTemp = parseFloat(msg.payload[1]);\n\nif (currentTemp >= lastHighTemp) {\n msg.payload = msg.payload[0];\n flow.set(\"lastHighTemp\", msg.payload[0]);\n}\n\nelse {\n msg.payload = msg.payload[1];\n}\n\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 870,
"y": 1020,
"wires": [
[
"3162e44ddd15262f"
]
]
},
{
"id": "e91a94d367947402",
"type": "ui_text",
"z": "560c131af0c0df4d",
"group": "7a51f7a62e395bfe",
"order": 10,
"width": 0,
"height": 0,
"name": "",
"label": "Exit Water High Temp",
"format": "{{flow.lastHighTemp}}",
"layout": "row-spread",
"className": "",
"style": false,
"font": "",
"fontSize": 16,
"color": "#000000",
"x": 1100,
"y": 1060,
"wires": []
},
{
"id": "5af57c58ba42dfa9",
"type": "change",
"z": "560c131af0c0df4d",
"name": "",
"rules": [
{
"t": "set",
"p": "lastHighTemp",
"pt": "flow",
"to": "0",
"tot": "num"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 520,
"y": 1100,
"wires": [
[]
]
},
{
"id": "8aad94337c8c8e47",
"type": "inject",
"z": "560c131af0c0df4d",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 280,
"y": 1100,
"wires": [
[
"5af57c58ba42dfa9"
]
]
},
{
"id": "820bd3ee63e64e48",
"type": "change",
"z": "560c131af0c0df4d",
"name": "Current/Last Temp Array",
"rules": [
{
"t": "set",
"p": "payload[0]",
"pt": "msg",
"to": "currentExitTemp",
"tot": "flow",
"dc": true
},
{
"t": "set",
"p": "payload[1]",
"pt": "msg",
"to": "lastHighTemp",
"tot": "flow",
"dc": true
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 530,
"y": 1020,
"wires": [
[
"1830970fbab5a9be"
]
]
},
{
"id": "e4e0630254ab888e",
"type": "inject",
"z": "560c131af0c0df4d",
"name": "lastHighTemp",
"props": [
{
"p": "payload"
}
],
"repeat": "10",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "lastHighTemp",
"payloadType": "flow",
"x": 860,
"y": 1100,
"wires": [
[
"e91a94d367947402"
]
]
},
{
"id": "5b3b3df5856bd971",
"type": "inject",
"z": "560c131af0c0df4d",
"name": "",
"props": [
{
"p": "payload"
}
],
"repeat": "5",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "{}",
"payloadType": "msg",
"x": 310,
"y": 1020,
"wires": [
[
"820bd3ee63e64e48"
]
]
},
{
"id": "3162e44ddd15262f",
"type": "debug",
"z": "560c131af0c0df4d",
"name": "debug 368",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 1030,
"y": 960,
"wires": []
},
{
"id": "74149027be269f42",
"type": "change",
"z": "560c131af0c0df4d",
"name": "",
"rules": [
{
"t": "set",
"p": "currentExitTemp",
"pt": "flow",
"to": "msg.payload",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 610,
"y": 920,
"wires": [
[]
]
},
{
"id": "c1b0bc59ccef8d2b",
"type": "mqtt in",
"z": "560c131af0c0df4d",
"name": "",
"topic": "/waterHeater/temp2",
"qos": "2",
"datatype": "auto-detect",
"broker": "e8de652f3f0d5685",
"nl": false,
"rap": true,
"rh": 0,
"inputs": 0,
"x": 190,
"y": 860,
"wires": [
[
"279fe863a247588f",
"7efee34e59ad5c6a",
"f64e2fcc96d980a8",
"74149027be269f42"
]
]
},
{
"id": "7a51f7a62e395bfe",
"type": "ui_group",
"name": "Greenhouse",
"tab": "f3a8a67ff0904e39",
"order": 5,
"disp": true,
"width": "6",
"collapse": true,
"className": ""
},
{
"id": "e8de652f3f0d5685",
"type": "mqtt-broker",
"name": "",
"broker": "192.168.1.154",
"port": "1883",
"clientid": "",
"autoConnect": true,
"usetls": false,
"protocolVersion": "4",
"keepalive": "60",
"cleansession": true,
"birthTopic": "",
"birthQos": "0",
"birthPayload": "",
"birthMsg": {},
"closeTopic": "",
"closeQos": "0",
"closePayload": "",
"closeMsg": {},
"willTopic": "",
"willQos": "0",
"willPayload": "",
"willMsg": {},
"userProps": "",
"sessionExpiry": ""
},
{
"id": "f3a8a67ff0904e39",
"type": "ui_tab",
"name": "Home",
"icon": "home",
"order": 1,
"disabled": false,
"hidden": false
}
]