Sonnenbatterie with APIv2 / Webhook

sonnen battery is manageable via RESTful API. So you can use the Home Assistant RESTful Command to send commands to the battery to charge or discharge at whatever rate you want.

Alternatively you can do the same thing with Node-Red by using the http request node.

In either case to change the battery charge/discharge rate requires a PUT command after the battery has been put in manual mode (which can also be done with a RESTful command).

Example:


These two flows put the battery into manual mode and then pass a number in Watts to charge the battery.
Here’s the JSON code for these two flows:

[{"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)\n// Increase pospayload by 100 if it is between 200 and 2500\nif (pospayload >= 200 && pospayload <= 2500) \n{\n    pospayload += 100;\n}\nmsg.headers = {}\nmsg.headers['Auth-Token'] = 'YOUR-SONNEN-AUTH-TOKEN'\nmsg.headers [\"Content-Type\"] = \"application/x-www-form-urlencoded\"\nmsg.url = \"http://192.168.1.70:80/api/v2/setpoint/charge/\" + pospayload.toString()\nreturn msg;","outputs":1,"timeout":"","noerr":0,"initialize":"","finalize":"","libs":[],"x":1080,"y":340,"wires":[["f8c8624c7c9dca94"]]},{"id":"0e3f0373d7e81e09","type":"debug","z":"65840aa926d9c567","name":"debug Charge","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1440,"y":340,"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-AUTH-TOKEN'\nmsg.headers [\"Content-Type\"] = \"application/x-www-form-urlencoded\"\nmsg.url = \"http://192.168.1.70: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":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1460,"y":280,"wires":[]},{"id":"4b6455180cf0d210","type":"delay","z":"65840aa926d9c567","name":"4 sec","pauseType":"delay","timeout":"4","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":"93beed478696134e","type":"link in","z":"65840aa926d9c567","name":"link in Charge Setup","links":["8f6da85cea51a6c2","63ba9e6850f7361b","95976ebe7f6655d3","cc0a6d9606abe439","cba7fee3cee79393","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","cba7fee3cee79393","b42b8c412b6200e7"],"x":835,"y":280,"wires":[["e8a2ee908ef64a78"]]},{"id":"e8a2ee908ef64a78","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":280,"wires":[["9efde64dbc00c864"]]}]

You should be able to import this JSON into you Node-Red instance and work with it. Remember to replace the AUTH-TOKEN with your battery AUTH-TOKEN which can be found here on your battery (assume it’s IP address is 192.168.1.70.

Now to decide what rate to charge or discharge I use EMHASS. My config for EMHASS is located here.

1 Like