diff --git a/node-red-flows/meters.json b/node-red-flows/meters.json index 1d54d6f..79be5ba 100644 --- a/node-red-flows/meters.json +++ b/node-red-flows/meters.json @@ -539,108 +539,6 @@ ] ] }, - { - "id": "22bdca2522a4b3c9", - "type": "function", - "z": "f96eea4d4a3a345d", - "name": "format and save to global var", - "func": "temp = parseFloat(msg.payload * 0.001).toFixed(2);\nglobal.set(\"einspeisung_l1_import\", temp)\nreturn msg;", - "outputs": 1, - "noerr": 0, - "initialize": "", - "finalize": "", - "libs": [], - "x": 940, - "y": 500, - "wires": [ - [] - ] - }, - { - "id": "51dc86ef4b4e31fd", - "type": "function", - "z": "f96eea4d4a3a345d", - "name": "format and save to global var", - "func": "temp = parseFloat(msg.payload * 0.001).toFixed(2);\nglobal.set(\"einspeisung_l2_import\", temp)\nreturn msg;", - "outputs": 1, - "noerr": 0, - "initialize": "", - "finalize": "", - "libs": [], - "x": 940, - "y": 540, - "wires": [ - [] - ] - }, - { - "id": "804899fa9686be16", - "type": "function", - "z": "f96eea4d4a3a345d", - "name": "format and save to global var", - "func": "temp = parseFloat(msg.payload * 0.001).toFixed(2);\nglobal.set(\"einspeisung_l3_import\", temp)\nreturn msg;", - "outputs": 1, - "noerr": 0, - "initialize": "", - "finalize": "", - "libs": [], - "x": 940, - "y": 580, - "wires": [ - [] - ] - }, - { - "id": "ba0021b15f94fc41", - "type": "function", - "z": "f96eea4d4a3a345d", - "name": "format and save to global var", - "func": "temp = parseFloat(msg.payload * 0.001).toFixed(2);\nglobal.set(\"einspeisung_l1_export\", temp)\nreturn msg;", - "outputs": 1, - "noerr": 0, - "initialize": "", - "finalize": "", - "libs": [], - "x": 940, - "y": 620, - "wires": [ - [] - ] - }, - { - "id": "68157d83b4f176f5", - "type": "function", - "z": "f96eea4d4a3a345d", - "name": "format and save to global var", - "func": "temp = parseFloat(msg.payload * 0.001).toFixed(2);\nglobal.set(\"einspeisung_l2_export\", temp)\nreturn msg;", - "outputs": 1, - "noerr": 0, - "initialize": "", - "finalize": "", - "libs": [], - "x": 940, - "y": 660, - "wires": [ - [] - ] - }, - { - "id": "4d12b6c71b023fc8", - "type": "function", - "z": "f96eea4d4a3a345d", - "name": "format and save to global var", - "func": "temp = parseFloat(msg.payload * 0.001).toFixed(2);\nglobal.set(\"einspeisung_l3_export\", temp)\nreturn msg;", - "outputs": 1, - "noerr": 0, - "initialize": "", - "finalize": "", - "libs": [], - "x": 940, - "y": 700, - "wires": [ - [] - ] - }, { "id": "58942376d9fbdd07", "type": "inject", @@ -675,7 +573,7 @@ "type": "function", "z": "f96eea4d4a3a345d", "name": "Calculate kWh of sum power", - "func": "//init counters if not defined\nif (global.get(\"einspeisung_total_import\") === undefined) {\n global.set(\"einspeisung_total_import\", 0);\n}\nif (global.get(\"einspeisung_total_export\") === undefined) {\n global.set(\"einspeisung_total_export\", 0);\n}\n//get counters from global variable\nvar total_import = global.get(\"einspeisung_total_import\");\nvar total_export = global.get(\"einspeisung_total_export\");\nvar check = \"Nothing\";\n\nif (msg.payload < 0) {\n total_export += Math.abs(msg.payload);\n check = \"Export: \" + Math.abs(msg.payload) + \" kWh\";\n}\nif (msg.payload > 0) {\n total_import += Math.abs(msg.payload);\n check = \"Import: \" + Math.abs(msg.payload) + \" kWh\";\n}\n\nglobal.set(\"einspeisung_total_import\", total_import);\nglobal.set(\"einspeisung_total_export\", total_export);\nmsg.payload = {total_import: total_import, total_export: total_export, check: check}\nreturn msg;", + "func": "//init counters if not defined\nif (global.get(\"einspeisung_total_import\") === undefined) {\n global.set(\"einspeisung_total_import\", 0);\n}\nif (global.get(\"einspeisung_total_export\") === undefined) {\n global.set(\"einspeisung_total_export\", 0);\n}\n//get counters from global variable\nvar total_import = global.get(\"einspeisung_total_import\");\nvar total_export = global.get(\"einspeisung_total_export\");\nvar check = \"Nothing\";\n\n//check if usage (payload) is positive=import or negative=export\n//add diff to import or export counters\nif (msg.payload < 0) {\n total_export += Math.abs(msg.payload);\n check = \"Export: \" + Math.abs(msg.payload) + \" kWh\";\n}\nif (msg.payload > 0) {\n total_import += Math.abs(msg.payload);\n check = \"Import: \" + Math.abs(msg.payload) + \" kWh\";\n}\n\n//write result back to global vars and send a msg for debug\nglobal.set(\"einspeisung_total_import\", total_import);\nglobal.set(\"einspeisung_total_export\", total_export);\nmsg.payload = {total_import: total_import, total_export: total_export, check: check}\nreturn msg;", "outputs": 1, "noerr": 0, "initialize": "", @@ -714,7 +612,7 @@ "initialize": "", "finalize": "", "libs": [], - "x": 1440, + "x": 880, "y": 580, "wires": [ [] @@ -724,7 +622,7 @@ "id": "d905c25120cfdfd3", "type": "inject", "z": "f96eea4d4a3a345d", - "name": "Inject once", + "name": "Reset or init all counters (Set to Zero)", "props": [ { "p": "payload" @@ -741,7 +639,7 @@ "topic": "", "payload": "", "payloadType": "date", - "x": 1250, + "x": 260, "y": 580, "wires": [ [ @@ -802,7 +700,7 @@ "type": "function", "z": "f96eea4d4a3a345d", "name": "Calculate kWh of phase 1 power", - "func": "//init counters if not defined\nif (global.get(\"einspeisung_l1_import\") === undefined) {\n global.set(\"einspeisung_l1_import\", 0);\n}\nif (global.get(\"einspeisung_l1_export\") === undefined) {\n global.set(\"einspeisung_l1_export\", 0);\n}\n//get counters from global variable\nvar total_import = global.get(\"einspeisung_l1_import\");\nvar total_export = global.get(\"einspeisung_l1_export\");\nvar check = \"Nothing\";\n\nif (msg.payload < 0) {\n total_export += Math.abs(msg.payload);\n check = \"Export: \" + Math.abs(msg.payload) + \" kWh\";\n}\nif (msg.payload > 0) {\n total_import += Math.abs(msg.payload);\n check = \"Import: \" + Math.abs(msg.payload) + \" kWh\";\n}\n\nglobal.set(\"einspeisung_l1_import\", total_import);\nglobal.set(\"einspeisung_l1_export\", total_export);\nmsg.payload = {total_import: total_import, total_export: total_export, check: check}\nreturn msg;", + "func": "//init counters if not defined\nif (global.get(\"einspeisung_l1_import\") === undefined) {\n global.set(\"einspeisung_l1_import\", 0);\n}\nif (global.get(\"einspeisung_l1_export\") === undefined) {\n global.set(\"einspeisung_l1_export\", 0);\n}\n//get counters from global variable\nvar total_import = global.get(\"einspeisung_l1_import\");\nvar total_export = global.get(\"einspeisung_l1_export\");\nvar check = \"Nothing\";\n\n//check if usage (payload) is positive=import or negative=export\n//add diff to import or export counters\nif (msg.payload < 0) {\n total_export += Math.abs(msg.payload);\n check = \"Export: \" + Math.abs(msg.payload) + \" kWh\";\n}\nif (msg.payload > 0) {\n total_import += Math.abs(msg.payload);\n check = \"Import: \" + Math.abs(msg.payload) + \" kWh\";\n}\n//write result back to global vars and send a msg for debug\nglobal.set(\"einspeisung_l1_import\", total_import);\nglobal.set(\"einspeisung_l1_export\", total_export);\nmsg.payload = {total_import: total_import, total_export: total_export, check: check}\nreturn msg;", "outputs": 1, "noerr": 0, "initialize": "", @@ -819,7 +717,7 @@ "type": "function", "z": "f96eea4d4a3a345d", "name": "Calculate kWh of phase 2 power", - "func": "//init counters if not defined\nif (global.get(\"einspeisung_l2_import\") === undefined) {\n global.set(\"einspeisung_l2_import\", 0);\n}\nif (global.get(\"einspeisung_l2_export\") === undefined) {\n global.set(\"einspeisung_l2_export\", 0);\n}\n//get counters from global variable\nvar total_import = global.get(\"einspeisung_l2_import\");\nvar total_export = global.get(\"einspeisung_l2_export\");\nvar check = \"Nothing\";\n\nif (msg.payload < 0) {\n total_export += Math.abs(msg.payload);\n check = \"Export: \" + Math.abs(msg.payload) + \" kWh\";\n}\nif (msg.payload > 0) {\n total_import += Math.abs(msg.payload);\n check = \"Import: \" + Math.abs(msg.payload) + \" kWh\";\n}\n\nglobal.set(\"einspeisung_l2_import\", total_import);\nglobal.set(\"einspeisung_l2_export\", total_export);\nmsg.payload = {total_import: total_import, total_export: total_export, check: check}\nreturn msg;", + "func": "//init counters if not defined\nif (global.get(\"einspeisung_l2_import\") === undefined) {\n global.set(\"einspeisung_l2_import\", 0);\n}\nif (global.get(\"einspeisung_l2_export\") === undefined) {\n global.set(\"einspeisung_l2_export\", 0);\n}\n//get counters from global variable\nvar total_import = global.get(\"einspeisung_l2_import\");\nvar total_export = global.get(\"einspeisung_l2_export\");\nvar check = \"Nothing\";\n\n//check if usage (payload) is positive=import or negative=export\n//add diff to import or export counters\nif (msg.payload < 0) {\n total_export += Math.abs(msg.payload);\n check = \"Export: \" + Math.abs(msg.payload) + \" kWh\";\n}\nif (msg.payload > 0) {\n total_import += Math.abs(msg.payload);\n check = \"Import: \" + Math.abs(msg.payload) + \" kWh\";\n}\n\n//write result back to global vars and send a msg for debug\nglobal.set(\"einspeisung_l2_import\", total_import);\nglobal.set(\"einspeisung_l2_export\", total_export);\nmsg.payload = {total_import: total_import, total_export: total_export, check: check}\nreturn msg;", "outputs": 1, "noerr": 0, "initialize": "", @@ -836,7 +734,7 @@ "type": "function", "z": "f96eea4d4a3a345d", "name": "Calculate kWh of phase 3 power", - "func": "//init counters if not defined\nif (global.get(\"einspeisung_l3_import\") === undefined) {\n global.set(\"einspeisung_l3_import\", 0);\n}\nif (global.get(\"einspeisung_l3_export\") === undefined) {\n global.set(\"einspeisung_l3_export\", 0);\n}\n//get counters from global variable\nvar total_import = global.get(\"einspeisung_l3_import\");\nvar total_export = global.get(\"einspeisung_l3_export\");\nvar check = \"Nothing\";\n\nif (msg.payload < 0) {\n total_export += Math.abs(msg.payload);\n check = \"Export: \" + Math.abs(msg.payload) + \" kWh\";\n}\nif (msg.payload > 0) {\n total_import += Math.abs(msg.payload);\n check = \"Import: \" + Math.abs(msg.payload) + \" kWh\";\n}\n\nglobal.set(\"einspeisung_l3_import\", total_import);\nglobal.set(\"einspeisung_l3_export\", total_export);\nmsg.payload = {total_import: total_import, total_export: total_export, check: check}\nreturn msg;", + "func": "//init counters if not defined\nif (global.get(\"einspeisung_l3_import\") === undefined) {\n global.set(\"einspeisung_l3_import\", 0);\n}\nif (global.get(\"einspeisung_l3_export\") === undefined) {\n global.set(\"einspeisung_l3_export\", 0);\n}\n//get counters from global variable\nvar total_import = global.get(\"einspeisung_l3_import\");\nvar total_export = global.get(\"einspeisung_l3_export\");\nvar check = \"Nothing\";\n\n//check if usage (payload) is positive=import or negative=export\n//add diff to import or export counters\nif (msg.payload < 0) {\n total_export += Math.abs(msg.payload);\n check = \"Export: \" + Math.abs(msg.payload) + \" kWh\";\n}\nif (msg.payload > 0) {\n total_import += Math.abs(msg.payload);\n check = \"Import: \" + Math.abs(msg.payload) + \" kWh\";\n}\n\n//write result back to global vars and send a msg for debug\nglobal.set(\"einspeisung_l3_import\", total_import);\nglobal.set(\"einspeisung_l3_export\", total_export);\nmsg.payload = {total_import: total_import, total_export: total_export, check: check}\nreturn msg;", "outputs": 1, "noerr": 0, "initialize": "", @@ -847,5 +745,45 @@ "wires": [ [] ] + }, + { + "id": "8fe908e8e4e30699", + "type": "comment", + "z": "f96eea4d4a3a345d", + "name": "Write all values into global vars, to export them via a JSON-HTTP-API", + "info": "Write all values into global vars,\nto export them via a JSON-HTTP-API", + "x": 790, + "y": 80, + "wires": [] + }, + { + "id": "c648f182292dd923", + "type": "comment", + "z": "f96eea4d4a3a345d", + "name": "Read all global vars an create a JObject so we can poll it via HTTP", + "info": "Read all global vars an create a JObject so we can poll it via HTTP", + "x": 700, + "y": 820, + "wires": [] + }, + { + "id": "b38818b5fb6846af", + "type": "comment", + "z": "f96eea4d4a3a345d", + "name": "You can save global vars to a context file, if you enable \"Context storage\" in your Node-RED settings.json", + "info": "You can save global vars to a context file, if you enable \"Context storage\" in your Node-RED settings.json", + "x": 850, + "y": 720, + "wires": [] + }, + { + "id": "2413b4c69ccefdfb", + "type": "comment", + "z": "f96eea4d4a3a345d", + "name": "With Context storage all global vars are persisted bedween Node RED restarts", + "info": "With Context storage all global vars are persisted bedween Node RED restarts", + "x": 740, + "y": 760, + "wires": [] } ] \ No newline at end of file