Hello All,
As my name implies I am new to coding with Node Red and am trying to use it to track high and low temps from my home weather station. I want to write the data to the InfluxDB measurement (table) one per day so I am using flow variables to track it throughout the day and then once the day part of the date changes to the next day I am wanting to then write the line out to the database with (at that time) yesterday's date, high, and low.
My problem though is the change node that should be parsing my data and saving it to the msg.payload is instead causing the payload to be empty. Another change node that I included called "Parse Weather Data" works just fine. Even if I put that code in the Parse High/Low Data change node.
So I assume it is something with the flow variables in the change node but can someone help me figure this out please?
[
{
"id": "28d075bbece12065",
"type": "tab",
"label": "Flow 1",
"disabled": false,
"info": "",
"env": []
},
{
"id": "05315d1976ea1b82",
"type": "switch",
"z": "28d075bbece12065",
"name": "New Day?",
"property": "newday",
"propertyType": "flow",
"rules": [
{
"t": "neq",
"v": "oldday",
"vt": "flow"
}
],
"checkall": "true",
"repair": false,
"outputs": 1,
"x": 690,
"y": 360,
"wires": [
[
"fe95dc69b2fd6119"
]
]
},
{
"id": "fe95dc69b2fd6119",
"type": "change",
"z": "28d075bbece12065",
"name": "Parse High/Low Data",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "[\t{\t \"Date\": flow.get(\"olddate\"),\t \"High\": flow.get(\"high\"),\t \"Low\": flow.get(\"low\")\t}\t]",
"tot": "jsonata"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 880,
"y": 360,
"wires": [
[]
]
},
{
"id": "a80697e34517090a",
"type": "function",
"z": "28d075bbece12065",
"name": "High & Low",
"func": "//var oldday = 0;\n\nvar high = flow.get(\"high\")||0;\nvar low = flow.get(\"low\")||0;\nvar olddate = flow.get(\"olddate\")||0;\nvar oldday = flow.get(\"oldday\")||0;\nvar newdate = flow.get(\"newdate\"||0);\nvar newday = flow.get(\"newday\") || 0;\n\nnode.warn(\"newday \" + newday);\n\nif (oldday != 0) {\n node.warn(\"Not First Run\");\n newdate = new Date();\n flow.set(\"newdate\", newdate);\n newday = newdate.getDate();\n //flow.set(\"newday\", newday);\n flow.set(\"newday\", 24);\n if (high < msg.payload[0].lastData.tempf) {\n high = msg.payload[0].lastData.tempf;\n flow.set(\"high\", high);\n }\n if (low > msg.payload[0].lastData.tempf) {\n low = msg.payload[0].lastData.tempf;\n flow.set(\"low\", low);\n }\n}\nif (oldday==0)\n{\n node.warn(\"First Run\");\n olddate = new Date();\n flow.set(\"olddate\", olddate);\n oldday = olddate.getDate();\n flow.set(\"oldday\", oldday);\n high = msg.payload[0].lastData.tempf;\n flow.set(\"high\", high);\n low = msg.payload[0].lastData.tempf;\n flow.set(\"low\", low);\n}\n\nnode.warn(\"high \" + high);\nnode.warn(\"low \" + low);\nnode.warn(\"olddate \" + olddate);\nnode.warn(\"oldday \" + oldday);\nnode.warn(\"newdate \" + newdate);\nnode.warn(\"newday \" + newday);\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 510,
"y": 360,
"wires": [
[
"05315d1976ea1b82"
]
]
},
{
"id": "847100e6ad63c29a",
"type": "change",
"z": "28d075bbece12065",
"name": "Parse Weather Data",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "[\t{\t\"OutsideTemp\": payload[0].lastData.tempf,\t\"Humidity\": payload[0].lastData.humidity,\t\"WindSpeedMPH\": payload[0].lastData.windspeedmph\t}\t]",
"tot": "jsonata"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 880,
"y": 440,
"wires": [
[]
]
}
]