Custom Integration: Sonnenbatterie

What is shown in the HA Log?

Is anyone able to help with how to make my idea work for my system?:

  • I get free power from the power company from 9pm-12am every day.
  • I put the Sonnen into manual mode and make it fully charge over this time
  • Car charger also charges the car at this time to about 1/2 full from empty
  • The car charger has a Solar mode where it monitors grid export, and when there is any power exported, it starts feeding that into the car as long as its plugged in. It wont charge from the grid except for the time I specified above.
  • As all excess solar is used first to charge the Sonnen, the battery has to get to 100% before it shows up as exporting to the grid for the car charging system.

So I was thinking if I could bypass the Sonnen from charging from solar at around 60-70% and have the solar charge the car, the Sonnen would have enough power to run the house until 9pm, then get fully charged from the grid. I’ve looked through the API’s and nothing to me stands out has being able to stop the Sonnen from charging from PV. (But I dont really know what most of the APIs actually mean)

I did have an idea after looking at a post above for a work around. I could write a Node red flow that monitors the Sonnen battery state between say 10am-3pm, and whenever it reaches 80% or so, discharges until it hits 60% which will then go into the car battery.

Thanks a lot for this!
I had the same issue… didn’t bother too much to get it fixed, but when I saw this, tried it and yes it works again.

1 Like

@pirpy Does this work?

[
    {
        "id": "c6c55bc1b05efe1a",
        "type": "http request",
        "z": "2518eeecba83559e",
        "name": "Status Request",
        "method": "GET",
        "ret": "obj",
        "paytoqs": "body",
        "url": "",
        "tls": "",
        "persist": false,
        "proxy": "",
        "insecureHTTPParser": false,
        "authType": "bearer",
        "senderr": false,
        "headers": [],
        "x": 360,
        "y": 360,
        "wires": [
            [
                "4c2fe18b598a80f6",
                "79f63e1e144482ea"
            ]
        ]
    },
    {
        "id": "62ce92d4f58c11a6",
        "type": "inject",
        "z": "2518eeecba83559e",
        "name": "Paus",
        "props": [],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "x": 70,
        "y": 360,
        "wires": [
            [
                "93ed6ec22e9f6078"
            ]
        ]
    },
    {
        "id": "79f63e1e144482ea",
        "type": "switch",
        "z": "2518eeecba83559e",
        "name": "Manual?",
        "property": "payload.OperatingMode",
        "propertyType": "msg",
        "rules": [
            {
                "t": "eq",
                "v": "1",
                "vt": "str"
            },
            {
                "t": "eq",
                "v": "2",
                "vt": "str"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 2,
        "x": 560,
        "y": 360,
        "wires": [
            [],
            []
        ]
    },
    {
        "id": "93ed6ec22e9f6078",
        "type": "function",
        "z": "2518eeecba83559e",
        "name": "function 1",
        "func": "msg.headers = {}\nmsg.headers['Auth-Token'] = '5a61c845-79d8-4a9b-a149-2bc2c1babec7'\nmsg.headers[\"Content-Type\"] = \"application/x-www-form-urlencoded\"\nmsg.url = \"http://192.168.1.55:80/api/v2/status\"\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 200,
        "y": 360,
        "wires": [
            [
                "c6c55bc1b05efe1a"
            ]
        ]
    },
    {
        "id": "4c2fe18b598a80f6",
        "type": "debug",
        "z": "2518eeecba83559e",
        "name": "debug 1",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 660,
        "y": 320,
        "wires": []
    }
]

I Have to ask, this is what I’m attempting to do also and impliment into my system. I have no clue how to die this. I have the hacs file downloaded but I don’t know how to edit this?

The manual charge discharge I need to deploy for better control of my system

This is how I manage charging and discharging and switching loads on and off. I’m using the EMHASS add-on. This takes a feed of electricity price and FiT forecast (if you have these forecasts available), solar forecast from the likes of solcast.com and some historical data like last X days of power consumption and it produces a plan for the next 24 hours.

I then use the sensors returned by EMHASS to manage the battery and any loads in the house I want the system to manage (car charging, pool pump, hot waster etc.).

Example of a 24hr plan:

This plan has the schedue for charging and discharging the battery and at what wattage. The green below the line is a forecast sensor with charge schedule and wattage and above the line is discharge time and wattage:

You can see this charge and discharge lines up with a forecast of Feed-in Tariff and price from my electricity company (which happens to be a variable wholesale FiT and price). Its instructing the battery to charge in the morning between about 10:30 and 14:00 when the price is low and the sun is shining. Discharge is after 16:00 when the FiT is high.

FiT:

Pirce (which is of cause higher than the FiT):

This plan changes constantly (I run the calcualtion every minute) so the graph has change below. This is the solar forecast from solcast. Which also influences the charge/discharge and load schedules:

Pool pump load (deferrable load that is contoled by EMHASS):

House load. What the system forecasts we will use in the house over the next 24hrs.

This system only levers the sensors into home assistant. It doesn’t contol the battery or pool pump directly. You have to build the interface yourself.

I’ve done this in node-red:


This setup does three things:

  1. Takes the charge/discharge sensor from EMHASS and sends http POST and PUT to the sonnen battery and reports back any errors from the battery to my phone.
  2. Takes the deferrable load sensors from EMHASS and turns the pool pump on and off (only using one deferrable load at the moment)
  3. Backages up the forecast data (FiT and price) from my electricity company and the solar forecast from solcast and builds an array of all that data and POSTs that into EMAHSS every minute.

It also makes available mannual contols over the batter via switch nodes. This is then displayed on a dashboard. Example below:

Rob,
your setup looks pretty schmick. I want to delve into something like this but I need to work out how to contend with my house loads. I recently installed a sauna that sucks up about 6-8kW each hour. Obviously I can’t run this during the day as no-one is here to use it. We sauna after work hours. I tried to do a bit of preheat during the day to utilise more of my solar but winter is probably not the best time to do this.
I reckon I’m gonna need another two Sonnen batteries now to cover this along with all normal appliances.
Pat

This is awsome and what im trying to do with my local wholesaler rates in Australia.

The only thing I’m trying to find out is how you got the charge and discharge to work as the standard hacs download doesn’t have it. It’s purely sensors.

I’ve got the sonnen 8.1 and I want to control it exact same way.

I seem tio remember Rob or someone else mentioning that if you go to the IP address of your battery and login you will get access to the commands required. I have logged in and confirmed that I can do that - I need to switch the battery from automatic to manual and then set the disharge rate and then press discharge. A lot of commands to get right. I haven’t gone as far as trying to get this into emhass and automated but I guess with time… it’s project 234 at the moment.
Pat

I have an EV which also sucks up the juice. I was planning to include it as a deferrable load in EMHASS but so far I’ve left it out of its control. I just pick the best window to charge.

With amber electric (my electricity supplier) I get a forecast of price and FiT so I try to pick the best period to charge.

FiT can fluctuate from -10c to like $17. But I usually get a curve like this:


You can see a spike of $6/kWh yesterday and you want the system to be discharging at that point but to charge an EV I just set it to charge when the price is very low like 13c/kWh in the middle of the day or at 3am.

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}]

