Hi,
i always gettin a TypeError: Cannot read properties of undefined (reading 'TotalStartTime')"
If i want to use 2 Merged Messages in a Function Node.
When i connect the Node coming from Influx (Read) to the Function Node i gettin this TypeError above.
Here is my Flow:
[
{
"id": "53900d740b730748",
"type": "function",
"z": "3f086c32776e553e",
"name": "Werte prüfen/ Werte umwandeln",
"func": "var totalstarttime = msg.payload.ENERGY.TotalStartTime;\nvar totalkwh = msg.payload.ENERGY.Total;\nvar yesterdaykwh = msg.payload.ENERGY.Yesterday;\nvar todaykwh = msg.payload.ENERGY.Today;\nvar period = msg.payload.ENERGY.Period;\nvar watt = msg.payload.ENERGY.Power;\nvar voltage = msg.payload.ENERGY.Voltage;\nvar ampere = msg.payload.ENERGY.Current;\nvar factor = msg.payload.ENERGY.Factor;\nvar scheinleistung = msg.payload.ENERGY.ApparentPower;\nvar blindleistung = msg.payload.ENERGY.ReactivePower;\n\n\n msg.payload = {\n totalstarttime: totalstarttime,\n totalkwh: totalkwh,\n yesterdaykwh: yesterdaykwh,\n todaykwh: todaykwh,\n period: period,\n watt: watt,\n voltage: voltage,\n ampere: ampere,\n factor: factor,\n scheinleistung: scheinleistung,\n blindleistung: blindleistung\n }\nreturn msg;\n\n\n\n",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 700,
"y": 100,
"wires": [
[
"aac3aa3e82b0541d"
]
]
},
{
"id": "6afb76d9e25fac8c",
"type": "function",
"z": "3f086c32776e553e",
"name": "Query Totalkwh auslesen",
"func": "msg.query ='SELECT totalkwh FROM solarkraftwerk ORDER BY time DESC LIMIT 1';\nreturn msg; ",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 210,
"y": 240,
"wires": [
[
"dc2fad0f6c3ce051"
]
]
},
{
"id": "dc2fad0f6c3ce051",
"type": "influxdb in",
"z": "3f086c32776e553e",
"influxdb": "0e895e68048f325c",
"name": "InfluxDB Solarkraftwerk Read",
"query": "",
"rawOutput": false,
"precision": "",
"retentionPolicy": "",
"org": "organisation",
"x": 500,
"y": 240,
"wires": [
[
"8ecaf0e23257306c"
]
]
},
{
"id": "4adb842cb842dae2",
"type": "inject",
"z": "3f086c32776e553e",
"name": "Total 0",
"props": [
{
"p": "payload"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "{\"Time\":1667822720,\"Switch1\":\"OFF\",\"ENERGY\":{\"TotalStartTime\":\"2022-10-29T18:30:48\",\"Total\":0,\"Yesterday\":1.818,\"Today\":0.15,\"Period\":1,\"Power\":27,\"ApparentPower\":43,\"ReactivePower\":33,\"Factor\":0.63,\"Voltage\":237,\"Current\":0.18}}",
"payloadType": "json",
"x": 110,
"y": 80,
"wires": [
[
"6afb76d9e25fac8c",
"d1ac6107bfffcb81"
]
]
},
{
"id": "8ecaf0e23257306c",
"type": "change",
"z": "3f086c32776e553e",
"name": "",
"rules": [
{
"t": "move",
"p": "payload[0]",
"pt": "msg",
"to": "payload",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 770,
"y": 240,
"wires": [
[
"d1ac6107bfffcb81"
]
]
},
{
"id": "d1ac6107bfffcb81",
"type": "join",
"z": "3f086c32776e553e",
"name": "",
"mode": "custom",
"build": "merged",
"property": "payload",
"propertyType": "msg",
"key": "payload",
"joiner": "\\n",
"joinerType": "str",
"accumulate": false,
"timeout": "",
"count": "2",
"reduceRight": false,
"reduceExp": "",
"reduceInit": "",
"reduceInitType": "",
"reduceFixup": "",
"x": 1030,
"y": 200,
"wires": [
[
"53900d740b730748"
]
]
},
{
"id": "aac3aa3e82b0541d",
"type": "debug",
"z": "3f086c32776e553e",
"name": "debug 4",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 1040,
"y": 120,
"wires": []
},
{
"id": "0e895e68048f325c",
"type": "influxdb",
"hostname": "xxx",
"port": "8086",
"protocol": "http",
"database": "solarkraftwerk",
"name": "InfluxDB Solarkraftwerk",
"usetls": false,
"tls": "",
"influxdbVersion": "1.x",
"url": "http://localhost:8086",
"rejectUnauthorized": true
}
]
My Function Node looks like this:
var totalstarttime = msg.payload.ENERGY.TotalStartTime;
var totalkwh = msg.payload.ENERGY.Total;
var yesterdaykwh = msg.payload.ENERGY.Yesterday;
var todaykwh = msg.payload.ENERGY.Today;
var period = msg.payload.ENERGY.Period;
var watt = msg.payload.ENERGY.Power;
var voltage = msg.payload.ENERGY.Voltage;
var ampere = msg.payload.ENERGY.Current;
var factor = msg.payload.ENERGY.Factor;
var scheinleistung = msg.payload.ENERGY.ApparentPower;
var blindleistung = msg.payload.ENERGY.ReactivePower;
msg.payload = {
totalstarttime: totalstarttime,
totalkwh: totalkwh,
yesterdaykwh: yesterdaykwh,
todaykwh: todaykwh,
period: period,
watt: watt,
voltage: voltage,
ampere: ampere,
factor: factor,
scheinleistung: scheinleistung,
blindleistung: blindleistung
}
return msg;
MQTT IN Node:
{"Time":1667822720,"Switch1":"OFF","ENERGY":{"TotalStartTime":"2022-10-29T18:30:48","Total":0,"Yesterday":1.818,"Today":0.15,"Period":1,"Power":27,"ApparentPower":43,"ReactivePower":33,"Factor":0.63,"Voltage":237,"Current":0.18}}
Join Node: A Merged Object after 2 Messages
My Goal is it to read the Total Energy History from Influx Database and compare it in the Function Node with the actually value