[{"id":"7f9ef685.babe58","type":"tab","label":"Batteriesteuerung","disabled":false,"info":""},{"id":"3196ab6e.763eb4","type":"group","z":"7f9ef685.babe58","name":"Simulation Smartmeter","style":{"label":true},"nodes":["245139dc.5e5396","578c5085.40056","f9c2a914.4630b8","fe3ea8a0.e1cda8","d1f075ac.46ff38","14b3a79c.9bc058","662ed225.bb617c","c330383e.c26a68","1bfbc86d.58b058","3a567802.42d478","b20cd441.b8baa8","f625cf0e.63f34","fac7ff18.40136","eba40ee7.35d49","4349ad49.726984","a30d5958.888328","87ac7ea2.426f8","6c1b854f.8f65bc","4179d476.6bc0ec","c426e351.aa073","75cf7210.3ffb5c"],"x":94,"y":96.5,"w":1212,"h":627},{"id":"e9c802e2.9d6c","type":"group","z":"7f9ef685.babe58","name":"Get inverter commands from Google Sheet","style":{"label":true},"nodes":["f33394ef.df1698","7fb207bc.5a2898","cad781dc.7c0a2","35715c6e.649124","3ce6e387.439cec","354f004a.a9bc2","4cfd3297.c4e7dc","3b0e67c8.0a6bb8","17c7aec8.a64a01","5f27b4a7.2e07ec","142ee3e5.198fec","63db62b4.43e40c","5dbb76a.8d17688","24d5551.a74cbaa","8e323c6b.3df72","70b60e20.81d1c","ca8680ed.f1411","1334cc03.3348b4","880d5006.9be55"],"x":94,"y":759,"w":1358,"h":362},{"id":"5f27b4a7.2e07ec","type":"group","z":"7f9ef685.babe58","g":"e9c802e2.9d6c","style":{"stroke":"#3a3a3a","stroke-opacity":"1","fill":"#1e1e1e","fill-opacity":"0.5","label":true,"label-position":"nw","color":"#cccccc"},"nodes":["18a2d084.fe472f","15ea06a5.c89879"],"x":1194,"y":819,"w":232,"h":142},{"id":"245139dc.5e5396","type":"modbus-server","z":"7f9ef685.babe58","g":"3196ab6e.763eb4","name":"NodeRed-MB-Smartmeter Grid","logEnabled":true,"hostname":"192.168.1.65","serverPort":"502","responseDelay":100,"delayUnit":"ms","coilsBufferSize":10000,"holdingBufferSize":"41000","inputBufferSize":10000,"discreteBufferSize":10000,"showErrors":true,"x":1110,"y":160,"wires":[[],[],[],[],[]]},{"id":"578c5085.40056","type":"modbus-flex-write","z":"7f9ef685.babe58","g":"3196ab6e.763eb4","name":"","showStatusActivities":true,"showErrors":true,"server":"46f72e91930e4509","emptyMsgOnFail":false,"keepMsgProperties":false,"x":1170,"y":240,"wires":[[],[]]},{"id":"f9c2a914.4630b8","type":"function","z":"7f9ef685.babe58","g":"3196ab6e.763eb4","name":"Write Headers","func":"const registers = [40000, 40001, 40002, 40003, 40004, 40005, 40006, 40007, 40008, 40009,\n    40010, 40011, 40012, 40013, 40014, 40015, 40016, 40017, 40018, 40019,\n    40020, 40021, 40022, 40023, 40024, 40025, 40026, 40027, 40028, 40029,\n    40030, 40031, 40032, 40033, 40034, 40035, 40036, 40037, 40038, 40039,\n    40040, 40041, 40042, 40043, 40044, 40045, 40046, 40047, 40048, 40049,\n    40050, 40051, 40052, 40053, 40054, 40055, 40056, 40057, 40058, 40059,\n    40060, 40061, 40062, 40063, 40064, 40065, 40066, 40067, 40068, 40069,\n    40070, 40071, 40072, 40073, 40074, 40075, 40076, 40077, 40078, 40079,\n    40080, 40081, 40082, 40083, 40084, 40085, 40086, 40087, 40088, 40089,\n    40090, 40091, 40092, 40093, 40094, 40095, 40096, 40097, 40098, 40099,\n    40100, 40101, 40102, 40103, 40104, 40105, 40106, 40107, 40108, 40109,\n    40110, 40111, 40112, 40113, 40114, 40115, 40116, 40117, 40118, 40119,\n    40120, 40121, 40122, 40123, 40124, 40125, 40126, 40127, 40128, 40129,\n    40130, 40131, 40132, 40133, 40134, 40135, 40136, 40137, 40138, 40139,\n    40140, 40141, 40142, 40143, 40144, 40145, 40146, 40147, 40148, 40149,\n    40150, 40151, 40152, 40153, 40154, 40155, 40156, 40157, 40158, 40159,\n    40160, 40161, 40162, 40163, 40164, 40165, 40166, 40167, 40168, 40169,\n    40170, 40171, 40172, 40173, 40174, 40175, 40176, 40177, 40178, 40179,\n    40180, 40181, 40182, 40183, 40184, 40185, 40186, 40187, 40188, 40189,\n    40190, 40191, 40192, 40193, 40194, 40195, 40196, 40197 ];\n\nconst values = [21365, 28243, 1, 65, 18034, 28526, 26997, 29440, 0, 0,\n    0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n    21357, 24946, 29728, 19813, 29797, 29216, 21587, 8246, 13633, 11571, \n    0, 0, 0, 0, 0, 0, 15472, 29289, 28001, 29305,\n    15872, 0, 0, 0, 12590, 13056, 0, 0, 0, 0,\n    //0, 0, 13111, 13111, 13111, 12851, 13360, 0, 0, 0,\n    0, 0, 12848, 14645, 13364, 14645, 12597, 0, 0, 0,\n    0, 0, 0, 0, 0, 0, 0, 0, 1, 213,\n    124, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n    0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n    0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n    0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n    0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n    0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n    0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n    0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n    0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n    0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n    0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n    0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n    0, 0, 0, 0, 0, 0, 65535, 0 ]\n\nconst reg1 = registers.map(reg => reg)\nconst reg2 = reg1.splice(100)\nconst values2 = values.splice(100)\n\nconst p1 = {\n    'value': values,\n    'fc': 16,\n    'unitid': 1,\n    'address': reg1,\n    'quantity': values.length\n}\nconst p2 = {\n    'value': values2,\n    'fc': 16,\n    'unitid': 1,\n    'address': reg2,\n    'quantity': values2.length\n}\n\nnode.send({payload: p1})\nnode.send({payload: p2})\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":580,"y":240,"wires":[["578c5085.40056"]]},{"id":"fe3ea8a0.e1cda8","type":"inject","z":"7f9ef685.babe58","g":"3196ab6e.763eb4","name":"","props":[],"repeat":"","crontab":"","once":true,"onceDelay":"1","topic":"","payloadType":"str","x":230,"y":240,"wires":[["f9c2a914.4630b8"]]},{"id":"d1f075ac.46ff38","type":"function","z":"7f9ef685.babe58","g":"3196ab6e.763eb4","name":"Symo","func":"\nvar Grid = msg.payload;\n\nmsg.inverterdata = {\n    Current_AC: 0,\n    Current_AC_Phase_1: 0,\n    Current_AC_Phase_2: 0,\n    Current_AC_Phase_3: 0,\n    Voltage_AC_Phase_1: 239.0,\n    Voltage_AC_Phase_2: 238.0,\n    Voltage_AC_Phase_3: 239.0,\n    Voltage_AC_Phase_Avg: 239.0,\n    Voltage_AC_PhaseToPhase_12: 400.0,\n    Voltage_AC_PhaseToPhase_23: 401.0,\n    Voltage_AC_PhaseToPhase_31: 339.0,\n    Voltage_AC_PhaseToPhase_Avg: 400.0,\n\n    Frequency_Phase_Average: 49.9,\n    PowerReal_AC_Grid: Grid,\n    PowerReal_AC_Phase_1: Grid,\n    PowerReal_AC_Phase_2: 0,\n    PowerReal_AC_Phase_3: 0,\n    PowerApparent_AC: 0,  //Scheinleistung\n    PowerApparent_AC_Phase_1: 0,\n    PowerApparent_AC_Phase_2: 0,\n    PowerApparent_AC_Phase_3: 0,\n    PowerReactive_AC: 0,\n    PowerReactive_AC_Phase_1: 0,\n    PowerReactive_AC_Phase_2: 0,\n    PowerReactive_AC_Phase_3: 0,\n    PowerFactor_AC: 1,\n    PowerFactor_AC_Phase_1: 1,\n    PowerFactor_AC_Phase_2: 1,\n    PowerFactor_AC_Phase_3: 1,\n    E_Grid_Exported: 0, //TotalExportiert,\n    E_Grid_Exported_Phase_1: 0,\n    E_Grid_Exported_Phase_2: 0,\n    E_Grid_Exported_Phase_3: 0,\n    E_Grid_Imported: 0, //TotalImportiert,\n    E_Grid_Imported_Phase_1: 0,\n    E_Grid_Imported_Phase_2: 0,\n    E_Grid_Imported_Phase_3: 0\n}\n\n\n\nfunction tofloatregisters(value) {\n    var buf = Buffer.alloc(4);\n    buf.writeFloatBE(value);\n    return [(buf[0] * 256 + buf[1]), (buf[2] * 256) + buf[3]]\n}\n\nvar registers = [];\nvar values = [];\nvar i = 40071;\n\nfor (var key of Object.keys(msg.inverterdata)) {\n    registers.push(i, i + 1)\n    for (var val of tofloatregisters(msg.inverterdata[key])) values.push(val);\n    i = i + 2;\n}\n\nconst modbusmessage = {\n    'value': values,\n    'fc': 16,\n    'unitid': 1,\n    'address': registers,\n    'quantity': values.length\n}\n\nreturn ({ payload: modbusmessage })","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":970,"y":360,"wires":[["c330383e.c26a68","578c5085.40056"]]},{"id":"14b3a79c.9bc058","type":"inject","z":"7f9ef685.babe58","g":"3196ab6e.763eb4","name":"Get Data","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"10","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"782\":null}","payloadType":"json","x":210,"y":300,"wires":[["662ed225.bb617c"]],"info":"{\"801\":{\"170\":null}}\n\n{\"780\":null,\"781\":null,\"782\":null,\"801\":{\"130\":null,\"170\":null}}"},{"id":"662ed225.bb617c","type":"http request","z":"7f9ef685.babe58","g":"3196ab6e.763eb4","name":"Request SolarLog","method":"POST","ret":"obj","paytoqs":"ignore","url":"http://192.168.1.4/getjp","tls":"","persist":false,"proxy":"","authType":"","x":410,"y":300,"wires":[["1bfbc86d.58b058","75cf7210.3ffb5c"]],"info":"JSON Objekte\nDatenpunkt \t\t    Werteb. Einh.\tIndex\tBeschreibung\nlastUpdateTime \t    DWORD\tZeit\t100 \tUhrzeit\nPac \t\t\t    DWORD \tW \t    101 \tGesamte Leistung PAC von allen Wechselrichtern und Zählern im Wechselrichtermodus\nPdc \t\t\t    DWORD \tW \t    102 \tGesamte Leistung PAC von allen Wechselrichtern\nUac \t\t\t    WORD \tV \t    103 \tDurchschnittliche Spannung UAC der Wechselrichter\nUdc \t\t\t    WORD \tV \t    104 \tDurchschnittliche Spannung UDC der Wechselrichter\nyieldDay \t\t    DWORD \tWh \t    105 \tSummierter Tagesertrag aller Wechselrichter\nyieldYesterday\t    DWORD \tWh \t    106 \tSummierter gestriger Tagesertrag aller Wechselrichter\nyieldMonth \t\t    DWORD \tWh \t    107 \tSummierter Monatsertrag aller Wechselrichter\nyieldYear \t\t    DWORD \tWh \t    108 \tSummierter Jahresertrag aller Wechselrichter\nyieldTotal \t\t    DWORD \tWh \t    109 \tGesamtertrag aller Wechselrichter\nconsPac \t\t    DWORD \tW \t    110 \tMomentaner Gesamtverbrauch PAC aller Verbrauchszähler\nconsYieldDay\t    DWORD \tWh \t    111 \tSummierter Verbrauch aller Verbrauchszähler\nconsYieldYesterday \tDWORD \tWh \t    112 \tSummierter Verbrauch des gestrigen Tages; alle Verbrauchszähler\nconsYieldMonth \t    DWORD \tWh \t    113 \tSummierter Verbrauch des Monats; alle Verbrauchszähler\nconsYieldYear \t    DWORD \tWh \t    114 \tSummierter Verbrauch des Jahres, alle Verbrauchszähler\nconsYieldTotal \t    DWORD \tWh \t    115 \tSummierter Gesamtverbrauch, alle Verbrauchszähler\ntotalPower \t\t    DWORD \tWp \t    116 \tInstallierte Generatorleistung"},{"id":"c330383e.c26a68","type":"debug","z":"7f9ef685.babe58","g":"3196ab6e.763eb4","name":"Symo Out (Grid)","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1160,"y":360,"wires":[]},{"id":"1bfbc86d.58b058","type":"function","z":"7f9ef685.babe58","g":"3196ab6e.763eb4","name":"Compute net power at grid and SolarEdge inverter","func":"//Eigentlich müsste hier der Wert des Zählers \"Generell\" \n//beigezogen werden. Dieser konnte aber noch nicht gefunden werden\n\nGrid = new Object();\nSolarEdge = new Object();\ncontext.data = context.data || new Object();\n\nGrid.topic = \"Grid\";\nSolarEdge.topic = \"SolarEdge\";\n\nvar Consumption = parseInt(msg.payload[782][2]);\nvar Gain = parseInt(msg.payload[782][1])+parseInt(msg.payload[782][6]);\nSolarEdge.payload = parseInt(msg.payload[782][1]);\n//var TotalErtrag = msg.payload[801][170][105];\n//var TotalVerbrauch = msg.payload[801][170][111];\n//var TotalExportiert = msg.payload[801][130][100];\n//var TotalImportiert = msg.payload[801][130][105];\n//var TotalEigenverbrauch = msg.payload[801][130][102];\nGrid.payload = Consumption - Gain; //Power export to grid = negative; Power import = positive\n\n\n//context.data.Grid = Consumption - Gain; //Power export to grid = negative; Power import = positive\n//if (Math.abs(Grid.payload) <= 100) {\n//    Grid.payload = 0;\n//}\n\nreturn [Grid, SolarEdge];","outputs":2,"noerr":0,"initialize":"","finalize":"","libs":[],"x":610,"y":380,"wires":[["3a567802.42d478","d1f075ac.46ff38","ca8680ed.f1411"],["87ac7ea2.426f8","c426e351.aa073","4349ad49.726984"]]},{"id":"3a567802.42d478","type":"debug","z":"7f9ef685.babe58","g":"3196ab6e.763eb4","name":"Grid","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1130,"y":300,"wires":[]},{"id":"494741fb.910ba","type":"comment","z":"7f9ef685.babe58","name":"Pendenzen","info":"# Prüfung, ob die Einspeisungsleistung aktiv ist\nWährend den Tests festgestellt, dass es vorkommen kann, das der GEN24 manchmal die Einspseisewerte nicht mehr ändert, obwohl diese im Zähler korrekt sind.\n\n# Batterieladung ausschalten während das Auto lädt\nAnsonsten kommt es zu Schwingungen. Als Alternative kann das Auto auf eine fixe Ladeleistung gestellt werden.  dfd","x":130,"y":60,"wires":[]},{"id":"f33394ef.df1698","type":"google-spreadsheet","z":"7f9ef685.babe58","g":"e9c802e2.9d6c","name":"Get Instructions ","auth":"4ea411a2.fe143","sheet":"1UKvqEo3yGbNzWyS3AA8jb4CNSL0H4-wk_99dpqQC_2U","range":"Fernsteuerung_WR!A1:B1","method":"new","direction":"line","action":"get","clear":false,"line":false,"column":false,"fields":"all","save":"_sheet","selfields":[""],"cell_l":"","cell_c":"","input":"payload","output":"payload","saveType":"msg","inputType":"msg","outputType":"msg","sheetType":"str","rangeType":"str","cell_lType":"str","cell_cType":"str","x":380,"y":900,"wires":[["63db62b4.43e40c"],[]]},{"id":"7fb207bc.5a2898","type":"inject","z":"7f9ef685.babe58","g":"e9c802e2.9d6c","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":210,"y":900,"wires":[["f33394ef.df1698"]]},{"id":"cad781dc.7c0a2","type":"function","z":"7f9ef685.babe58","g":"e9c802e2.9d6c","name":"InWRte","func":"var InWRte = msg.payload;\n\n\nmsg.payload = { \n    'value': InWRte,\n    'fc': 6,\n    'unitid': 1,\n    'address': 40366,\n    'quantity': 1\n} \n\nreturn msg","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1060,"y":880,"wires":[["15ea06a5.c89879","4cfd3297.c4e7dc"]]},{"id":"35715c6e.649124","type":"function","z":"7f9ef685.babe58","g":"e9c802e2.9d6c","name":"OutWRte","func":"var OutWRte = msg.payload;\n\nmsg.payload = { \n    'value': OutWRte,\n    'fc': 6,\n    'unitid': 1,\n    'address': 40365,\n    'quantity': 1\n} \n\nreturn msg","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1060,"y":920,"wires":[["15ea06a5.c89879","3b0e67c8.0a6bb8"]]},{"id":"3ce6e387.439cec","type":"function","z":"7f9ef685.babe58","g":"e9c802e2.9d6c","name":"StorCtl_Mod","func":"var storctl_mod = msg.payload;\n\nmsg.payload = { \n    'value': storctl_mod,\n    'fc': 6,\n    'unitid': 1,\n    'address': 40358,\n    'quantity': 1\n} \n\nreturn msg","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1070,"y":960,"wires":[["15ea06a5.c89879","17c7aec8.a64a01"]]},{"id":"354f004a.a9bc2","type":"delay","z":"7f9ef685.babe58","g":"e9c802e2.9d6c","name":"Resend command after 200ms","pauseType":"delay","timeout":"200","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":710,"y":840,"wires":[["142ee3e5.198fec"]]},{"id":"18a2d084.fe472f","type":"modbus-response","z":"7f9ef685.babe58","g":"5f27b4a7.2e07ec","name":"","registerShowMax":20,"x":1310,"y":860,"wires":[]},{"id":"15ea06a5.c89879","type":"modbus-flex-write","z":"7f9ef685.babe58","g":"5f27b4a7.2e07ec","name":"Fronius-Storage","showStatusActivities":true,"showErrors":true,"server":"b96da7d4da3bbd9e","emptyMsgOnFail":true,"keepMsgProperties":true,"x":1300,"y":920,"wires":[["18a2d084.fe472f"],[]]},{"id":"4cfd3297.c4e7dc","type":"debug","z":"7f9ef685.babe58","g":"e9c802e2.9d6c","name":"InWRte","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1260,"y":1000,"wires":[]},{"id":"3b0e67c8.0a6bb8","type":"debug","z":"7f9ef685.babe58","g":"e9c802e2.9d6c","name":"OutWRte","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1260,"y":1040,"wires":[]},{"id":"17c7aec8.a64a01","type":"debug","z":"7f9ef685.babe58","g":"e9c802e2.9d6c","name":"StorCtrlMod","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1270,"y":1080,"wires":[]},{"id":"f625cf0e.63f34","type":"modbus-flex-write","z":"7f9ef685.babe58","g":"3196ab6e.763eb4","name":"","showStatusActivities":true,"showErrors":true,"server":"567a58ba.1e6468","emptyMsgOnFail":false,"keepMsgProperties":false,"x":1170,"y":500,"wires":[[],[]]},{"id":"b20cd441.b8baa8","type":"modbus-server","z":"7f9ef685.babe58","g":"3196ab6e.763eb4","name":"NodeRed-MB-Solaredge SolarEdge Inverter","logEnabled":true,"hostname":"192.168.1.11","serverPort":"502","responseDelay":100,"delayUnit":"ms","coilsBufferSize":10000,"holdingBufferSize":"41000","inputBufferSize":10000,"discreteBufferSize":10000,"showErrors":true,"x":1070,"y":660,"wires":[[],[],[],[],[]]},{"id":"fac7ff18.40136","type":"function","z":"7f9ef685.babe58","g":"3196ab6e.763eb4","name":"Write Headers","func":"const registers = [40000, 40001, 40002, 40003, 40004, 40005, 40006, 40007, 40008, 40009,\n    40010, 40011, 40012, 40013, 40014, 40015, 40016, 40017, 40018, 40019,\n    40020, 40021, 40022, 40023, 40024, 40025, 40026, 40027, 40028, 40029,\n    40030, 40031, 40032, 40033, 40034, 40035, 40036, 40037, 40038, 40039,\n    40040, 40041, 40042, 40043, 40044, 40045, 40046, 40047, 40048, 40049,\n    40050, 40051, 40052, 40053, 40054, 40055, 40056, 40057, 40058, 40059,\n    40060, 40061, 40062, 40063, 40064, 40065, 40066, 40067, 40068, 40069,\n    40070, 40071, 40072, 40073, 40074, 40075, 40076, 40077, 40078, 40079,\n    40080, 40081, 40082, 40083, 40084, 40085, 40086, 40087, 40088, 40089,\n    40090, 40091, 40092, 40093, 40094, 40095, 40096, 40097, 40098, 40099,\n    40100, 40101, 40102, 40103, 40104, 40105, 40106, 40107, 40108, 40109,\n    40110, 40111, 40112, 40113, 40114, 40115, 40116, 40117, 40118, 40119,\n    40120, 40121, 40122, 40123, 40124, 40125, 40126, 40127, 40128, 40129,\n    40130, 40131, 40132, 40133, 40134, 40135, 40136, 40137, 40138, 40139,\n    40140, 40141, 40142, 40143, 40144, 40145, 40146, 40147, 40148, 40149,\n    40150, 40151, 40152, 40153, 40154, 40155, 40156, 40157, 40158, 40159,\n    40160, 40161, 40162, 40163, 40164, 40165, 40166, 40167, 40168, 40169,\n    40170, 40171, 40172, 40173, 40174, 40175, 40176, 40177, 40178, 40179,\n    40180, 40181, 40182, 40183, 40184, 40185, 40186, 40187, 40188, 40189,\n    40190, 40191, 40192, 40193, 40194, 40195, 40196, 40197 ];\n\nconst values = [21365, 28243, 1, 65, 18034, 28526, 26997, 29440, 0, 0,\n    0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n    21357, 24946, 29728, 19813, 29797, 29216, 21587, 8246, 13633, 11571, \n    0, 0, 0, 0, 0, 0, 15472, 29289, 28001, 29305,\n    15872, 0, 0, 0, 12590, 13056, 0, 0, 0, 0,\n    0, 0, 13111, 13111, 13111, 12851, 13360, 0, 0, 0,\n    //0, 0, 12848, 14645, 13364, 14645, 12597, 0, 0, 0,\n    0, 0, 0, 0, 0, 0, 0, 0, 2, 213,\n    124, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n    0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n    0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n    0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n    0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n    0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n    0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n    0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n    0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n    0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n    0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n    0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n    0, 0, 0, 0, 0, 0, 65535, 0 ]\n\nconst reg1 = registers.map(reg => reg)\nconst reg2 = reg1.splice(100)\nconst values2 = values.splice(100)\n\nconst p1 = {\n    'value': values,\n    'fc': 16,\n    'unitid': 1,\n    'address': reg1,\n    'quantity': values.length\n}\nconst p2 = {\n    'value': values2,\n    'fc': 16,\n    'unitid': 1,\n    'address': reg2,\n    'quantity': values2.length\n}\n\nnode.send({payload: p1})\nnode.send({payload: p2})\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":500,"y":500,"wires":[["f625cf0e.63f34"]]},{"id":"eba40ee7.35d49","type":"inject","z":"7f9ef685.babe58","g":"3196ab6e.763eb4","name":"","props":[],"repeat":"","crontab":"","once":true,"onceDelay":"1","topic":"","payloadType":"str","x":230,"y":500,"wires":[["fac7ff18.40136"]]},{"id":"4349ad49.726984","type":"function","z":"7f9ef685.babe58","g":"3196ab6e.763eb4","name":"Symo","func":"//Inform GEN24 inverter on Power from SolarEdge inverter\n//Important: This power is not shown locally on the GEN24 \n//web interface but only on https://www.solarweb.com/PvSystems/PvSystem?pvSystemId=b03c5087-c6d0-48e8-8bec-e3f4e3566aa0\n\nvar GenPower = msg.payload*-1;\n\nmsg.inverterdata = {\n    Current_AC: 0,\n    Current_AC_Phase_1: 0,\n    Current_AC_Phase_2: 0,\n    Current_AC_Phase_3: 0,\n    Voltage_AC_Phase_1: 239.0,\n    Voltage_AC_Phase_2: 238.0,\n    Voltage_AC_Phase_3: 239.0,\n    Voltage_AC_Phase_Avg: 239.0,\n    Voltage_AC_PhaseToPhase_12: 400.0,\n    Voltage_AC_PhaseToPhase_23: 401.0,\n    Voltage_AC_PhaseToPhase_31: 339.0,\n    Voltage_AC_PhaseToPhase_Avg: 400.0,\n\n    Frequency_Phase_Average: 49.9,\n    PowerReal_AC_Grid: GenPower,\n    PowerReal_AC_Phase_1: GenPower,\n    PowerReal_AC_Phase_2: 0,\n    PowerReal_AC_Phase_3: 0,\n    PowerApparent_AC: 0,  //Scheinleistung\n    PowerApparent_AC_Phase_1: 0,\n    PowerApparent_AC_Phase_2: 0,\n    PowerApparent_AC_Phase_3: 0,\n    PowerReactive_AC: 0,\n    PowerReactive_AC_Phase_1: 0,\n    PowerReactive_AC_Phase_2: 0,\n    PowerReactive_AC_Phase_3: 0,\n    PowerFactor_AC: 1,\n    PowerFactor_AC_Phase_1: 1,\n    PowerFactor_AC_Phase_2: 1,\n    PowerFactor_AC_Phase_3: 1,\n    E_Grid_Exported: 0, //TotalExportiert,\n    E_Grid_Exported_Phase_1: 0,\n    E_Grid_Exported_Phase_2: 0,\n    E_Grid_Exported_Phase_3: 0,\n    E_Grid_Imported: 0, //TotalImportiert,\n    E_Grid_Imported_Phase_1: 0,\n    E_Grid_Imported_Phase_2: 0,\n    E_Grid_Imported_Phase_3: 0\n}\n\n\n\nfunction tofloatregisters(value) {\n    var buf = Buffer.alloc(4);\n    buf.writeFloatBE(value);\n    return [(buf[0] * 256 + buf[1]), (buf[2] * 256) + buf[3]]\n}\n\nvar registers = [];\nvar values = [];\nvar i = 40071;\n\nfor (var key of Object.keys(msg.inverterdata)) {\n    registers.push(i, i + 1)\n    for (var val of tofloatregisters(msg.inverterdata[key])) values.push(val);\n    i = i + 2;\n}\n\nconst modbusmessage = {\n    'value': values,\n    'fc': 16,\n    'unitid': 1,\n    'address': registers,\n    'quantity': values.length\n}\n\nreturn ({ payload: modbusmessage })","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":970,"y":420,"wires":[["f625cf0e.63f34","a30d5958.888328"]]},{"id":"a30d5958.888328","type":"debug","z":"7f9ef685.babe58","g":"3196ab6e.763eb4","name":"Symo Out (Inverter)","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1170,"y":420,"wires":[]},{"id":"87ac7ea2.426f8","type":"debug","z":"7f9ef685.babe58","g":"3196ab6e.763eb4","name":"SolarEdge","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":930,"y":580,"wires":[]},{"id":"142ee3e5.198fec","type":"function","z":"7f9ef685.babe58","g":"e9c802e2.9d6c","name":"Format values and output","func":"context.data = context.data || new Object();\n//context.data.OpMode = \"\";\n//context.data.Power = 0;\n//context.data.InWRte = 0;\n//context.data.OutWRte = 0;\n//context.data.storctl_mod = 0;\nInWRte = new Object();\nOutWRte = new Object();\nstorctl_mod = new Object();\nOpMode = new Object();\nconst DoNothing = 0; //within +/- this value there shall be no action\n\n\nswitch (msg.topic) {\n    \n    case \"Google\":\n\n        context.data.OpMode = msg.payload[0][0];\n        context.data.Power = parseInt(msg.payload[0][1]/4);\n\n        switch (context.data.OpMode) {\n            case \"KeineRegelung\":\n                context.data.InWRte = 0;\n                context.data.OutWRte = 0;\n                context.data.storctl_mod = 3;\n            break;\n\n            case \"Automatik\":\n                context.data.InWRte = 0;\n                context.data.OutWRte = 0; \n                context.data.storctl_mod = 0;\n            break;\n        \n            case \"Laden\":\n                context.data.InWRte = context.data.Power;\n                context.data.OutWRte = 65536-context.data.Power; //Sum of OutWRte and InWRte must never be more than 0xFFFF\n                context.data.storctl_mod = 3;\n            break;\n        \n            case \"Entladen\":\n                context.data.InWRte = 65536-context.data.Power; //Sum of OutWRte and InWRte must never be more than 0xFFFF\n                context.data.OutWRte = context.data.Power;\n                context.data.storctl_mod = 3;\n            break;\n        \n        }\n    break;\n  \n    case \"PID\":\n        \n        context.data.Power = parseInt(msg.payload);\n        if (context.data.OpMode == \"Automatik\") { \n            //context.data.OpMode = context.data.OpMode + \"PID\";\n            if (context.data.Power > DoNothing) { //Discharge battery\n                context.data.OutWRte = context.data.Power;\n                context.data.InWRte = 65536-context.data.Power; //Sum of OutWRte and InWRte must never be more than 0xFFFF\n                context.data.storctl_mod = 3;\n            }\n        \n            if (context.data.Power < DoNothing) { //Charge battery\n                context.data.Power = context.data.Power*-1; //no negative numbers allowed\n                context.data.InWRte = context.data.Power;\n                context.data.OutWRte = 65536-context.data.Power; //Sum of OutWRte and InWRte must never be more than 0xFFFF\n                context.data.storctl_mod = 3;           \n            }\n            \n            if (context.data.Power == DoNothing) { //Do Nothing\n                context.data.InWRte = 0;\n                context.data.OutWRte = 0; \n                context.data.storctl_mod = 3;           \n            }\n        } \n    break;\n    \n    default: //if argument is missing do nothing\n        context.data.InWRte = 0;\n        context.data.OutWRte = 0; \n        context.data.storctl_mod = 3;\n}\n\nInWRte.payload = context.data.InWRte;\nOutWRte.payload = context.data.OutWRte;\nstorctl_mod.payload = context.data.storctl_mod;\nOpMode.payload = context.data.OpMode\n\nreturn [InWRte, OutWRte, storctl_mod, OpMode];\n","outputs":4,"noerr":0,"initialize":"","finalize":"","libs":[],"x":850,"y":920,"wires":[["cad781dc.7c0a2"],["35715c6e.649124"],["3ce6e387.439cec"],["70b60e20.81d1c"]]},{"id":"63db62b4.43e40c","type":"change","z":"7f9ef685.babe58","g":"e9c802e2.9d6c","name":"Set msg topic","rules":[{"t":"set","p":"topic","pt":"msg","to":"Google","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":580,"y":900,"wires":[["24d5551.a74cbaa","142ee3e5.198fec","354f004a.a9bc2"]]},{"id":"5dbb76a.8d17688","type":"change","z":"7f9ef685.babe58","g":"e9c802e2.9d6c","name":"Set msg topic","rules":[{"t":"set","p":"topic","pt":"msg","to":"PID","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":580,"y":960,"wires":[["142ee3e5.198fec","8e323c6b.3df72"]]},{"id":"24d5551.a74cbaa","type":"debug","z":"7f9ef685.babe58","g":"e9c802e2.9d6c","name":"Google Output","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":820,"y":800,"wires":[]},{"id":"8e323c6b.3df72","type":"debug","z":"7f9ef685.babe58","g":"e9c802e2.9d6c","name":"PID Output","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":810,"y":1000,"wires":[]},{"id":"70b60e20.81d1c","type":"debug","z":"7f9ef685.babe58","g":"e9c802e2.9d6c","name":"OpMode","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1060,"y":1020,"wires":[]},{"id":"ca8680ed.f1411","type":"PID","z":"7f9ef685.babe58","g":"e9c802e2.9d6c","name":"","setpoint":"0","pb":"16000","ti":"99999","td":0,"integral_default":0.5,"smooth_factor":"0","max_interval":"60","enable":1,"disabled_op":".5","x":220,"y":960,"wires":[["1334cc03.3348b4","880d5006.9be55"]]},{"id":"1334cc03.3348b4","type":"function","z":"7f9ef685.babe58","g":"e9c802e2.9d6c","name":"Scaling","func":"//scaling the output of PID controller (0-1) to the required +/- values (reversed)\n\nconst ScaleFactor = 4000;\nconst ZeroScaling = 0.5; //0 = maximal value; 0.5 = zero value; 1 = minimal value\n\nvar PIDInput = msg.payload;\n\nif (PIDInput <= ZeroScaling){\n    msg.payload = (ZeroScaling-PIDInput)*ScaleFactor;//*ScaleFactor); //compute the difference to ZeroScaling\n} else {\n    msg.payload = (PIDInput-ZeroScaling)*ScaleFactor*-1; //compute the difference to ZeroScaling\n}\n//if (PIDInput == 0.5){\n//    msg.payload = ScaleFactor;\n//}\n\n/*\nswitch (PIDInput) {\n  case (PIDInput <= ZeroScaling):\n    msg.payload = parseInt(PIDInput*ScaleFactor);\n    break;\n  case (PIDInput > ZeroScaling):\n    msg.payload = parseInt(PIDInput*ScaleFactor*-1)\n    break;\n  default:\n    msg.payload = 1234;//ScaleFactor;\n    break;\n}\n*/\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":390,"y":960,"wires":[["5dbb76a.8d17688"]]},{"id":"880d5006.9be55","type":"debug","z":"7f9ef685.babe58","g":"e9c802e2.9d6c","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":420,"y":1040,"wires":[]},{"id":"6c1b854f.8f65bc","type":"file","z":"7f9ef685.babe58","g":"3196ab6e.763eb4","name":"Write Logfile","filename":"/var/log/PowerOut","appendNewline":true,"createDir":false,"overwriteFile":"false","encoding":"none","x":690,"y":600,"wires":[[]]},{"id":"4179d476.6bc0ec","type":"function","z":"7f9ef685.babe58","g":"3196ab6e.763eb4","name":"","func":"context.data = context.data || new Object();\n\ncontext.data.Time = Date();\n\nswitch (msg.topic) {\n    case \"Grid\":\n        context.data.Grid = msg.payload;\n    break;\n\n    case \"SolarEdge\":\n        context.data.SolarEdge = msg.payload;    \n    break;\n\n}\n\nmsg.payload = \"Date: \" + context.data.Time + \" Grid: \" + context.data.Grid + \" SolarEdge: \" + context.data.SolarEdge; \n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":480,"y":600,"wires":[["6c1b854f.8f65bc"]]},{"id":"c426e351.aa073","type":"mqtt out","z":"7f9ef685.babe58","g":"3196ab6e.763eb4","name":"SolarEdge Leistung","topic":"openWB/set/pv/2/W","qos":"0","retain":"false","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"7a4dd03f.f90ad","x":1010,"y":460,"wires":[]},{"id":"75cf7210.3ffb5c","type":"debug","z":"7f9ef685.babe58","g":"3196ab6e.763eb4","name":"Solar Log API","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":710,"y":300,"wires":[]},{"id":"46f72e91930e4509","type":"modbus-client","name":"NodeRed-MB-Smartmeter Grid","clienttype":"tcp","bufferCommands":true,"stateLogEnabled":false,"queueLogEnabled":false,"tcpHost":"192.168.1.65","tcpPort":"502","tcpType":"DEFAULT","serialPort":"/dev/ttyUSB","serialType":"RTU-BUFFERD","serialBaudrate":"9600","serialDatabits":"8","serialStopbits":"1","serialParity":"none","serialConnectionDelay":"100","unit_id":2,"commandDelay":1,"clientTimeout":1000,"reconnectOnTimeout":true,"reconnectTimeout":2000,"parallelUnitIdsAllowed":true},{"id":"4ea411a2.fe143","type":"google-service-account","name":"Energiestatistik","scope":["https://www.googleapis.com/auth/spreadsheets"],"way":"json","check_dialogflow":"","check_speech":""},{"id":"b96da7d4da3bbd9e","type":"modbus-client","name":"Fronius Symo GEN24 10.0","clienttype":"tcp","bufferCommands":true,"stateLogEnabled":false,"queueLogEnabled":false,"tcpHost":"192.168.1.10","tcpPort":"502","tcpType":"DEFAULT","serialPort":"/dev/ttyUSB","serialType":"RTU-BUFFERD","serialBaudrate":"9600","serialDatabits":"8","serialStopbits":"1","serialParity":"none","serialConnectionDelay":"100","unit_id":1,"commandDelay":1,"clientTimeout":1000,"reconnectOnTimeout":true,"reconnectTimeout":2000,"parallelUnitIdsAllowed":true},{"id":"567a58ba.1e6468","type":"modbus-client","name":"NodeRed-MB-Generatorzähler","clienttype":"tcp","bufferCommands":true,"stateLogEnabled":false,"queueLogEnabled":false,"tcpHost":"192.168.1.11","tcpPort":"502","tcpType":"DEFAULT","serialPort":"/dev/ttyUSB","serialType":"RTU-BUFFERD","serialBaudrate":"9600","serialDatabits":"8","serialStopbits":"1","serialParity":"none","serialConnectionDelay":"100","unit_id":1,"commandDelay":1,"clientTimeout":1000,"reconnectOnTimeout":true,"reconnectTimeout":2000,"parallelUnitIdsAllowed":true},{"id":"7a4dd03f.f90ad","type":"mqtt-broker","name":"OpenWB","broker":"127.0.0.1","port":"1883","clientid":"","usetls":false,"protocolVersion":"4","keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","birthMsg":{},"closeTopic":"","closeQos":"0","closePayload":"","closeMsg":{},"willTopic":"","willQos":"0","willPayload":"","willMsg":{},"sessionExpiry":""}]