These are other component flows.

[{"id":"f49b840467d14aca","type":"inject","z":"65840aa926d9c567","name":"trigger","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":310,"y":900,"wires":[["4f20c85e38e98c5e"]]},{"id":"4f20c85e38e98c5e","type":"function","z":"65840aa926d9c567","name":"Retrieve mode","func":"msg.headers = {}\nmsg.headers['Auth-Token'] = 'YOUR SONNEN TOKEN'\nmsg.headers [\"Content-Type\"] = \"application/x-www-form-urlencoded\"\nmsg.url = \"http://192.168.99.168:80/api/v2/configurations/EM_OperatingMode\"\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":460,"y":900,"wires":[["c23e139112a8dce9"]]},{"id":"c23e139112a8dce9","type":"http request","z":"65840aa926d9c567","name":"get State","method":"GET","ret":"obj","paytoqs":"body","url":"","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"bearer","senderr":false,"headers":[],"x":620,"y":900,"wires":[["de6e76a004e1f6b3"]]},{"id":"de6e76a004e1f6b3","type":"debug","z":"65840aa926d9c567","name":"GET operating mode","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":880,"y":900,"wires":[]},{"id":"dcf72bf2f1dc306f","type":"http request","z":"65840aa926d9c567","name":"Status Request","method":"GET","ret":"obj","paytoqs":"body","url":"","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"bearer","senderr":false,"headers":[],"x":640,"y":960,"wires":[["520c8fab2df4add5"]]},{"id":"c616cb50e3f013e5","type":"inject","z":"65840aa926d9c567","name":"Trigger","props":[],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":310,"y":960,"wires":[["31ef47cf7df4bd23"]]},{"id":"31ef47cf7df4bd23","type":"function","z":"65840aa926d9c567","name":"Status Params","func":"msg.headers = {}\nmsg.headers['Auth-Token'] = 'YOUR SONNEN TOKEN'\nmsg.headers[\"Content-Type\"] = \"application/x-www-form-urlencoded\"\nmsg.url = \"http://192.168.99.168:80/api/v2/status\"\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":460,"y":960,"wires":[["dcf72bf2f1dc306f"]]},{"id":"520c8fab2df4add5","type":"debug","z":"65840aa926d9c567","name":"GET Status","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":850,"y":960,"wires":[]},{"id":"f51f44ccea58465f","type":"comment","z":"65840aa926d9c567","name":"GET Status","info":"","x":150,"y":960,"wires":[]},{"id":"becc1fdfc5a07c8c","type":"http request","z":"65840aa926d9c567","name":"Status Request","method":"GET","ret":"obj","paytoqs":"body","url":"","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"bearer","senderr":false,"headers":[],"x":640,"y":1020,"wires":[["a2acdd4ef8a2e7e3"]]},{"id":"fb0902746f5bab42","type":"inject","z":"65840aa926d9c567","name":"Trigger","props":[],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":310,"y":1020,"wires":[["e0be402ddf51cfbb"]]},{"id":"e0be402ddf51cfbb","type":"function","z":"65840aa926d9c567","name":"Status Params","func":"msg.headers = {}\nmsg.headers['Auth-Token'] = 'YOUR SONNEN TOKEN'\nmsg.headers[\"Content-Type\"] = \"application/x-www-form-urlencoded\"\nmsg.url = \"http://192.168.99.168:80/api/v2/io\"\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":460,"y":1020,"wires":[["becc1fdfc5a07c8c"]]},{"id":"a2acdd4ef8a2e7e3","type":"debug","z":"65840aa926d9c567","name":"GET IO","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":840,"y":1020,"wires":[]},{"id":"e8dbe3b330ea803e","type":"comment","z":"65840aa926d9c567","name":"GET IO","info":"","x":170,"y":1020,"wires":[]},{"id":"5176c1062a394a95","type":"http request","z":"65840aa926d9c567","name":"Status Request","method":"GET","ret":"obj","paytoqs":"body","url":"","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"bearer","senderr":false,"headers":[],"x":640,"y":1080,"wires":[["c6410de503791df9"]]},{"id":"9b243a676ccfb88e","type":"inject","z":"65840aa926d9c567","name":"Trigger","props":[],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":310,"y":1080,"wires":[["173e80755bdb5261"]]},{"id":"173e80755bdb5261","type":"function","z":"65840aa926d9c567","name":"Status Params","func":"msg.headers = {}\nmsg.headers['Auth-Token'] = 'YOUR SONNEN TOKEN'\nmsg.headers[\"Content-Type\"] = \"application/x-www-form-urlencoded\"\nmsg.url = \"http://192.168.99.168:80/api/v2/battery\"\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":460,"y":1080,"wires":[["5176c1062a394a95"]]},{"id":"c6410de503791df9","type":"debug","z":"65840aa926d9c567","name":"GET Battery","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":850,"y":1080,"wires":[]},{"id":"5c0ef53e4e44158d","type":"comment","z":"65840aa926d9c567","name":"GET Battery","info":"","x":150,"y":1080,"wires":[]},{"id":"553306fb16b96940","type":"http request","z":"65840aa926d9c567","name":"Status Request","method":"GET","ret":"obj","paytoqs":"body","url":"","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"bearer","senderr":false,"headers":[],"x":640,"y":1140,"wires":[["a0353cca92e68c16"]]},{"id":"842f6343da93d49c","type":"inject","z":"65840aa926d9c567","name":"Trigger","props":[],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":310,"y":1140,"wires":[["8293ee5ee5596f8f"]]},{"id":"8293ee5ee5596f8f","type":"function","z":"65840aa926d9c567","name":"Status Params","func":"msg.headers = {}\nmsg.headers['Auth-Token'] = 'YOUR SONNEN TOKEN'\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":460,"y":1140,"wires":[["553306fb16b96940"]]},{"id":"a0353cca92e68c16","type":"debug","z":"65840aa926d9c567","name":"GET Configurations","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":870,"y":1140,"wires":[]},{"id":"39286523c9b62903","type":"comment","z":"65840aa926d9c567","name":"GET Configurations","info":"","x":130,"y":1140,"wires":[]},{"id":"ac04e9f3576b49d5","type":"http request","z":"65840aa926d9c567","name":"Status Request","method":"GET","ret":"obj","paytoqs":"body","url":"","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"bearer","senderr":false,"headers":[],"x":640,"y":1200,"wires":[["c4bc628c4fd44b18"]]},{"id":"1c2ab7107cbac5b5","type":"inject","z":"65840aa926d9c567","name":"Trigger","props":[],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":310,"y":1200,"wires":[["9606a2a1504d07d5"]]},{"id":"9606a2a1504d07d5","type":"function","z":"65840aa926d9c567","name":"Status Params","func":"msg.headers = {}\nmsg.headers['Auth-Token'] = 'YOUR SONNEN TOKEN'\nmsg.headers[\"Content-Type\"] = \"application/x-www-form-urlencoded\"\nmsg.url = \"http://192.168.99.168:80/api/v2/inverter\"\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":460,"y":1200,"wires":[["ac04e9f3576b49d5"]]},{"id":"c4bc628c4fd44b18","type":"debug","z":"65840aa926d9c567","name":"GET Inverter","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":850,"y":1200,"wires":[]},{"id":"01548c5b60c0b68a","type":"comment","z":"65840aa926d9c567","name":"GET Inverter","info":"","x":150,"y":1200,"wires":[]},{"id":"080d44b50dd0dd93","type":"http request","z":"65840aa926d9c567","name":"Status Request","method":"GET","ret":"obj","paytoqs":"body","url":"","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"bearer","senderr":false,"headers":[],"x":640,"y":1260,"wires":[["3b9297f3cbf62658"]]},{"id":"19dd47afef0ca74d","type":"inject","z":"65840aa926d9c567","name":"Trigger","props":[],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":310,"y":1260,"wires":[["578044a0e7ce7634"]]},{"id":"578044a0e7ce7634","type":"function","z":"65840aa926d9c567","name":"Status Params","func":"msg.headers = {}\nmsg.headers['Auth-Token'] = 'YOUR SONNEN TOKEN'\nmsg.headers[\"Content-Type\"] = \"application/x-www-form-urlencoded\"\nmsg.url = \"http://192.168.99.168:80/api/v2/latestdata\"\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":460,"y":1260,"wires":[["080d44b50dd0dd93"]]},{"id":"3b9297f3cbf62658","type":"debug","z":"65840aa926d9c567","name":"GET Latestdata","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":860,"y":1260,"wires":[]},{"id":"30f5e3f99a78c778","type":"comment","z":"65840aa926d9c567","name":"GET Latestdata","info":"","x":140,"y":1260,"wires":[]},{"id":"4b7c72c4088338cb","type":"http request","z":"65840aa926d9c567","name":"Status Request","method":"GET","ret":"obj","paytoqs":"body","url":"","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"bearer","senderr":false,"headers":[],"x":640,"y":1320,"wires":[["b918447f5f8ce9a4"]]},{"id":"9258719230a2601a","type":"inject","z":"65840aa926d9c567","name":"Trigger","props":[],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":310,"y":1320,"wires":[["5d706338108541ef"]]},{"id":"5d706338108541ef","type":"function","z":"65840aa926d9c567","name":"Status Params","func":"msg.headers = {}\nmsg.headers['Auth-Token'] = 'YOUR SONNEN TOKEN'\nmsg.headers[\"Content-Type\"] = \"application/x-www-form-urlencoded\"\nmsg.url = \"http://192.168.99.168:80/api/v2/powermeter\"\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":460,"y":1320,"wires":[["4b7c72c4088338cb"]]},{"id":"b918447f5f8ce9a4","type":"debug","z":"65840aa926d9c567","name":"GET Powermeter","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":870,"y":1320,"wires":[]},{"id":"06440a35d73da0c4","type":"comment","z":"65840aa926d9c567","name":"GET Powermeter","info":"","x":140,"y":1320,"wires":[]},{"id":"2e7446e7fb79d335","type":"server-state-changed","z":"65840aa926d9c567","name":"Deferrable0 (Pool Pump) on ","server":"afc27684.cf6ed8","version":4,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"sensor.p_deferrable0","entityidfiltertype":"exact","outputinitially":false,"state_type":"num","haltifstate":"1","halt_if_type":"num","halt_if_compare":"gt","outputs":2,"output_only_on_state_change":true,"for":"","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"}],"x":320,"y":1740,"wires":[["d4b6ad2504c7d89f"],[]]},{"id":"d872f1ac6aa60d6f","type":"api-call-service","z":"65840aa926d9c567","name":"Switch Pump off","server":"afc27684.cf6ed8","version":5,"debugenabled":false,"domain":"switch","service":"turn_off","areaId":[],"deviceId":[],"entityId":["switch.garage_power_point_l2"],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"Off","valueType":"str"}],"queue":"none","x":620,"y":1820,"wires":[["99ec6f9f22c1bad7"]]},{"id":"99ec6f9f22c1bad7","type":"api-call-service","z":"65840aa926d9c567","name":"Notify Robert's iPhone","server":"afc27684.cf6ed8","version":5,"debugenabled":false,"domain":"notify","service":"mobile_app_robsiphone","areaId":[],"deviceId":[],"entityId":[],"data":"{\"message\":\"Pool pump has been switched off\",\"title\":\"Pool Pump\",\"data\":{\"subtitle\":\"Switch\",\"push\":{\"sound\":\"Descent.caf\"}}}","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":860,"y":1820,"wires":[[]]},{"id":"d4b6ad2504c7d89f","type":"api-call-service","z":"65840aa926d9c567","name":"Switch Pump on","server":"afc27684.cf6ed8","version":5,"debugenabled":false,"domain":"switch","service":"turn_on","areaId":[],"deviceId":[],"entityId":["switch.garage_power_point_l2"],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":620,"y":1740,"wires":[["dcbb413614aa4146"]]},{"id":"dcbb413614aa4146","type":"api-call-service","z":"65840aa926d9c567","name":"Notify Robert's iPhone","server":"afc27684.cf6ed8","version":5,"debugenabled":false,"domain":"notify","service":"mobile_app_robsiphone","areaId":[],"deviceId":[],"entityId":[],"data":"{\"message\":\"Pool pump has been switched on\",\"title\":\"Pool Pump\",\"data\":{\"subtitle\":\"Switch\",\"push\":{\"sound\":\"Descent.caf\"}}}","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":860,"y":1740,"wires":[[]]},{"id":"3cf2e6149b60f7de","type":"comment","z":"65840aa926d9c567","name":"GET Operating mode","info":"","x":120,"y":900,"wires":[]},{"id":"a86fa3ecd00eed26","type":"server-state-changed","z":"65840aa926d9c567","name":"Deferrable0 (Pool Pump) off","server":"afc27684.cf6ed8","version":4,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"sensor.p_deferrable0","entityidfiltertype":"exact","outputinitially":false,"state_type":"num","haltifstate":"1","halt_if_type":"num","halt_if_compare":"lt","outputs":2,"output_only_on_state_change":true,"for":"","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"}],"x":320,"y":1820,"wires":[["d872f1ac6aa60d6f"],[]]},{"id":"702dc6566d4b5ead","type":"comment","z":"65840aa926d9c567","name":"Deferrable0 Load Pool Pump automation","info":"","x":540,"y":1680,"wires":[]},{"id":"570fa7a2f2fc0742","type":"api-call-service","z":"65840aa926d9c567","name":"Solcast Update Forecast","server":"afc27684.cf6ed8","version":5,"debugenabled":false,"domain":"solcast_solar","service":"update_forecasts","areaId":[],"deviceId":[],"entityId":[],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":690,"y":1540,"wires":[[]]},{"id":"d2aca8e46132c153","type":"inject","z":"65840aa926d9c567","name":"Run at 06:00","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"00 06 * * *","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":380,"y":1460,"wires":[["570fa7a2f2fc0742"]]},{"id":"c1c685f71ca35696","type":"inject","z":"65840aa926d9c567","name":"Run at 09:00","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"08 08 * * *","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":380,"y":1500,"wires":[["570fa7a2f2fc0742"]]},{"id":"7a45deafd13aa17f","type":"inject","z":"65840aa926d9c567","name":"Run at 15:00","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"00 15 * * *","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":380,"y":1580,"wires":[["570fa7a2f2fc0742"]]},{"id":"09c1c349d798e291","type":"inject","z":"65840aa926d9c567","name":"Run at 12:00","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"00 12 * * *","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":380,"y":1540,"wires":[["570fa7a2f2fc0742"]]},{"id":"82da1cba425d4240","type":"inject","z":"65840aa926d9c567","name":"Run at 18:00","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"00 18 * * *","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":380,"y":1620,"wires":[["570fa7a2f2fc0742"]]},{"id":"be4ca37b27f6e061","type":"comment","z":"65840aa926d9c567","name":"Solcast access using Oziee HACS","info":"","x":568.25390625,"y":1411.01171875,"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}]

I use oziee ha-solcast-solar HACS to retrieve my solar PV forecast. One of the flows above calls this HACS 5 times a day to update the solar data. You only get 10 API calls a day to solcast if you’re new to them.

So ive got all the Integrations except EMHASS as i cant find it and no clue how to put this in. But im not worried about this. I wanted to implement the Red node correct, Did you have to use a webhook to create the initial call for charge/discharge?

I have started my flow but looking at yours it doesnt have a webhook start?

No, not using webhooks just REST API.

The way it works is:
The node on the left named “p_batt_forecast level” is the sensor published by EMHASS with what the battery should be doing, charge, discharge or standby. The sensor contains a number between the max input to the battery to the max output of the battery. In my case -3300w to 3300w (negative meaning charge and pos meaing discharge and 0 meaning standby).


When p_batt_forecast changes the blue “events state” node send the desired battery state to the switch node which switches it between these three states and onto the appropriate sequence of REST API calls to achieve the desired state.

So. for example, less than zero (charge) causes three API calls

  1. first put the battery into 0% backup buffer (the top one)
  2. 1 second later put the battery into manual mode
  3. 2 seconds later charge at the wattage number passed through (see below)

So 3 above is passing the charge wattage (which is a negative number) through to the battery.

The charge setup node is a function node with the above code in it. This code sets up a java object with the desired info to pass to the battery. line 2 in the code is turning the negative number from EMHASS into a positive number (the watts to charge the battery at).
I’ve blacked out my auth token as that gives access to my battery. The IP address will have to be changed to your IP address. The java object with all the info for the POST call is then passed to a http request node witch is the node that actually contacts the battery with the API call application info.

image

Of cause if you don’t want to implement EMHASS yet but just what the buttons:


So you can manually control the bat then the blue switch nodes are what you want. buttons above are linked to the blue switch nodes on the left below. They simply call the sequence of REST API calls to carry out each action. The blue “call service” nodes on the right simply turn the switch off (turning the switch off removes the yellow highlight you can see above on the “EMHASS control” button, doesn’t do anything else).

EMHASS is an add-on found in github GitHub - davidusb-geek/emhass: emhass: Energy Management for Home Assistant, is a Python module designed to optimize your home energy interfacing with Home Assistant..

I think you missing the point.

My standard configuration after linking my Sonnen to home assist does not have any config changing. i have no option to configure a charge or discharge. No existance of this. Ive tried everything. im now currently attempting to use node red to webhook the api web address from the software intergration and its not letting me send a “post” request to the api service to change the status of the battery.

All my entitis when i uploaded the sonnen hacs intergration provided is status readings only.

No thats whats in the node-red flow I posed above. weltmeyer HACS doesn’t implement any controls over a battery, only reads the various paramaters into sensors. Which BTW you can do yourseld using REST API GET commands.

Im gonna be honest. I have no idea what any of that is, or how to put that into red node

The flows in node-red can be exported and imported. What’s pasted in the responce above is a couple of flows that implements control over a battery via API (and interface a battry with EMHASS). You can copy the text and past it into your node-red by pressing ctrl-i or selecting ‘import’ from the hamburger menu in top right.
image
But you’ll have to modify the imported flow to work in your envirnment as it will reference my environment. So it takes a bit of getting used to.

HAHA, your the best!! ok now the thing im stuck on and i keep getting autharisation code 401

ive put this in to the url and i cant get past it. and im sure its wrong as ive tried all of them

http://192.168.0.173:80/api/v2/latestdata?api_key=(mykey)