With Node-Red I was able to create a nice tariff based controller for my GEN24 10kW. Maybe the Node Red code is usefull inspiration
The whole register setting is some what unlogical to me but I managed to figure it out.
[{"id":"ffb07c75f3edf808","type":"group","z":"082d1a6d7f9f4ee6","name":"Write changes to Gen24 inverter (1Hz)","style":{"fill":"#c8e7a7","label":true},"nodes":["acc53a6f4ee7fcc1","042d68470832006d","612e3990e9a32c1d","313d603e6a147c48","e23254938653df68"],"x":1414,"y":559,"w":992,"h":142},{"id":"acc53a6f4ee7fcc1","type":"function","z":"082d1a6d7f9f4ee6","g":"ffb07c75f3edf808","name":"Modbus Payload Packet","func":"var values = [msg.storctl_mod, (65535), (500), (10000), (65535), (65535), (5), (msg.outwrte), (msg.inwrte)]\n\nmsg.payload = {\n 'value': values,\n 'fc': 16,\n 'unitid': 1,\n // INT+SF = -10\n 'address': 40358,\n 'quantity': 9\n}\n\nreturn msg","outputs":1,"timeout":"","noerr":0,"initialize":"","finalize":"","libs":[],"x":1550,"y":640,"wires":[["e23254938653df68"]]},{"id":"042d68470832006d","type":"modbus-response","z":"082d1a6d7f9f4ee6","g":"ffb07c75f3edf808","name":"","registerShowMax":20,"x":2210,"y":600,"wires":[]},{"id":"612e3990e9a32c1d","type":"modbus-flex-write","z":"082d1a6d7f9f4ee6","g":"ffb07c75f3edf808","name":"Fronius Storage","showStatusActivities":true,"showErrors":true,"showWarnings":true,"server":"bcc4229c.180ac","emptyMsgOnFail":true,"keepMsgProperties":true,"delayOnStart":false,"startDelayTime":"10","x":1980,"y":640,"wires":[["042d68470832006d","313d603e6a147c48"],[]]},{"id":"313d603e6a147c48","type":"debug","z":"082d1a6d7f9f4ee6","g":"ffb07c75f3edf808","name":"Inverter MODBUS Response","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":2240,"y":660,"wires":[]},{"id":"e23254938653df68","type":"delay","z":"082d1a6d7f9f4ee6","g":"ffb07c75f3edf808","name":"Rate limit (1Hz)","pauseType":"rate","timeout":"500","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":true,"allowrate":false,"outputs":1,"x":1780,"y":640,"wires":[["612e3990e9a32c1d"]]},{"id":"bcc4229c.180ac","type":"modbus-client","name":"Fronius","clienttype":"tcp","bufferCommands":true,"stateLogEnabled":false,"queueLogEnabled":false,"failureLogEnabled":false,"tcpHost":"192.168.x.x","tcpPort":"502","tcpType":"DEFAULT","serialPort":"/dev/ttyUSB","serialType":"RTU-BUFFERD","serialBaudrate":"9600","serialDatabits":"8","serialStopbits":"1","serialParity":"none","serialConnectionDelay":"100","serialAsciiResponseStartDelimiter":"","unit_id":200,"commandDelay":1,"clientTimeout":1000,"reconnectOnTimeout":true,"reconnectTimeout":2000,"parallelUnitIdsAllowed":true},{"id":"e71396201ab31ab6","type":"group","z":"082d1a6d7f9f4ee6","name":"SOC charge/discharge manager","style":{"fill":"#c8e7a7","label":true},"nodes":["ab44b5cb2df49b31","c888c99eccf91d8c","9578ea3068d442bf"],"x":594,"y":499,"w":652,"h":122},{"id":"ab44b5cb2df49b31","type":"api-current-state","z":"082d1a6d7f9f4ee6","g":"e71396201ab31ab6","name":"Battery SOC lower than 20%, stop discharge","server":"aa39721f.3c9dc","version":3,"outputs":2,"halt_if":"20","halt_if_type":"num","halt_if_compare":"lte","entity_id":"sensor.tesla_battery_state_of_charge","state_type":"num","blockInputOverrides":false,"outputProperties":[{"property":"status","propertyType":"msg","value":"SOC < 20%","valueType":"str"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":1030,"y":540,"wires":[["e39ad0b0a923904a"],[]]},{"id":"c888c99eccf91d8c","type":"api-current-state","z":"082d1a6d7f9f4ee6","g":"e71396201ab31ab6","name":"Battery SOC higher than 30%, normal operation","server":"aa39721f.3c9dc","version":3,"outputs":2,"halt_if":"25","halt_if_type":"num","halt_if_compare":"gt","entity_id":"sensor.tesla_battery_state_of_charge","state_type":"num","blockInputOverrides":false,"outputProperties":[{"property":"status","propertyType":"msg","value":"SOC > 30%","valueType":"str"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":1040,"y":580,"wires":[["7219cc5524b6201c"],[]]},{"id":"9578ea3068d442bf","type":"ha-switch","z":"082d1a6d7f9f4ee6","g":"e71396201ab31ab6","name":"SOC manager On/Off","version":0,"debugenabled":false,"inputs":1,"outputs":2,"entityConfig":"2f29503ca621eacd","enableInput":true,"outputOnStateChange":false,"outputProperties":[{"property":"outputType","propertyType":"msg","value":"state change","valueType":"str"},{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"}],"x":720,"y":560,"wires":[["ab44b5cb2df49b31","c888c99eccf91d8c"],[]]},{"id":"aa39721f.3c9dc","type":"server","name":"Home Assistant 1","addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"","connectionDelay":false,"cacheJson":false,"heartbeat":false,"heartbeatInterval":"","statusSeparator":"","enableGlobalContextStore":false},{"id":"2f29503ca621eacd","type":"ha-entity-config","server":"aa39721f.3c9dc","deviceConfig":"","name":"SOC manager On/Off","version":"6","entityType":"switch","haConfig":[{"property":"name","value":"SOC manager On/Off"},{"property":"icon","value":""},{"property":"entity_picture","value":""},{"property":"entity_category","value":""},{"property":"device_class","value":""}],"resend":false,"debugEnabled":false},{"id":"c927b6a863acb390","type":"group","z":"082d1a6d7f9f4ee6","name":"Every minute and protections","style":{"label":true,"fill":"#dbcbe7"},"nodes":["f571da0891d8ce43","d26c1cd22f597dab","93e59122d814ce01"],"x":14,"y":439,"w":532,"h":182},{"id":"f571da0891d8ce43","type":"cronplus","z":"082d1a6d7f9f4ee6","g":"c927b6a863acb390","name":"every 2 seconds","outputField":"payload","timeZone":"","storeName":"","commandResponseMsgOutput":"output1","defaultLocation":"","defaultLocationType":"default","outputs":1,"options":[{"name":"schedule1","topic":"topic1","payloadType":"default","payload":"","expressionType":"cron","expression":"0/2 * * * * *","location":"","offset":"0","solarType":"all","solarEvents":"sunrise,sunset"}],"x":140,"y":580,"wires":[["93e59122d814ce01","http-request-node"]]},{"id":"d26c1cd22f597dab","type":"api-current-state","z":"082d1a6d7f9f4ee6","g":"c927b6a863acb390","name":"Above backup energy level","server":"aa39721f.3c9dc","version":3,"outputs":2,"halt_if":"10","halt_if_type":"num","halt_if_compare":"gte","entity_id":"sensor.tesla_battery_state_of_charge","state_type":"num","blockInputOverrides":false,"outputProperties":[{"property":"status","propertyType":"msg","value":"SOC >= min%","valueType":"str"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":320,"y":480,"wires":[["98275a63d7578b29"],["11a3663361be0176"]]},{"id":"93e59122d814ce01","type":"ha-switch","z":"082d1a6d7f9f4ee6","g":"c927b6a863acb390","name":"Auto battery management","version":0,"debugenabled":false,"inputs":1,"outputs":2,"entityConfig":"8c13c83e43673f66","enableInput":true,"outputOnStateChange":false,"outputProperties":[{"property":"outputType","propertyType":"msg","value":"state change","valueType":"str"},{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"}],"x":410,"y":580,"wires":[["d26c1cd22f597dab"],["9578ea3068d442bf"]]},{"id":"8c13c83e43673f66","type":"ha-entity-config","server":"aa39721f.3c9dc","deviceConfig":"","name":"Auto battery management","version":"6","entityType":"switch","haConfig":[{"property":"name","value":"Auto battery management"},{"property":"icon","value":""},{"property":"entity_picture","value":""},{"property":"entity_category","value":""},{"property":"device_class","value":""}],"resend":false,"debugEnabled":false},{"id":"972413b3b474c04e","type":"group","z":"082d1a6d7f9f4ee6","name":"Energy selling and buying","style":{"label":true,"stroke":"#a4a4a4","fill":"#bfdbef","fill-opacity":"0.47"},"nodes":["166f102fe8044a4d","fd2ffb49be6386f4","9eb0e0e8a944a8ab","4da31527a79ba2bb","d154056291b873bc","8934403241c202e6"],"x":28,"y":13,"w":1424,"h":408},{"id":"166f102fe8044a4d","type":"junction","z":"082d1a6d7f9f4ee6","g":"972413b3b474c04e","x":1340,"y":360,"wires":[["7219cc5524b6201c"]]},{"id":"fd2ffb49be6386f4","type":"api-call-service","z":"082d1a6d7f9f4ee6","g":"972413b3b474c04e","name":"Update Normal Price State","server":"aa39721f.3c9dc","version":7,"debugenabled":false,"action":"input_text.set_value","floorId":[],"areaId":[],"deviceId":[],"entityId":["input_text.price_select_state"],"labelId":[],"data":"{\"value\":\"normal\"}","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","blockInputOverrides":false,"domain":"input_text","service":"set_value","x":880,"y":380,"wires":[[]]},{"id":"9eb0e0e8a944a8ab","type":"group","z":"082d1a6d7f9f4ee6","g":"972413b3b474c04e","name":"Low price","style":{"stroke":"#a4a4a4","label":true,"fill":"#e3f3d3"},"nodes":["b659660eddbff070","d122f965b4cc06c2","7f64baa7b4233a58"],"x":754,"y":39,"w":292,"h":142},{"id":"b659660eddbff070","type":"api-call-service","z":"082d1a6d7f9f4ee6","g":"9eb0e0e8a944a8ab","name":"Update Low Price State","server":"aa39721f.3c9dc","version":7,"debugenabled":false,"action":"input_text.set_value","floorId":[],"areaId":[],"deviceId":[],"entityId":["input_text.price_select_state"],"labelId":[],"data":"{\"value\":\"low\"}","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","blockInputOverrides":false,"domain":"input_text","service":"set_value","x":910,"y":80,"wires":[[]]},{"id":"d122f965b4cc06c2","type":"ha-switch","z":"082d1a6d7f9f4ee6","g":"9eb0e0e8a944a8ab","name":"Energy buying","version":0,"debugenabled":false,"inputs":1,"outputs":2,"entityConfig":"7e0478382e6245ea","enableInput":true,"outputOnStateChange":false,"outputProperties":[{"property":"outputType","propertyType":"msg","value":"state change","valueType":"str"},{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"}],"x":870,"y":140,"wires":[["11a3663361be0176"],["166f102fe8044a4d"]]},{"id":"7f64baa7b4233a58","type":"junction","z":"082d1a6d7f9f4ee6","g":"9eb0e0e8a944a8ab","x":780,"y":140,"wires":[["b659660eddbff070","d122f965b4cc06c2"]]},{"id":"7e0478382e6245ea","type":"ha-entity-config","server":"aa39721f.3c9dc","deviceConfig":"","name":"Energy buying","version":"6","entityType":"switch","haConfig":[{"property":"name","value":"Energy buying"},{"property":"icon","value":""},{"property":"entity_picture","value":""},{"property":"entity_category","value":""},{"property":"device_class","value":""}],"resend":false,"debugEnabled":false},{"id":"4da31527a79ba2bb","type":"group","z":"082d1a6d7f9f4ee6","g":"972413b3b474c04e","name":"High price","style":{"fill":"#ffbfbf","label":true},"nodes":["b31e815209d2c646","9b6a8f9c6e184f7f","0afdd7a9f3168964","ae318f7d467ec754"],"x":754,"y":199,"w":672,"h":142},{"id":"b31e815209d2c646","type":"api-call-service","z":"082d1a6d7f9f4ee6","g":"4da31527a79ba2bb","name":"Update High Price State","server":"aa39721f.3c9dc","version":7,"debugenabled":false,"action":"input_text.set_value","floorId":[],"areaId":[],"deviceId":[],"entityId":["input_text.price_select_state"],"labelId":[],"data":"{\"value\":\"high\"}","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","blockInputOverrides":false,"domain":"input_text","service":"set_value","x":910,"y":240,"wires":[[]]},{"id":"9b6a8f9c6e184f7f","type":"ha-switch","z":"082d1a6d7f9f4ee6","g":"4da31527a79ba2bb","name":"Energy selling","version":0,"debugenabled":false,"inputs":1,"outputs":2,"entityConfig":"6806eaeffeb00bc4","enableInput":true,"outputOnStateChange":false,"outputProperties":[{"property":"outputType","propertyType":"msg","value":"state change","valueType":"str"},{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"}],"x":870,"y":300,"wires":[["ae318f7d467ec754"],["166f102fe8044a4d"]]},{"id":"0afdd7a9f3168964","type":"junction","z":"082d1a6d7f9f4ee6","g":"4da31527a79ba2bb","x":780,"y":280,"wires":[["b31e815209d2c646","9b6a8f9c6e184f7f"]]},{"id":"ae318f7d467ec754","type":"api-current-state","z":"082d1a6d7f9f4ee6","g":"4da31527a79ba2bb","name":"Battery SOC >= than 10%, discharge","server":"aa39721f.3c9dc","version":3,"outputs":2,"halt_if":"10","halt_if_type":"num","halt_if_compare":"gte","entity_id":"sensor.tesla_battery_state_of_charge","state_type":"num","blockInputOverrides":false,"outputProperties":[{"property":"status","propertyType":"msg","value":"SOC >= 10%","valueType":"str"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":1250,"y":280,"wires":[["0d8023037a7d1b5a"],["166f102fe8044a4d"]]},{"id":"6806eaeffeb00bc4","type":"ha-entity-config","server":"aa39721f.3c9dc","deviceConfig":"","name":"Energy selling","version":"6","entityType":"switch","haConfig":[{"property":"name","value":"Energy selling"},{"property":"icon","value":""},{"property":"entity_picture","value":""},{"property":"entity_category","value":""},{"property":"device_class","value":""}],"resend":false,"debugEnabled":false},{"id":"d154056291b873bc","type":"group","z":"082d1a6d7f9f4ee6","g":"972413b3b474c04e","name":"Selector","style":{"label":true,"stroke":"#9363b7","stroke-opacity":"0.55"},"nodes":["3bdd4e2662f4b4a4","98275a63d7578b29","fd320becde60c34c","d319fc7d7512279e","94137adeb2ba33eb","de8324abdcf0b2cf"],"x":54,"y":179,"w":632,"h":202},{"id":"3bdd4e2662f4b4a4","type":"api-current-state","z":"082d1a6d7f9f4ee6","g":"d154056291b873bc","name":"Get spot price","server":"aa39721f.3c9dc","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"sensor.epex_spot_data_net_price","state_type":"num","blockInputOverrides":false,"outputProperties":[{"property":"price","propertyType":"msg","value":"","valueType":"entityState"},{"property":"topic","propertyType":"msg","value":"price","valueType":"str"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":200,"y":220,"wires":[["94137adeb2ba33eb"]]},{"id":"98275a63d7578b29","type":"junction","z":"082d1a6d7f9f4ee6","g":"d154056291b873bc","x":80,"y":280,"wires":[["3bdd4e2662f4b4a4","fd320becde60c34c","d319fc7d7512279e"]]},{"id":"fd320becde60c34c","type":"api-current-state","z":"082d1a6d7f9f4ee6","g":"d154056291b873bc","name":"Get low price threshold","server":"aa39721f.3c9dc","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"input_number.low_price_threshold","state_type":"num","blockInputOverrides":false,"outputProperties":[{"property":"lowThreshold","propertyType":"msg","value":"","valueType":"entityState"},{"property":"topic","propertyType":"msg","value":"lowThreshold","valueType":"str"}],"for":0,"forType":"num","forUnits":"minutes","x":230,"y":280,"wires":[["94137adeb2ba33eb"]]},{"id":"d319fc7d7512279e","type":"api-current-state","z":"082d1a6d7f9f4ee6","g":"d154056291b873bc","name":"Get high price threshold","server":"aa39721f.3c9dc","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"input_number.high_price_threshold","state_type":"num","blockInputOverrides":false,"outputProperties":[{"property":"highThreshold","propertyType":"msg","value":"","valueType":"entityState"},{"property":"topic","propertyType":"msg","value":"highThreshold","valueType":"str"}],"for":0,"forType":"num","forUnits":"minutes","x":230,"y":340,"wires":[["94137adeb2ba33eb"]]},{"id":"94137adeb2ba33eb","type":"join","z":"082d1a6d7f9f4ee6","g":"d154056291b873bc","name":"","mode":"custom","build":"object","property":"","propertyType":"full","key":"topic","joiner":"\\n","joinerType":"str","useparts":false,"accumulate":false,"timeout":"","count":"3","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"num","reduceFixup":"","x":450,"y":260,"wires":[["de8324abdcf0b2cf"]]},{"id":"de8324abdcf0b2cf","type":"switch","z":"082d1a6d7f9f4ee6","g":"d154056291b873bc","name":"Price select (ct)","property":"price","propertyType":"msg","rules":[{"t":"lte","v":"lowThreshold","vt":"msg"},{"t":"gte","v":"highThreshold","vt":"msg"},{"t":"else"}],"checkall":"false","repair":false,"outputs":3,"x":580,"y":320,"wires":[["7f64baa7b4233a58"],["0afdd7a9f3168964"],["166f102fe8044a4d","fd2ffb49be6386f4"]]},{"id":"8934403241c202e6","type":"comment","z":"082d1a6d7f9f4ee6","g":"972413b3b474c04e","name":"10% SOC backup buffer","info":"De inverter is ingesteld op dat minimaal \n10% soc beschikbaar blijft voor backup-power\n\n% in te stellen op de locale GEN24 pagina:\nDevice configuration > FuncĀtions and I/Os","x":470,"y":100,"wires":[]},{"id":"6f28ef0306b0dbd9","type":"group","z":"082d1a6d7f9f4ee6","style":{"stroke":"#999999","stroke-opacity":"1","fill":"none","fill-opacity":"1","label":true,"label-position":"nw","color":"#a4a4a4"},"nodes":["7219cc5524b6201c","0d8023037a7d1b5a","e39ad0b0a923904a","8b9fdfe7e1821416"],"x":1474,"y":299,"w":552,"h":202},{"id":"7219cc5524b6201c","type":"function","z":"082d1a6d7f9f4ee6","g":"6f28ef0306b0dbd9","name":"Normal operation","func":"msg.storctl_mod = \"0\"\n\nmsg.newstate = \"normal\"\n\nreturn msg","outputs":1,"timeout":"","noerr":0,"initialize":"","finalize":"","libs":[],"x":1590,"y":460,"wires":[["8b9fdfe7e1821416"]],"info":"Example 3: Do not permit charging or discharging\nThis behavior can be achieved by limiting the maximum charge capacity to 0%\nand the maximum discharge capacity to 0%\n=> results in window [0 W, 0 W]\n- InWRte = 0% (set charge limit of WchaMax to 0%)\n- OutWRte = 0% (set discharge limit of WchaMax to 0%)\n- StorCtl_Mod = 3 (activate both limit values, bit pattern: 11)"},{"id":"0d8023037a7d1b5a","type":"function","z":"082d1a6d7f9f4ee6","g":"6f28ef0306b0dbd9","name":"Max discharge","func":"msg.storctl_mod = \"1\"\nmsg.outwrte = \"0\"\nmsg.inwrte = \"60933\"\n\nmsg.newstate = \"Max discharge\"\n\nreturn msg","outputs":1,"timeout":"","noerr":0,"initialize":"","finalize":"","libs":[],"x":1580,"y":340,"wires":[["8b9fdfe7e1821416"]],"info":"Example 3: Do not permit charging or discharging\nThis behavior can be achieved by limiting the maximum charge capacity to 0%\nand the maximum discharge capacity to 0%\n=> results in window [0 W, 0 W]\n- InWRte = 0% (set charge limit of WchaMax to 0%)\n- OutWRte = 0% (set discharge limit of WchaMax to 0%)\n- StorCtl_Mod = 3 (activate both limit values, bit pattern: 11)"},{"id":"e39ad0b0a923904a","type":"function","z":"082d1a6d7f9f4ee6","g":"6f28ef0306b0dbd9","name":"No discharge, allow solar charge","func":"msg.storctl_mod = \"3\"\nmsg.outwrte = \"0\"\nmsg.inwrte = \"2439\"\n\nmsg.newstate = \"No discharge, allow solar charge\"\n\nreturn msg","outputs":1,"timeout":"","noerr":0,"initialize":"","finalize":"","libs":[],"x":1640,"y":400,"wires":[["8b9fdfe7e1821416"]],"info":"Example 3: Do not permit charging or discharging\nThis behavior can be achieved by limiting the maximum charge capacity to 0%\nand the maximum discharge capacity to 0%\n=> results in window [0 W, 0 W]\n- InWRte = 0% (set charge limit of WchaMax to 0%)\n- OutWRte = 0% (set discharge limit of WchaMax to 0%)\n- StorCtl_Mod = 3 (activate both limit values, bit pattern: 11)"},{"id":"8b9fdfe7e1821416","type":"junction","z":"082d1a6d7f9f4ee6","g":"6f28ef0306b0dbd9","x":2000,"y":400,"wires":[["acc53a6f4ee7fcc1"]]},{"id":"336421b5a0497c39","type":"group","z":"082d1a6d7f9f4ee6","name":"Charge + Main fuse over current limiter for Home battery charger","style":{"fill":"#ffC000","fill-opacity":"0.78","label":true},"nodes":["987e5486ddb6e3cb","7072c1b693b72fe8","11a3663361be0176"],"x":1474,"y":199,"w":552,"h":82},{"id":"987e5486ddb6e3cb","type":"comment","z":"082d1a6d7f9f4ee6","g":"336421b5a0497c39","name":"TODO!","info":"Make some signalling on Home Assistant\ndashboard.","x":1950,"y":240,"wires":[]},{"id":"7072c1b693b72fe8","type":"function","z":"082d1a6d7f9f4ee6","g":"336421b5a0497c39","name":"Calculate amount of charge power","func":"// Retrieve the stored smart meter data from the flow context\nconst meterData = flow.get('smartMeterData');\n\nif (!meterData || !meterData.Body || !meterData.Body.Data) {\n node.error(\"No valid data from the smart meter\");\n return null;\n}\n\n// Extract data from the smart meter response\nconst phase1Current = meterData.Body.Data.Current_AC_Phase_1 || 0; // Phase 1 current in Amps\nconst phase2Current = meterData.Body.Data.Current_AC_Phase_2 || 0; // Phase 2 current in Amps\nconst phase3Current = meterData.Body.Data.Current_AC_Phase_3 || 0; // Phase 3 current in Amps\n\n// Constants for calculations\nconst fuseValue = 25; // Maximum allowable current in amps\nconst registerStart = 65291; // Maximum register value\nconst registerEnd = 63296; // Minimum register value\nconst extraStepUp = 200; // Extra step size for sudden overload\nconst stepUp = 50; // Step size to increase register value\nconst stepDown = 50; // Step size to decrease register value\n\n// Current register value and previous max current from context\nconst currentRegisterValue = context.get('currentRegisterValue') || registerStart;\nconst previousMaxCurrent = context.get('previousMaxCurrent') || 0;\n\n// Calculate maximum current across phases\nconst maxCurrent = Math.max(phase1Current, phase2Current, phase3Current);\n\n// Determine if the maximum current exceeds the fuse value\nconst availableMargin = fuseValue - maxCurrent;\nconst suddenOverload = maxCurrent > fuseValue + 5;\n\n// Adjust the register value based on conditions\nlet updatedRegisterValue = currentRegisterValue;\n\nif (suddenOverload) {\n // Increase register value due to sudden overload\n updatedRegisterValue = Math.min(currentRegisterValue + extraStepUp, registerStart);\n node.warn(\"Sudden overload detected. Increased register value.\");\n} else if (availableMargin <= 0) {\n // Increase register value due to overload\n updatedRegisterValue = Math.min(currentRegisterValue + stepUp, registerStart);\n node.warn(\"Overload detected. Increased register value.\");\n} else {\n // Decrease register value within safe margin\n updatedRegisterValue = Math.max(currentRegisterValue - stepDown, registerEnd);\n node.warn(\"Safe margin detected. Decreased register value.\");\n}\n\n// Store the updated register value and current in the context\ncontext.set('currentRegisterValue', updatedRegisterValue);\ncontext.set('previousMaxCurrent', maxCurrent);\n\nnode.warn(`Max current: ${maxCurrent}`);\nnode.warn(`Available margin: ${availableMargin}`);\nnode.warn(`Register value: ${currentRegisterValue}`);\n\n// Prepare the output message\nmsg.storctl_mod = \"2\";\nmsg.outwrte = updatedRegisterValue;\nmsg.inwrte = \"0\";\nmsg.newstate = \"charge power updated\";\nmsg.maxCurrent = maxCurrent;\n\nreturn msg;","outputs":1,"timeout":"","noerr":0,"initialize":"","finalize":"","libs":[],"x":1720,"y":240,"wires":[["8b9fdfe7e1821416"]]},{"id":"11a3663361be0176","type":"junction","z":"082d1a6d7f9f4ee6","g":"336421b5a0497c39","x":1500,"y":240,"wires":[["7072c1b693b72fe8"]]},{"id":"ee426500a61afdd4","type":"group","z":"082d1a6d7f9f4ee6","style":{"stroke":"#999999","stroke-opacity":"1","fill":"none","fill-opacity":"1","label":true,"label-position":"nw","color":"#a4a4a4"},"nodes":["http-request-node","storeSmartMeterData"],"x":234,"y":659,"w":512,"h":82},{"id":"http-request-node","type":"http request","z":"082d1a6d7f9f4ee6","g":"ee426500a61afdd4","name":"Get Smart Meter Data","method":"GET","ret":"obj","paytoqs":"ignore","url":"http://192.168.x.x/solar_api/v1/GetMeterRealtimeData.cgi?Scope=Device&DeviceId=0","tls":"","persist":false,"proxy":"","authType":"","x":360,"y":700,"wires":[["storeSmartMeterData"]]},{"id":"storeSmartMeterData","type":"change","z":"082d1a6d7f9f4ee6","g":"ee426500a61afdd4","name":"Store Smart Meter Data","rules":[{"t":"set","p":"smartMeterData","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":610,"y":700,"wires":[[]]}]