Hi,
I am just starting with node red and want to join several payloads from an OBD2-Adapter and a wallbox.
I want to write into a csv-file depending on the alternating status between "online" and "offline".
In my project I have no control about the time of the published final message. Can somebody help me to control the publishing time as desired.
Formatting all topics works well, but I have another problem converting the time and date. After the timestamp conversion i have a false day, 2 days later than the real day, shown in the original "now".variable.
As new user I cannot upload a file here, that's why here the projects file text:
[
{
"id": "667cec54c048503c",
"type": "tab",
"label": "Flow 3",
"disabled": false,
"info": "",
"env": []
},
{
"id": "b35e51cc0f70f6fc",
"type": "mqtt in",
"z": "667cec54c048503c",
"name": "WiCAN Status",
"topic": "wican/7c2c67b3dbc1/can/status",
"qos": "2",
"datatype": "utf8",
"broker": "5c944a233ddbd024",
"nl": false,
"rap": true,
"rh": 0,
"inputs": 0,
"x": 130,
"y": 220,
"wires": [
[
"1f1f7d535435a077",
"2e6d55ebe817c89e"
]
]
},
{
"id": "1f1f7d535435a077",
"type": "function",
"z": "667cec54c048503c",
"name": "Zeitstempel formatieren",
"func": "var now = new Date();\nvar year = now.getFullYear();\nvar month = now.getMonth()+1;\nvar day = now.getDay();\nvar hour = now.getHours();\nvar minute = now.getMinutes();\nvar second = now.getSeconds();\n\nif(month.toString().length == 1) {\n month = '0' + month;\n}\nif(day.toString().length == 1) {\n day = '0' + day;\n}\nif(hour.toString().length == 1) {\n hour = '0' + hour;\n}\nif(minute.toString().length == 1) {\n minute = '0' + minute;\n}\nif(second.toString().length == 1) {\n second = '0' + second;\n}\n\n//Funktion gibt die aktuelle Zeit als Payload aus\n//msg.payload = now\nmsg.payload = year + '-' + month + '-' + day + ';' + hour + ':' + minute + ':' + second;\n//msg.payload = now;\nreturn msg;",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 370,
"y": 220,
"wires": [
[
"8b0fd796241ec09d"
]
]
},
{
"id": "87b8aed1b7e49c7c",
"type": "file",
"z": "667cec54c048503c",
"name": "Zoe-Daten.csv",
"filename": "\\\\fritz.box\\AremoricaNAS\\backup\\micha\\Dokumente\\NodeRed\\Zoe-Daten.csv",
"filenameType": "str",
"appendNewline": true,
"createDir": false,
"overwriteFile": "false",
"encoding": "utf8",
"x": 1180,
"y": 340,
"wires": [
[]
]
},
{
"id": "2931e955acfbd9b7",
"type": "mqtt in",
"z": "667cec54c048503c",
"name": "Wallbox E1",
"topic": "cfos_mqtt/get/E1",
"qos": "2",
"datatype": "json",
"broker": "5c944a233ddbd024",
"nl": false,
"rap": true,
"rh": 0,
"inputs": 0,
"x": 120,
"y": 420,
"wires": [
[
"a5c18b192740d349",
"d4c9f823dd98ce95",
"07a13776143fd6e3"
]
]
},
{
"id": "a5c18b192740d349",
"type": "change",
"z": "667cec54c048503c",
"name": "total_energy",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "payload.total_energy",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 330,
"y": 380,
"wires": [
[
"e9384a9106db9179"
]
]
},
{
"id": "d4c9f823dd98ce95",
"type": "change",
"z": "667cec54c048503c",
"name": "used_phases",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "payload.used_phases",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 340,
"y": 420,
"wires": [
[
"e9384a9106db9179"
]
]
},
{
"id": "07a13776143fd6e3",
"type": "change",
"z": "667cec54c048503c",
"name": "power_w",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "payload.power_w",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 320,
"y": 460,
"wires": [
[
"e9384a9106db9179"
]
]
},
{
"id": "e9384a9106db9179",
"type": "join",
"z": "667cec54c048503c",
"name": "",
"mode": "custom",
"build": "string",
"property": "payload",
"propertyType": "msg",
"key": "topic",
"joiner": ";",
"joinerType": "str",
"useparts": false,
"accumulate": false,
"timeout": "",
"count": "3",
"reduceRight": false,
"reduceExp": "",
"reduceInit": "",
"reduceInitType": "",
"reduceFixup": "",
"x": 550,
"y": 420,
"wires": [
[
"7632ca7698b33e53"
]
]
},
{
"id": "9006e9867c02ffb1",
"type": "mqtt in",
"z": "667cec54c048503c",
"name": "WiCAN Zoe",
"topic": "wican/7c2c67b3dbc1/auto",
"qos": "2",
"datatype": "auto-detect",
"broker": "5c944a233ddbd024",
"nl": false,
"rap": true,
"rh": 0,
"inputs": 0,
"x": 130,
"y": 620,
"wires": [
[
"8c55cd189e42dede",
"061ad5ec23363449",
"100f934956a08826",
"099b2cd1789df28a",
"867b7c8caa7ae670"
]
]
},
{
"id": "8c55cd189e42dede",
"type": "change",
"z": "667cec54c048503c",
"name": "km-Stand",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "payload.Odometer",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 320,
"y": 540,
"wires": [
[
"1057d40a833a85b8"
]
]
},
{
"id": "061ad5ec23363449",
"type": "change",
"z": "667cec54c048503c",
"name": "SoC",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "payload.SOC",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 310,
"y": 580,
"wires": [
[
"1057d40a833a85b8"
]
]
},
{
"id": "100f934956a08826",
"type": "change",
"z": "667cec54c048503c",
"name": "kWh Batterie",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "payload.KwhAvail",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 330,
"y": 620,
"wires": [
[
"1057d40a833a85b8"
]
]
},
{
"id": "099b2cd1789df28a",
"type": "change",
"z": "667cec54c048503c",
"name": "AcPhases",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "payload.AcPhases",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 320,
"y": 660,
"wires": [
[
"1057d40a833a85b8"
]
]
},
{
"id": "867b7c8caa7ae670",
"type": "change",
"z": "667cec54c048503c",
"name": "Temperatur",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "payload.TempAmb",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 330,
"y": 700,
"wires": [
[
"1057d40a833a85b8"
]
]
},
{
"id": "1057d40a833a85b8",
"type": "join",
"z": "667cec54c048503c",
"name": "",
"mode": "custom",
"build": "string",
"property": "payload",
"propertyType": "msg",
"key": "topic",
"joiner": ";",
"joinerType": "str",
"useparts": false,
"accumulate": false,
"timeout": "",
"count": "5",
"reduceRight": false,
"reduceExp": "",
"reduceInit": "",
"reduceInitType": "",
"reduceFixup": "",
"x": 550,
"y": 620,
"wires": [
[
"2aaeb2c46d413413"
]
]
},
{
"id": "2aaeb2c46d413413",
"type": "function",
"z": "667cec54c048503c",
"name": "Punkt zu Komma",
"func": "msg.payload = msg.payload.replace('.',',');\nreturn msg;",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 730,
"y": 620,
"wires": [
[
"7632ca7698b33e53"
]
]
},
{
"id": "2e6d55ebe817c89e",
"type": "change",
"z": "667cec54c048503c",
"name": "status",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "payload.status",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 310,
"y": 280,
"wires": [
[
"522477f7ab33fe1c"
]
]
},
{
"id": "522477f7ab33fe1c",
"type": "switch",
"z": "667cec54c048503c",
"name": "Online",
"property": "payload",
"propertyType": "msg",
"rules": [
{
"t": "eq",
"v": "\"online\"",
"vt": "str"
}
],
"checkall": "true",
"repair": false,
"outputs": 1,
"x": 450,
"y": 280,
"wires": [
[
"89579474bdcc9cc4"
]
]
},
{
"id": "7632ca7698b33e53",
"type": "join",
"z": "667cec54c048503c",
"name": "",
"mode": "custom",
"build": "string",
"property": "payload",
"propertyType": "msg",
"key": "topic",
"joiner": ";",
"joinerType": "str",
"useparts": true,
"accumulate": false,
"timeout": "",
"count": "",
"reduceRight": false,
"reduceExp": "",
"reduceInit": "",
"reduceInitType": "",
"reduceFixup": "",
"x": 1010,
"y": 420,
"wires": [
[
"ac0464631b5580fe"
]
]
},
{
"id": "ac0464631b5580fe",
"type": "debug",
"z": "667cec54c048503c",
"name": "debug 4",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 1160,
"y": 420,
"wires": []
},
{
"id": "89579474bdcc9cc4",
"type": "change",
"z": "667cec54c048503c",
"name": "",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "complete",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 630,
"y": 280,
"wires": [
[
"8b0fd796241ec09d"
]
]
},
{
"id": "8b0fd796241ec09d",
"type": "join",
"z": "667cec54c048503c",
"name": "",
"mode": "custom",
"build": "string",
"property": "payload",
"propertyType": "msg",
"key": "topic",
"joiner": ";",
"joinerType": "str",
"useparts": false,
"accumulate": false,
"timeout": "",
"count": "2",
"reduceRight": false,
"reduceExp": "",
"reduceInit": "",
"reduceInitType": "",
"reduceFixup": "",
"x": 830,
"y": 220,
"wires": [
[
"7632ca7698b33e53"
]
]
},
{
"id": "5c944a233ddbd024",
"type": "mqtt-broker",
"name": "Raspi3",
"broker": "192.168.178.2",
"port": 1883,
"clientid": "",
"autoConnect": true,
"usetls": false,
"protocolVersion": 4,
"keepalive": 60,
"cleansession": true,
"autoUnsubscribe": true,
"birthTopic": "",
"birthQos": "0",
"birthRetain": "false",
"birthPayload": "",
"birthMsg": {},
"closeTopic": "",
"closeQos": "0",
"closeRetain": "false",
"closePayload": "",
"closeMsg": {},
"willTopic": "",
"willQos": "0",
"willRetain": "false",
"willPayload": "",
"willMsg": {},
"userProps": "",
"sessionExpiry": ""
}
]