ok I donât know about the sonnen 8.1 (mine is an eco 9.43) but if its the same then you can control it via REST API.
If your battery is like mine you sould be able to log into it and and select software-integration from the menu. There you will be able to set the API token and all the REST API calls available.
Then you can set up node-red to make these calls when you want.
This is my flow for the control switches and interface to EMHASS via sensor.p_batt_forecast
[{"id":"f8c8624c7c9dca94","type":"http request","z":"65840aa926d9c567","name":"POST","method":"POST","ret":"obj","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"bearer","senderr":false,"headers":[],"x":1250,"y":340,"wires":[["0e3f0373d7e81e09","7e7a97b8e68d3389"]]},{"id":"858d53f8ca9abe53","type":"function","z":"65840aa926d9c567","name":"Charge Setup","func":"var pospayload = 0.0\npospayload = Math.abs(msg.payload)\nmsg.headers = {}\nmsg.headers['Auth-Token'] = 'YOUR SONNEN API TOKEN HERE'\nmsg.headers [\"Content-Type\"] = \"application/x-www-form-urlencoded\"\nmsg.url = \"http://192.168.99.168:80/api/v2/setpoint/charge/\" + pospayload.toString()\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1080,"y":340,"wires":[["f8c8624c7c9dca94"]]},{"id":"0e3f0373d7e81e09","type":"debug","z":"65840aa926d9c567","name":"debug Charge","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1440,"y":340,"wires":[]},{"id":"05d69d4319a0f5d6","type":"http request","z":"65840aa926d9c567","name":"POST","method":"POST","ret":"obj","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"bearer","senderr":false,"headers":[],"x":1250,"y":400,"wires":[["0e4ea3476743d2c3","7e7a97b8e68d3389"]]},{"id":"6151ac699f7381c1","type":"function","z":"65840aa926d9c567","name":"Discharge Setup","func":"var pospayload = 0.0\npospayload = Math.abs(msg.payload)\nmsg.headers = {}\nmsg.headers['Auth-Token'] = 'YOUR SONNEN API TOKEN HERE'\nmsg.headers [\"Content-Type\"] = \"application/x-www-form-urlencoded\"\nmsg.url = \"http://192.168.99.168:80/api/v2/setpoint/discharge/\" + pospayload.toString()\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1090,"y":400,"wires":[["05d69d4319a0f5d6"]]},{"id":"0e4ea3476743d2c3","type":"debug","z":"65840aa926d9c567","name":"debug discharge","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1450,"y":400,"wires":[]},{"id":"402679171d35e0d2","type":"http request","z":"65840aa926d9c567","name":"PUT","method":"PUT","ret":"obj","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"bearer","senderr":false,"headers":[],"x":1250,"y":280,"wires":[["5bd08bcd972153bc","81532e458a6da3d1"]]},{"id":"9efde64dbc00c864","type":"function","z":"65840aa926d9c567","name":"Manual Mode","func":"msg.payload = \"EM_OperatingMode=1\"\nmsg.headers = {}\nmsg.headers['Auth-Token'] = 'YOUR SONNEN API TOKEN HERE'\nmsg.headers [\"Content-Type\"] = \"application/x-www-form-urlencoded\"\nmsg.url = \"http://192.168.99.168:80/api/v2/configurations\" \nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1080,"y":280,"wires":[["402679171d35e0d2"]]},{"id":"5bd08bcd972153bc","type":"debug","z":"65840aa926d9c567","name":"debug Manual Mode","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1460,"y":280,"wires":[]},{"id":"10920422f5fa573e","type":"api-call-service","z":"65840aa926d9c567","name":"Switch turn-off Charge","server":"afc27684.cf6ed8","version":5,"debugenabled":false,"domain":"switch","service":"turn_off","areaId":[],"deviceId":[],"entityId":["switch.sonnen_charge_2"],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1020,"y":640,"wires":[[]]},{"id":"b66c43b2d71ebcfc","type":"http request","z":"65840aa926d9c567","name":"PUT","method":"PUT","ret":"obj","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"bearer","senderr":false,"headers":[],"x":1250,"y":220,"wires":[["1736681453a9e3de","81532e458a6da3d1"]]},{"id":"49c07dcad21bb88c","type":"function","z":"65840aa926d9c567","name":"Automatic Mode","func":"msg.payload = \"EM_OperatingMode=2\"\nmsg.headers = {}\nmsg.headers['Auth-Token'] = 'YOUR SONNEN API TOKEN HERE'\nmsg.headers [\"Content-Type\"] = \"application/x-www-form-urlencoded\"\nmsg.url = \"http://192.168.99.168:80/api/v2/configurations\" \nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1080,"y":220,"wires":[["b66c43b2d71ebcfc"]]},{"id":"1736681453a9e3de","type":"debug","z":"65840aa926d9c567","name":"debug Automation Mode","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1470,"y":220,"wires":[]},{"id":"d6e30b460a9ee319","type":"api-call-service","z":"65840aa926d9c567","name":"Switch turn-off Automatic Mode","server":"afc27684.cf6ed8","version":5,"debugenabled":false,"domain":"switch","service":"turn_off","areaId":[],"deviceId":[],"entityId":["switch.sonnen_automatic_mode"],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1050,"y":520,"wires":[[]]},{"id":"163bc3abe14e285d","type":"ha-switch","z":"65840aa926d9c567","name":"Sonnen Charge","version":0,"inputs":1,"outputs":2,"entityConfig":"2d18a92a5ddd4fd8","enableInput":true,"outputOnStateChange":true,"outputProperties":[{"property":"payload","propertyType":"msg","value":"-3300","valueType":"num"}],"x":360,"y":520,"wires":[["8f6da85cea51a6c2"],[]]},{"id":"3896b33d87e81de7","type":"ha-switch","z":"65840aa926d9c567","name":"Sonnen Discharge","version":0,"inputs":1,"outputs":2,"entityConfig":"ee18bd169efda9d5","enableInput":true,"outputOnStateChange":true,"outputProperties":[{"property":"payload","propertyType":"msg","value":"3300","valueType":"num"}],"x":370,"y":460,"wires":[["c4a70f29ecac9603"],[]]},{"id":"99ea255a2bb6c9fa","type":"ha-switch","z":"65840aa926d9c567","name":"Sonnen Manual Mode","version":0,"inputs":1,"outputs":2,"entityConfig":"15891e5320025a4a","enableInput":true,"outputOnStateChange":true,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"str"}],"x":380,"y":400,"wires":[["767baa7b0d82b4ca"],[]]},{"id":"594e3b2e22d599e5","type":"ha-switch","z":"65840aa926d9c567","name":"Sonnen Automatic Mode","version":0,"inputs":1,"outputs":2,"entityConfig":"d173cac1c20527d9","enableInput":true,"outputOnStateChange":true,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"str"}],"x":390,"y":580,"wires":[["53cefbe739be3a2f"],[]]},{"id":"4b6455180cf0d210","type":"delay","z":"65840aa926d9c567","name":"2 sec","pauseType":"delay","timeout":"2","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":930,"y":340,"wires":[["858d53f8ca9abe53"]]},{"id":"4e83ea6e880ed707","type":"delay","z":"65840aa926d9c567","name":"","pauseType":"delay","timeout":"1","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":840,"y":520,"wires":[["d6e30b460a9ee319"]]},{"id":"889022fc881fbb93","type":"delay","z":"65840aa926d9c567","name":"","pauseType":"delay","timeout":"1","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":840,"y":640,"wires":[["10920422f5fa573e"]]},{"id":"b04c5a889c7811e1","type":"api-call-service","z":"65840aa926d9c567","name":"Switch turn-off Manual Mode","server":"afc27684.cf6ed8","version":5,"debugenabled":false,"domain":"switch","service":"turn_off","areaId":[],"deviceId":[],"entityId":["switch.sonnen_manual_mode_2"],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1040,"y":580,"wires":[[]]},{"id":"1504b8a31a27f3c0","type":"delay","z":"65840aa926d9c567","name":"","pauseType":"delay","timeout":"1","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":840,"y":580,"wires":[["b04c5a889c7811e1"]]},{"id":"235f18f61ad60ba6","type":"api-call-service","z":"65840aa926d9c567","name":"Switch turn-off Discharge","server":"afc27684.cf6ed8","version":5,"debugenabled":false,"domain":"switch","service":"turn_off","areaId":[],"deviceId":[],"entityId":["switch.sonnen_discharge_2"],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1030,"y":700,"wires":[[]]},{"id":"05cf76adb5e1fce4","type":"delay","z":"65840aa926d9c567","name":"","pauseType":"delay","timeout":"1","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":840,"y":700,"wires":[["235f18f61ad60ba6"]]},{"id":"8a366e8d4d842810","type":"comment","z":"65840aa926d9c567","name":"EMHASS p_batt_forecast automation","info":"","x":370,"y":140,"wires":[]},{"id":"738d28e88d4351bd","type":"link in","z":"65840aa926d9c567","name":"link in Automatic Mode","links":["d7480326262afc7a","53cefbe739be3a2f","8254f5986525b3a1"],"x":835,"y":220,"wires":[["66797c25cd25ad79"]]},{"id":"214eb49945a0f314","type":"link in","z":"65840aa926d9c567","name":"link in Turn off Automatic Moode Switch","links":["767baa7b0d82b4ca","d9ba6153cfb88bbb","c4a70f29ecac9603","8f6da85cea51a6c2","cba7fee3cee79393"],"x":735,"y":520,"wires":[["4e83ea6e880ed707"]]},{"id":"f276c6683121c547","type":"link in","z":"65840aa926d9c567","name":"link in Turn off Manual Switch","links":["d7480326262afc7a","53cefbe739be3a2f","c4a70f29ecac9603","8f6da85cea51a6c2","cba7fee3cee79393"],"x":735,"y":580,"wires":[["1504b8a31a27f3c0"]]},{"id":"fb229ac0227a16b7","type":"link in","z":"65840aa926d9c567","name":"link in Turn off Charge Switch","links":["d7480326262afc7a","53cefbe739be3a2f","d9ba6153cfb88bbb","c4a70f29ecac9603","767baa7b0d82b4ca","cba7fee3cee79393"],"x":735,"y":640,"wires":[["889022fc881fbb93"]]},{"id":"d577eb36f0d74d39","type":"link in","z":"65840aa926d9c567","name":"link in Turn off Discharge switch","links":["d7480326262afc7a","53cefbe739be3a2f","8f6da85cea51a6c2","767baa7b0d82b4ca","cba7fee3cee79393"],"x":735,"y":700,"wires":[["05cf76adb5e1fce4"]]},{"id":"53cefbe739be3a2f","type":"link out","z":"65840aa926d9c567","name":"link out Automatic Mode Switch","mode":"link","links":["738d28e88d4351bd","d577eb36f0d74d39","f276c6683121c547","fb229ac0227a16b7","6b4bedbad37114cb","3272c7b24e7d407a"],"x":535,"y":580,"wires":[]},{"id":"93beed478696134e","type":"link in","z":"65840aa926d9c567","name":"link in Charge Setup","links":["8f6da85cea51a6c2","63ba9e6850f7361b","95976ebe7f6655d3","cc0a6d9606abe439","b42b8c412b6200e7"],"x":835,"y":340,"wires":[["4b6455180cf0d210"]]},{"id":"2608790487e879c8","type":"link in","z":"65840aa926d9c567","name":"link in Manual Mode Setup","links":["8f6da85cea51a6c2","c4a70f29ecac9603","767baa7b0d82b4ca","d9ba6153cfb88bbb","63ba9e6850f7361b","95976ebe7f6655d3","cc0a6d9606abe439","87b07b541bba63f6","b42b8c412b6200e7"],"x":835,"y":280,"wires":[["e8a2ee908ef64a78"]]},{"id":"5ee73c1f9154912a","type":"link in","z":"65840aa926d9c567","name":"link in Discharge Setup","links":["c4a70f29ecac9603","d9ba6153cfb88bbb","87b07b541bba63f6"],"x":835,"y":400,"wires":[["174d6cc39f3cf6db"]]},{"id":"8f6da85cea51a6c2","type":"link out","z":"65840aa926d9c567","name":"link out Charge Mode Switch","mode":"link","links":["2608790487e879c8","93beed478696134e","28f35002be45f983","214eb49945a0f314","f276c6683121c547","d577eb36f0d74d39","6b4bedbad37114cb","3272c7b24e7d407a"],"x":535,"y":520,"wires":[]},{"id":"c4a70f29ecac9603","type":"link out","z":"65840aa926d9c567","name":"link out Discharge Mode Switch","mode":"link","links":["5ee73c1f9154912a","2608790487e879c8","214eb49945a0f314","f276c6683121c547","fb229ac0227a16b7","6b4bedbad37114cb","3272c7b24e7d407a"],"x":535,"y":460,"wires":[]},{"id":"174d6cc39f3cf6db","type":"delay","z":"65840aa926d9c567","name":"2 sec","pauseType":"delay","timeout":"2","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":930,"y":400,"wires":[["6151ac699f7381c1"]]},{"id":"767baa7b0d82b4ca","type":"link out","z":"65840aa926d9c567","name":"link out Manual Mode Switch","mode":"link","links":["2608790487e879c8","214eb49945a0f314","fb229ac0227a16b7","d577eb36f0d74d39","0fdea619274a2742","3272c7b24e7d407a"],"x":535,"y":400,"wires":[]},{"id":"63ba9e6850f7361b","type":"link out","z":"65840aa926d9c567","name":"link out EMHASS Charge","mode":"link","links":["2608790487e879c8","6b4bedbad37114cb","93beed478696134e"],"x":535,"y":180,"wires":[]},{"id":"b42b8c412b6200e7","type":"link out","z":"65840aa926d9c567","name":"link out Zero Charge","mode":"link","links":["0fdea619274a2742","2608790487e879c8","93beed478696134e"],"x":535,"y":220,"wires":[]},{"id":"71b6831a8862dc59","type":"http request","z":"65840aa926d9c567","name":"PUT","method":"PUT","ret":"obj","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"bearer","senderr":false,"headers":[],"x":1250,"y":160,"wires":[["0463b2679edf6145","81532e458a6da3d1"]]},{"id":"0a139a31c1ecd269","type":"function","z":"65840aa926d9c567","name":"100% Backup Buffer","func":"msg.payload = \"EM_USOC=100\"\nmsg.headers = {}\nmsg.headers['Auth-Token'] = 'YOUR SONNEN API TOKEN HERE'\nmsg.headers[\"Content-Type\"] = \"application/x-www-form-urlencoded\"\nmsg.url = \"http://192.168.99.168:80/api/v2/configurations\"\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1060,"y":160,"wires":[["71b6831a8862dc59"]]},{"id":"0463b2679edf6145","type":"debug","z":"65840aa926d9c567","name":"debug 100% Backup Buffer","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1480,"y":160,"wires":[]},{"id":"0fdea619274a2742","type":"link in","z":"65840aa926d9c567","name":"link in 100% Backup Buffer","links":["767baa7b0d82b4ca","b42b8c412b6200e7"],"x":835,"y":160,"wires":[["0a139a31c1ecd269"]]},{"id":"87b07b541bba63f6","type":"link out","z":"65840aa926d9c567","name":"link out EMHASS Discharge","mode":"link","links":["2608790487e879c8","5ee73c1f9154912a","6b4bedbad37114cb"],"x":535,"y":260,"wires":[]},{"id":"95b0d1a62df57792","type":"server-state-changed","z":"65840aa926d9c567","name":"p_batt_forecast level","server":"afc27684.cf6ed8","version":4,"exposeToHomeAssistant":true,"haConfig":[{"property":"name","value":"EMHASS Control"},{"property":"icon","value":"mdi:home-battery"}],"entityidfilter":"sensor.p_batt_forecast","entityidfiltertype":"exact","outputinitially":true,"state_type":"num","haltifstate":"","halt_if_type":"num","halt_if_compare":"lt","outputs":1,"output_only_on_state_change":true,"for":"0","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"}],"x":110,"y":160,"wires":[["cba7fee3cee79393","3467d7c82fe5fdbe"]]},{"id":"b42f3c112eb6fd00","type":"inject","z":"65840aa926d9c567","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"0","payloadType":"num","x":90,"y":220,"wires":[["cba7fee3cee79393","3467d7c82fe5fdbe"]]},{"id":"3467d7c82fe5fdbe","type":"switch","z":"65840aa926d9c567","name":"","property":"payload","propertyType":"msg","rules":[{"t":"lt","v":"0","vt":"num"},{"t":"eq","v":"0","vt":"num"},{"t":"gt","v":"0","vt":"num"}],"checkall":"true","repair":false,"outputs":3,"x":350,"y":220,"wires":[["63ba9e6850f7361b"],["b42b8c412b6200e7"],["87b07b541bba63f6"]]},{"id":"c9c830d16e77ad07","type":"http request","z":"65840aa926d9c567","name":"PUT","method":"PUT","ret":"obj","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"bearer","senderr":false,"headers":[],"x":1250,"y":100,"wires":[["67f43764710f12ca","81532e458a6da3d1"]]},{"id":"8ba6e02a205fedf5","type":"function","z":"65840aa926d9c567","name":"0% Backup Buffer","func":"msg.payload = \"EM_USOC=0\"\nmsg.headers = {}\nmsg.headers['Auth-Token'] = 'YOUR SONNEN API TOKEN HERE'\nmsg.headers[\"Content-Type\"] = \"application/x-www-form-urlencoded\"\nmsg.url = \"http://192.168.99.168:80/api/v2/configurations\"\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1050,"y":100,"wires":[["c9c830d16e77ad07"]]},{"id":"67f43764710f12ca","type":"debug","z":"65840aa926d9c567","name":"debug 0% Backup Buffer","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1470,"y":100,"wires":[]},{"id":"6b4bedbad37114cb","type":"link in","z":"65840aa926d9c567","name":"link in 0% Backup Buffer","links":["8254f5986525b3a1","87b07b541bba63f6","53cefbe739be3a2f","d7480326262afc7a","63ba9e6850f7361b","c4a70f29ecac9603","8f6da85cea51a6c2"],"x":835,"y":100,"wires":[["8ba6e02a205fedf5"]]},{"id":"66797c25cd25ad79","type":"delay","z":"65840aa926d9c567","name":"2 sec","pauseType":"delay","timeout":"2","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":930,"y":220,"wires":[["49c07dcad21bb88c"]]},{"id":"e8a2ee908ef64a78","type":"delay","z":"65840aa926d9c567","name":"1 sec","pauseType":"delay","timeout":"1","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":930,"y":280,"wires":[["9efde64dbc00c864"]]},{"id":"cba7fee3cee79393","type":"link out","z":"65840aa926d9c567","name":"link out EMHASS Control","mode":"link","links":["214eb49945a0f314","f276c6683121c547","fb229ac0227a16b7","d577eb36f0d74d39","3272c7b24e7d407a"],"x":535,"y":340,"wires":[]},{"id":"7e6123cc6e5d7580","type":"comment","z":"65840aa926d9c567","name":"< 0 charge","info":"","x":620,"y":180,"wires":[]},{"id":"9756ce48f8071dee","type":"comment","z":"65840aa926d9c567","name":"> 0 discharge","info":"","x":630,"y":260,"wires":[]},{"id":"0599d210da9c7483","type":"api-call-service","z":"65840aa926d9c567","name":"Notify Robert's iPhones","server":"afc27684.cf6ed8","version":5,"debugenabled":false,"domain":"notify","service":"mobile_app_robsiphone","areaId":[],"deviceId":[],"entityId":[],"data":"{\"title\":\"EMHASS POST to battery failed\",\"message\":\"error: '{{statusCode}}' URL: '{{responseUrl}}'\"}","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1710,"y":460,"wires":[[]]},{"id":"7e7a97b8e68d3389","type":"function","z":"65840aa926d9c567","name":"POST return != 201","func":"var status = msg.statusCode\nif(status != 201)\n{\n return msg\n}\nelse\nreturn","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1450,"y":460,"wires":[["0599d210da9c7483","b0d1e98b69148145"]]},{"id":"d56afcddad76fb9e","type":"api-call-service","z":"65840aa926d9c567","name":"Notify Robert's iPhones","server":"afc27684.cf6ed8","version":5,"debugenabled":false,"domain":"notify","service":"mobile_app_robsiphone","areaId":[],"deviceId":[],"entityId":[],"data":"{\"title\":\"EMHASS PUT to Battery failed\",\"message\":\"{{statusCode}}\"}","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1670,"y":40,"wires":[[]]},{"id":"81532e458a6da3d1","type":"function","z":"65840aa926d9c567","name":"PUT return != 200","func":"var status = msg.statusCode\nif(status != 200)\n{\n return msg\n}\nelse\nreturn","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1450,"y":40,"wires":[["d56afcddad76fb9e","58249f1787db2d31"]]},{"id":"aa3305bba4e89057","type":"ha-switch","z":"65840aa926d9c567","name":"Sonnen Standby","version":0,"debugenabled":false,"inputs":1,"outputs":2,"entityConfig":"022b9a4b7acb0aa7","enableInput":true,"outputOnStateChange":true,"outputProperties":[{"property":"outputType","propertyType":"msg","value":"state change","valueType":"str"},{"property":"payload","propertyType":"msg","value":"0","valueType":"num"}],"x":360,"y":340,"wires":[["cba7fee3cee79393","3467d7c82fe5fdbe"],[]]},{"id":"2ff2f7eb24f82350","type":"api-call-service","z":"65840aa926d9c567","name":"Switch turn-off Standby","server":"afc27684.cf6ed8","version":5,"debugenabled":false,"domain":"switch","service":"turn_off","areaId":[],"deviceId":[],"entityId":["switch.sonnen_standby"],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1030,"y":460,"wires":[[]]},{"id":"2bf09f945cc2a28a","type":"delay","z":"65840aa926d9c567","name":"","pauseType":"delay","timeout":"1","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":840,"y":460,"wires":[["2ff2f7eb24f82350"]]},{"id":"3272c7b24e7d407a","type":"link in","z":"65840aa926d9c567","name":"link in Standby off","links":["767baa7b0d82b4ca","c4a70f29ecac9603","8f6da85cea51a6c2","53cefbe739be3a2f","cba7fee3cee79393"],"x":735,"y":460,"wires":[["2bf09f945cc2a28a"]]},{"id":"035211769c9ed7a4","type":"function","z":"65840aa926d9c567","name":"POST Params","func":"var payload = msg.payload\nmsg.headers = {}\nmsg.headers[\"Content-Type\"] = \"application/json\"\nmsg.url = \"http://192.168.99.17:5000/action/naive-mpc-optim\"\nmsg.payload = payload\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":620,"y":780,"wires":[["80bd09881d89d374"]]},{"id":"cc56cc8594ded18c","type":"api-render-template","z":"65840aa926d9c567","name":"MPC Array","server":"afc27684.cf6ed8","version":0,"template":"{\"load_cost_forecast\":{{(\n ([states('sensor.cecil_st_general_price')|float(0)] +\n state_attr('sensor.cecil_st_general_forecast', 'forecasts') |map(attribute='per_kwh')|list)[:48])\n }}, \"prod_price_forecast\":{{(\n ([states('sensor.cecil_st_feed_in_price')|float(0)] +\n state_attr('sensor.cecil_st_feed_in_forecast', 'forecasts')|map(attribute='per_kwh')|list)[:48]) \n }},\"pv_power_forecast\":{{([states('sensor.sonnenbatterie_84324_production_w')|int(0)] +\n state_attr('sensor.forecast_today', 'detailedForecast')|selectattr('period_start','gt',utcnow()) | map(attribute='pv_estimate')|map('multiply',2000)|map('int')|list +\n state_attr('sensor.forecast_tomorrow', 'detailedForecast')|selectattr('period_start','gt',utcnow()) | map(attribute='pv_estimate')|map('multiply',2000)|map('int')|list\n )| tojson\n }}, \"prediction_horizon\":{{min(48, (state_attr('sensor.cecil_st_feed_in_forecast', 'forecasts')|map(attribute='per_kwh')|list|length)+1)\n }},\"soc_init\":{{(states('sensor.sonnenbatterie_84324_state_charge_user')|float(0))/100\n }},\"soc_final\":0.05,\"def_total_hours\":[2]}","resultsLocation":"payload","resultsLocationType":"msg","templateLocation":"","templateLocationType":"none","x":450,"y":780,"wires":[["035211769c9ed7a4"]]},{"id":"be01d6d98c163e23","type":"inject","z":"65840aa926d9c567","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"60","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"str","x":310,"y":780,"wires":[["cc56cc8594ded18c"]]},{"id":"459be90396eb63a0","type":"debug","z":"65840aa926d9c567","name":"debug MPC POST","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1510,"y":720,"wires":[]},{"id":"80bd09881d89d374","type":"http request","z":"65840aa926d9c567","name":"POST MPC","method":"POST","ret":"txt","paytoqs":"ignore","url":"http://192.168.99.17:5000/action/naive-mpc-optim","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[{"keyType":"Content-Type","keyValue":"","valueType":"application/json","valueValue":""}],"x":790,"y":780,"wires":[["459be90396eb63a0","7e7a97b8e68d3389","62d9e74bace8efe8"]]},{"id":"62d9e74bace8efe8","type":"change","z":"65840aa926d9c567","name":"","rules":[{"t":"set","p":"url","pt":"msg","to":"http://192.168.99.17:5000/action/publish-data","tot":"str"},{"t":"set","p":"method","pt":"msg","to":"POST","tot":"str"},{"t":"set","p":"headers","pt":"msg","to":"Content-Type: application/json","tot":"str"},{"t":"set","p":"payload","pt":"msg","to":"{}","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1000,"y":780,"wires":[["bec2a54eea11d3e8"]]},{"id":"bec2a54eea11d3e8","type":"http request","z":"65840aa926d9c567","name":"POST Publish data","method":"use","ret":"txt","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[],"x":1210,"y":780,"wires":[["459be90396eb63a0"]]},{"id":"b0d1e98b69148145","type":"file","z":"65840aa926d9c567","name":"write error","filename":"/share/sonnenposterror.log","filenameType":"str","appendNewline":true,"createDir":true,"overwriteFile":"false","encoding":"none","x":1700,"y":420,"wires":[[]]},{"id":"58249f1787db2d31","type":"file","z":"65840aa926d9c567","name":"write error","filename":"/share/sonnenputerror.log","filenameType":"str","appendNewline":true,"createDir":true,"overwriteFile":"false","encoding":"none","x":1720,"y":100,"wires":[[]]},{"id":"afc27684.cf6ed8","type":"server","name":"Home Assistant","version":5,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":30,"areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"friendlyName","statusSeparator":"at: ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"h23","statusTimeFormat":"h:m","enableGlobalContextStore":true},{"id":"2d18a92a5ddd4fd8","type":"ha-entity-config","server":"afc27684.cf6ed8","deviceConfig":"","name":"switch config for Sonnen Charge","version":"6","entityType":"switch","haConfig":[{"property":"name","value":"Sonnen Charge"},{"property":"icon","value":"mdi:battery-plus-outline"},{"property":"entity_category","value":""},{"property":"entity_picture","value":""},{"property":"device_class","value":""}],"resend":true,"debugEnabled":false},{"id":"ee18bd169efda9d5","type":"ha-entity-config","server":"afc27684.cf6ed8","deviceConfig":"","name":"switch config for Sonnen Discharge","version":"6","entityType":"switch","haConfig":[{"property":"name","value":"Sonnen Discharge"},{"property":"icon","value":"mdi:battery-minus-outline"},{"property":"entity_category","value":""},{"property":"entity_picture","value":""},{"property":"device_class","value":""}],"resend":true,"debugEnabled":false},{"id":"15891e5320025a4a","type":"ha-entity-config","server":"afc27684.cf6ed8","deviceConfig":"","name":"switch config for Sonnen manual mode","version":"6","entityType":"switch","haConfig":[{"property":"name","value":"Sonnen Manual Mode"},{"property":"icon","value":"mdi:car-shift-pattern"},{"property":"entity_category","value":""},{"property":"entity_picture","value":""},{"property":"device_class","value":""}],"resend":true,"debugEnabled":false},{"id":"d173cac1c20527d9","type":"ha-entity-config","server":"afc27684.cf6ed8","deviceConfig":"","name":"switch config for Sonnen Automatic Mode test","version":"6","entityType":"switch","haConfig":[{"property":"name","value":"Sonnen Automatic Mode"},{"property":"icon","value":"mdi:refresh-auto"},{"property":"entity_category","value":""},{"property":"entity_picture","value":""},{"property":"device_class","value":""}],"resend":true,"debugEnabled":false},{"id":"022b9a4b7acb0aa7","type":"ha-entity-config","server":"afc27684.cf6ed8","deviceConfig":"","name":"Sonnen Standby","version":"6","entityType":"switch","haConfig":[{"property":"name","value":"Sonnen Standby"},{"property":"icon","value":"mdi:cog-off-outline"},{"property":"entity_category","value":""},{"property":"entity_picture","value":""},{"property":"device_class","value":""}],"resend":false,"debugEnabled":false}]