Hello all!
Hope you enjoy the summer :-)
I have a question for you: We have a peoplecounter that sends multiple values with corresponding timestamps.
I have manage to make an array of these values and timestamps. However, the output is in what I think is Epoch/Unix time. I have used the template in Node-red.
The mail looks like this:
_Counter:1200
It been passing 0 persons between 1690888166433 and 1690888166433
Counter:1215
It been passing 15 persons between 1690888166433 and 1690888167352
Counter:1235
It been passing 20 persons between 1690888167352 and 1690888168190
Counter:1236
It been passing 1 persons between 1690888168190 and 1690888168954
Total passages in between the period (1690888166433 and 1690888168954) is 36 persons_
How can I convert the timestamp to be in UTC in a format of my choosing?
If needed, here is a sample flow in Node-Red:
`[
{
"id": "51d8b18577d5a17b",
"type": "debug",
"z": "af671d82.d368a",
"name": "debug 19",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 1220,
"y": 2100,
"wires": []
},
{
"id": "53361aea565b1786",
"type": "inject",
"z": "af671d82.d368a",
"name": "1200",
"props": [
{
"p": "payload.value",
"v": "1200",
"vt": "num"
},
{
"p": "payload.timestamp",
"v": "",
"vt": "date"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"x": 170,
"y": 2160,
"wires": [
[
"4697950317f208ec"
]
]
},
{
"id": "336e3144787fa161",
"type": "inject",
"z": "af671d82.d368a",
"name": "1215",
"props": [
{
"p": "payload.value",
"v": "1215",
"vt": "num"
},
{
"p": "payload.timestamp",
"v": "",
"vt": "date"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"x": 170,
"y": 2120,
"wires": [
[
"4697950317f208ec"
]
]
},
{
"id": "a2493448d1eb9ac6",
"type": "inject",
"z": "af671d82.d368a",
"name": "1235",
"props": [
{
"p": "payload.value",
"v": "1235",
"vt": "num"
},
{
"p": "payload.timestamp",
"v": "",
"vt": "date"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"x": 167.765625,
"y": 2081.75,
"wires": [
[
"4697950317f208ec"
]
]
},
{
"id": "a896e49b432640e2",
"type": "inject",
"z": "af671d82.d368a",
"name": "1236",
"props": [
{
"p": "payload.value",
"v": "1236",
"vt": "num"
},
{
"p": "payload.timestamp",
"v": "",
"vt": "date"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"x": 170,
"y": 2040,
"wires": [
[
"4697950317f208ec"
]
]
},
{
"id": "4697950317f208ec",
"type": "join",
"z": "af671d82.d368a",
"name": "Make Array",
"mode": "custom",
"build": "array",
"property": "payload",
"propertyType": "msg",
"key": "payload.value",
"joiner": ",",
"joinerType": "str",
"accumulate": false,
"timeout": "",
"count": "4",
"reduceRight": false,
"reduceExp": "",
"reduceInit": "",
"reduceInitType": "",
"reduceFixup": "",
"x": 350,
"y": 2100,
"wires": [
[
"0e8bab2558777f94"
]
]
},
{
"id": "0e8bab2558777f94",
"type": "function",
"z": "af671d82.d368a",
"name": "Functions",
"func": "let valueA = msg.payload[0].value;\nlet timeA = msg.payload[0].timestamp;\n\n\nlet valueB = msg.payload[1].value;\nlet timeB = msg.payload[1].timestamp;\n\n\nlet valueC = msg.payload[2].value;\nlet timeC = msg.payload[2].timestamp;\n\n\nlet valueD = msg.payload[3].value;\nlet timeD = msg.payload[3].timestamp;\n\n\nlet totA =(valueA *0)\nlet totB = (valueB-valueA)\nlet totC = (valueC - valueB)\nlet totD = (valueD - valueC)\n\nlet totS = (totA + totB + totC + totD)\n\nmsg.payload = { valueA, timeA, valueB, timeB, valueC, timeC, valueD, timeD, totA, totB, totC, totD, totS };\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 620,
"y": 2100,
"wires": [
[
"370b380ac22b2dc9"
]
]
},
{
"id": "370b380ac22b2dc9",
"type": "template",
"z": "af671d82.d368a",
"name": "",
"field": "payload",
"fieldType": "msg",
"format": "handlebars",
"syntax": "mustache",
"template": "Counter:{{payload.valueA}}\nIt been passing {{payload.totA}} persons between {{payload.timeA}} and {{payload.timeA}}\n\nCounter:{{payload.valueB}}\nIt been passing {{payload.totB}} persons between {{payload.timeA}} and {{payload.timeB}}\n\nCounter:{{payload.valueC}}\nIt been passing {{payload.totC}} persons between {{payload.timeB}} and {{payload.timeC}}\n\nCounter:{{payload.valueD}}\nIt been passing {{payload.totD}} persons between {{payload.timeC}} and {{payload.timeD}}\n\n\nTotal passages in between the period ({{payload.timeA}} and {{payload.timeD}}) is {{payload.totS}} persons",
"output": "str",
"x": 900,
"y": 2100,
"wires": [
[
"51d8b18577d5a17b"
]
]
}
]`
/Ola M