Der Thread ist zwar inzwischen schon etwas älter, aber da ich beim Suchen nach anderen Infos auf ihn aufmerksam geworden bin und auch gerade in den Vorbereitungen für diverse Auswertungen von Daten bin, kam mir das Thema gelegen und ich habe versucht, die hier geposteten Ansätze mal nachzubauen.
Noch angemerkt, meine Kenntnisse in Sachen ioB, NodeRed und JS sind noch recht begrenzt.
Grundgedanke: alle 3 Phasen sollen (permanent/mit Intervall) auf Veränderungen abgefragt werden, und aus den Werten, so denn vorhanden, die Summer ermittelt werden und in einen Datenpunkt (ioB/MQTT) geschrieben werden. Soweit so gut. Hab da aber auch jeden Fall schon konkretere Vorstellungen als @siporax in welche Richtung es gehen soll.
Bei der Variante mit der functionNode hole ich mir die Daten mit der ioB-in-Node, mit Join verbinden und in der functionNode berechnen. Nur das Berechnen funktioniert bei mir erst dann vollständig, wenn mindestens alle 3 Datenpunkte einmal aktualisiert wurden.
Gleiches scheint bei der Variante 2x changeNode von @mickym zu sein.
Was mache ich falsch oder was übersehe ich?
Bei der dritten Variante, Datenpunkte nach injectNode abfragen, funktioniert soweit alles, aber es ist ja angedacht, dass die Werte bei Veränderung 'abgeholt' und berechnet werden. In dem Fall habe ich mir mit einer ioB-in-Node und anschließen einer changeNode ohne Regeln weitergeholfen. Sicher nicht die beste Lösung, aber was machen wenn man zu doof oder zu doof ist, nodeRed und/oder JS zu verstehen...
Eins ist aber dennoch interessant an der Sache: bei allen 3 Varianten wird der Wert für L2 IMMER sofort abgeholt! Warum auch immer.
Btw. Der Vollständigkeit halber, da @Jacke Blockly erwähnte: habe Gleiches, also Daten holen nach Änderung/en, ausrechnen, an/in MQTT/ioB-Datenpunkt schreiben, in kaum 30 Min. zusammen 'geschustert' und nach weiteren knapp 30 Min sah das Ganze auch halbwegs übersichtlich aus und hat sogar noch 'Tendenz-Info' bekommen. Auch hier, erst mal nur mit meinem aktuellen, doch noch recht beschränktem Wissen.
Da ich noch keine Daten für die 3 Phasen erfassen kann hab ich mich bei Temeratursensoren bedien... 's geht, ja erst mal um's Gurndsätzliche.
Hier mal Screenshots von Node-Red und Blockly
Und der Code...
[
{
"id": "fb47b7d546e2b4ec",
"type": "tab",
"label": "Flow 9",
"disabled": false,
"info": "",
"env": []
},
{
"id": "1238a9470f81ac99",
"type": "function",
"z": "fb47b7d546e2b4ec",
"name": "function 6",
"func": "var L1, L2, L3 = 0;\nif (msg.topic === \"alias/0/Grid/GridHome/L1\") context.set(\"L1\", msg.payload[\"alias/0/Grid/GridHome/L1\"]);\nif (msg.topic === \"alias/0/Grid/GridHome/L2\") context.set(\"L2\", msg.payload[\"alias/0/Grid/GridHome/L2\"]);\nif (msg.topic === \"alias/0/Grid/GridHome/L3\") context.set(\"L3\", msg.payload[\"alias/0/Grid/GridHome/L3\"]);\n\nL1 = context.get(\"L1\" || 0);\nL2 = context.get(\"L2\" || 0);\nL3 = context.get(\"L3\" || 0); \n\nmsg.payload = (L1 + L2 + L3);\n// msg.payload = (L1 + L2 + L3);\n\nreturn msg;",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 560,
"y": 100,
"wires": [
[
"3b3f83cc2b2c710e",
"d419b93fcd0c50bb",
"beed7e1d8aeba85c"
]
]
},
{
"id": "2d63044d06f5f168",
"type": "debug",
"z": "fb47b7d546e2b4ec",
"name": "debug 9.6.2",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 170,
"y": 100,
"wires": []
},
{
"id": "399d9b7ab5e6c96a",
"type": "debug",
"z": "fb47b7d546e2b4ec",
"name": "debug 9.6.3",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 170,
"y": 340,
"wires": []
},
{
"id": "37bea2fc3821ecf1",
"type": "debug",
"z": "fb47b7d546e2b4ec",
"name": "debug 9.6.3",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 170,
"y": 220,
"wires": []
},
{
"id": "c4ed9bb19bd931a4",
"type": "join",
"z": "fb47b7d546e2b4ec",
"name": "",
"mode": "custom",
"build": "object",
"property": "payload",
"propertyType": "msg",
"key": "topic",
"joiner": "\\n",
"joinerType": "str",
"accumulate": true,
"timeout": "",
"count": "1",
"reduceRight": false,
"reduceExp": "",
"reduceInit": "",
"reduceInitType": "",
"reduceFixup": "",
"x": 390,
"y": 100,
"wires": [
[
"9e12902d4bf4665e",
"1238a9470f81ac99"
]
]
},
{
"id": "9e12902d4bf4665e",
"type": "debug",
"z": "fb47b7d546e2b4ec",
"name": "debug 9.6.4",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 430,
"y": 160,
"wires": []
},
{
"id": "1d99d6cc13089cd2",
"type": "ioBroker in",
"z": "fb47b7d546e2b4ec",
"name": "",
"attrname": "payload",
"topic": "alias.0.Grid.GridHome.L1",
"payloadType": "value",
"onlyack": "",
"func": "all",
"gap": "",
"fireOnStart": "false",
"outFormat": "MQTT",
"x": 130,
"y": 40,
"wires": [
[
"c4ed9bb19bd931a4",
"2d63044d06f5f168"
]
]
},
{
"id": "3b3f83cc2b2c710e",
"type": "debug",
"z": "fb47b7d546e2b4ec",
"name": "debug 9.6.5",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 750,
"y": 160,
"wires": []
},
{
"id": "5dcac88d0577f3fe",
"type": "ioBroker in",
"z": "fb47b7d546e2b4ec",
"name": "",
"attrname": "payload",
"topic": "alias.0.Grid.GridHome.L2",
"payloadType": "value",
"onlyack": "",
"func": "all",
"gap": "",
"fireOnStart": "false",
"outFormat": "MQTT",
"x": 130,
"y": 160,
"wires": [
[
"c4ed9bb19bd931a4",
"37bea2fc3821ecf1"
]
]
},
{
"id": "5a5366652ecdade5",
"type": "ioBroker in",
"z": "fb47b7d546e2b4ec",
"name": "",
"attrname": "payload",
"topic": "alias.0.Grid.GridHome.L3",
"payloadType": "value",
"onlyack": "",
"func": "all",
"gap": "",
"fireOnStart": "false",
"outFormat": "MQTT",
"x": 130,
"y": 280,
"wires": [
[
"c4ed9bb19bd931a4",
"399d9b7ab5e6c96a"
]
]
},
{
"id": "a872a7ba51fd3484",
"type": "inject",
"z": "fb47b7d546e2b4ec",
"name": "",
"props": [
{
"p": "trigger",
"v": "true",
"vt": "bool"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"x": 390,
"y": 640,
"wires": [
[
"256da960d23f9755"
]
]
},
{
"id": "256da960d23f9755",
"type": "ioBroker get",
"z": "fb47b7d546e2b4ec",
"name": "L1",
"topic": "alias.0.Grid.GridHome.L1",
"attrname": "L1",
"payloadType": "value",
"errOnInvalidState": "nothing",
"x": 530,
"y": 680,
"wires": [
[
"a4730fef776c6647"
]
]
},
{
"id": "a4730fef776c6647",
"type": "ioBroker get",
"z": "fb47b7d546e2b4ec",
"name": "L2",
"topic": "alias.0.Grid.GridHome.L2",
"attrname": "L2",
"payloadType": "value",
"errOnInvalidState": "nothing",
"x": 650,
"y": 680,
"wires": [
[
"0f84e002a70cacc1"
]
]
},
{
"id": "c5166dda9c56917b",
"type": "debug",
"z": "fb47b7d546e2b4ec",
"name": "Summe",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 840,
"y": 680,
"wires": []
},
{
"id": "9685e5e1edcb1ba4",
"type": "change",
"z": "fb47b7d546e2b4ec",
"name": "",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "$round((L1 + L2 + L3),4)",
"tot": "jsonata"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 810,
"y": 740,
"wires": [
[
"c5166dda9c56917b"
]
]
},
{
"id": "0f84e002a70cacc1",
"type": "ioBroker get",
"z": "fb47b7d546e2b4ec",
"name": "L3",
"topic": "alias.0.Grid.GridHome.L3",
"attrname": "L3",
"payloadType": "value",
"errOnInvalidState": "nothing",
"x": 650,
"y": 740,
"wires": [
[
"9685e5e1edcb1ba4"
]
]
},
{
"id": "d9b451ed1ef8f471",
"type": "ioBroker in",
"z": "fb47b7d546e2b4ec",
"name": "",
"attrname": "payload",
"topic": "alias.0.Grid.GridHome.L1",
"payloadType": "value",
"onlyack": "",
"func": "all",
"gap": "",
"fireOnStart": "false",
"outFormat": "MQTT",
"x": 130,
"y": 640,
"wires": [
[
"7eeb50a189819a75"
]
]
},
{
"id": "7eeb50a189819a75",
"type": "change",
"z": "fb47b7d546e2b4ec",
"name": "",
"rules": [],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 370,
"y": 700,
"wires": [
[
"256da960d23f9755"
]
]
},
{
"id": "5aaed265aab69983",
"type": "ioBroker in",
"z": "fb47b7d546e2b4ec",
"name": "",
"attrname": "payload",
"topic": "alias.0.Grid.GridHome.L2",
"payloadType": "value",
"onlyack": "",
"func": "all",
"gap": "",
"fireOnStart": "false",
"outFormat": "MQTT",
"x": 130,
"y": 700,
"wires": [
[
"7eeb50a189819a75"
]
]
},
{
"id": "63b5caefee96f50c",
"type": "ioBroker in",
"z": "fb47b7d546e2b4ec",
"name": "",
"attrname": "payload",
"topic": "alias.0.Grid.GridHome.L3",
"payloadType": "value",
"onlyack": "",
"func": "all",
"gap": "",
"fireOnStart": "false",
"outFormat": "MQTT",
"x": 130,
"y": 760,
"wires": [
[
"7eeb50a189819a75"
]
]
},
{
"id": "d419b93fcd0c50bb",
"type": "mqtt out",
"z": "fb47b7d546e2b4ec",
"name": "HomeGridSummary (2)",
"topic": "homegrid/phases/phases_sum2",
"qos": "",
"retain": "",
"respTopic": "",
"contentType": "",
"userProps": "",
"correl": "",
"expiry": "",
"broker": "dddaa640df8fba6b",
"x": 780,
"y": 100,
"wires": []
},
{
"id": "beed7e1d8aeba85c",
"type": "ioBroker out",
"z": "fb47b7d546e2b4ec",
"name": "HomeGridSummary",
"topic": "0_userdata.0.HomeGrid.HomeGrid_Summary",
"ack": "true",
"autoCreate": "false",
"stateName": "",
"role": "",
"payloadType": "",
"readonly": "",
"stateUnit": "",
"stateMin": "",
"stateMax": "",
"x": 770,
"y": 40,
"wires": []
},
{
"id": "07ae2369fe461fbe",
"type": "change",
"z": "fb47b7d546e2b4ec",
"name": "topic: L1",
"rules": [
{
"t": "set",
"p": "topic",
"pt": "msg",
"to": "L1",
"tot": "str"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 360,
"y": 420,
"wires": [
[
"a244a31c5bcbea91"
]
]
},
{
"id": "bf7144a4e29d4279",
"type": "change",
"z": "fb47b7d546e2b4ec",
"name": "topic: L2",
"rules": [
{
"t": "set",
"p": "topic",
"pt": "msg",
"to": "L2",
"tot": "str"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 360,
"y": 480,
"wires": [
[
"a244a31c5bcbea91"
]
]
},
{
"id": "64441cb4c466b694",
"type": "change",
"z": "fb47b7d546e2b4ec",
"name": "topic: L3",
"rules": [
{
"t": "set",
"p": "topic",
"pt": "msg",
"to": "L3",
"tot": "str"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 360,
"y": 540,
"wires": [
[
"a244a31c5bcbea91"
]
]
},
{
"id": "a244a31c5bcbea91",
"type": "join",
"z": "fb47b7d546e2b4ec",
"name": "",
"mode": "custom",
"build": "object",
"property": "payload",
"propertyType": "msg",
"key": "topic",
"joiner": "\\n",
"joinerType": "str",
"accumulate": true,
"timeout": "",
"count": "3",
"reduceRight": false,
"reduceExp": "",
"reduceInit": "",
"reduceInitType": "",
"reduceFixup": "",
"x": 550,
"y": 480,
"wires": [
[
"add94d9ab1b506bd"
]
]
},
{
"id": "3ceea4dfeb31a8e4",
"type": "debug",
"z": "fb47b7d546e2b4ec",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 750,
"y": 540,
"wires": []
},
{
"id": "add94d9ab1b506bd",
"type": "change",
"z": "fb47b7d546e2b4ec",
"name": "",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "payload.L1 + payload.L2 + payload.L3",
"tot": "jsonata"
},
{
"t": "set",
"p": "topic",
"pt": "msg",
"to": "Summe von L1,L2,L3",
"tot": "str"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 730,
"y": 480,
"wires": [
[
"3ceea4dfeb31a8e4"
]
]
},
{
"id": "af27203b1ea10edc",
"type": "ioBroker in",
"z": "fb47b7d546e2b4ec",
"name": "",
"attrname": "payload",
"topic": "alias.0.Grid.GridHome.L1",
"payloadType": "value",
"onlyack": "",
"func": "all",
"gap": "",
"fireOnStart": "false",
"outFormat": "MQTT",
"x": 130,
"y": 420,
"wires": [
[
"07ae2369fe461fbe"
]
]
},
{
"id": "f9752f905b3825cb",
"type": "ioBroker in",
"z": "fb47b7d546e2b4ec",
"name": "",
"attrname": "payload",
"topic": "alias.0.Grid.GridHome.L2",
"payloadType": "value",
"onlyack": "",
"func": "all",
"gap": "",
"fireOnStart": "false",
"outFormat": "MQTT",
"x": 130,
"y": 480,
"wires": [
[
"bf7144a4e29d4279"
]
]
},
{
"id": "c7ba8809df9440d9",
"type": "ioBroker in",
"z": "fb47b7d546e2b4ec",
"name": "",
"attrname": "payload",
"topic": "alias.0.Grid.GridHome.L3",
"payloadType": "value",
"onlyack": "",
"func": "all",
"gap": "",
"fireOnStart": "false",
"outFormat": "MQTT",
"x": 130,
"y": 540,
"wires": [
[
"64441cb4c466b694"
]
]
},
{
"id": "dddaa640df8fba6b",
"type": "mqtt-broker",
"name": "HomeGridSummary",
"broker": "localhost",
"port": "1884",
"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": ""
}
]
für Blockly
var Phase_L1, phases_summary, Phase_L2, tendency, summary_old, Phase_L3;
// Beschreibe diese Funktion …
async function get_data() {
Phase_L1 = getState('alias.0.Grid.GridHome.L1').val;
Phase_L2 = getState('alias.0.Grid.GridHome.L2').val;
Phase_L3 = getState('alias.0.Grid.GridHome.L3').val;
if (getState('mqtt.2.homegrid.phases.phases_sum').val) {
summary_old = getState('mqtt.2.homegrid.phases.phases_sum').val;
}
}
// Beschreibe diese Funktion …
async function debug_show_data() {
// weglassen/deaktivieren fall nicht gebraucht
console.log((['Die Summe über alle 3 Phasen beträgt: ',phases_summary,' | Tendenz ',tendency].join('')));
}
// Beschreibe diese Funktion …
async function calculate_summary() {
phases_summary = Math.round(((Phase_L1 + Phase_L2 + Phase_L3) / 3) * 1000) / 1000;
}
// Beschreibe diese Funktion …
async function send_data() {
sendTo('mqtt.2', 'sendMessage2Client', { topic: 'homegrid/phases/phases_L1', message: Phase_L1, retain: true }, (res) => { if (res && res.error) { console.error(res.error); } });sendTo('mqtt.2', 'sendMessage2Client', { topic: 'homegrid/phases/phases_L2', message: Phase_L2, retain: true }, (res) => { if (res && res.error) { console.error(res.error); } });sendTo('mqtt.2', 'sendMessage2Client', { topic: 'homegrid/phases/phases_L3', message: Phase_L3, retain: true }, (res) => { if (res && res.error) { console.error(res.error); } });sendTo('mqtt.2', 'sendMessage2Client', { topic: 'homegrid/phases/phases_sum', message: phases_summary, retain: true }, (res) => { if (res && res.error) { console.error(res.error); } });sendTo('mqtt.2', 'sendMessage2Client', { topic: 'homegrid/phases/tendency', message: tendency, retain: true }, (res) => { if (res && res.error) { console.error(res.error); } });}
// Beschreibe diese Funktion …
async function calculate_tendency() {
if (Math.round(phases_summary * 100) / 100 == Math.round(summary_old * 100) / 100) {
tendency = '⏺' + ' gleichbleibend';
} else if (phases_summary < summary_old) {
tendency = '🔽' + ' fallend';
} else if (phases_summary > summary_old) {
tendency = '🔼' + ' steigend';
} else {
tendency = '❓' + ' unbekannt';
}
summary_old = phases_summary;
}
on({ id: [].concat(['alias.0.Grid.GridHome.L1']).concat(['alias.0.Grid.GridHome.L2']).concat(['alias.0.Grid.GridHome.L3']), change: 'ne' }, async (obj) => {
await get_data();
await calculate_summary();
await calculate_tendency();
await debug_show_data();
await send_data();
});
Ooops, ist dann doch ganz schön lang geworden... Sorry.
Falls jemand findet/sieht, was ich 'vergurkt' habe... tät mich über Hinweise freuen. Danke im Voraus