Sonnenbatterie with APIv2 / Webhook

I do have currently the same issue and would like to set discharge to 0 value with a CURL.
But I am not succesfull at all and have no Idea how to use this API correct. I am using a Platform based on PERL and in API Version 1 my curl command worked fine.
Sonnen support did not answer yet and the they provide no example in the API doc.
Could you maybe give me any idea how this technically can be handled ?

@Roli1 it took me a while to figure out. First you need to set it to manual mode then send it a discharge rate of 0. I use HA to create switches and rates then I use Node Red to construct the Urlā€™s. Have you enabled the JSON local API?
I have created the curl below, took me a while to get it right:

curl -H 'Auth-Token: 1234567790xxxxxxxxx' -H 'Content-Type: application/x-www-form-urlencoded' -X POST "http://192.168.xx.xx:80/api/v2/setpoint/discharge/0" -d ''

put in your token number, IP address and the zero can be replaced with what ever discharge rate you need.

Loads of useful info here, and Iā€™ve gotten the data from the battery into the HA energy tab and also managed to get the Node Red commands to change the operation mode of the battery from reading through. Has anyone been able to set a TOU schedule this way?

Iā€™ve tried copying the nodes from the examples here to try and send info using ā€˜EM_ToU_Scheduleā€™ and some information from a German forum which gives a format of:

{ā€œEM_ToU_Scheduleā€:"[{ā€œstartā€:ā€œ22:00ā€,ā€œstopā€:ā€œ03:00ā€,ā€œthreshold_p_maxā€:500} ,{ā€œstartā€:ā€œ20:00ā€,ā€œstopā€:ā€œ22:00ā€,ā€œthreshold_p_maxā€:0}]"}

But I donā€™t really know what Iā€™m doing and I think my attempt at JSON is probably gibberish. :crazy_face:

I didnā€™t bother with it as its a bit of work. Might be easier if you want it, create the schedule in the battery then turn between automatic and TOU mode via HA. Although if you have the buttons working then you can do all that within HA and node red via an automation.

2 Likes

Iā€™m hoping to leave it on ToU but vary the charging amount in the Octopus Go window. So donā€™t discharge in that window (to stop the battery charge being dumped into my car if itā€™s plugged in) and then if thereā€™s not likely to be sun the next day then charge the battery fully, if itā€™s likely to be a bit sunny then half charge it and if itā€™s going to be full sun then donā€™t charge at all. Got a few days off over the holiday period so Iā€™ll see if I can teach myself enough to make it work!

That is exactly what Iā€™m doing now with my battery. I figure out how much solar there will be over time periods of the day versus house needs, then make up the difference. The car one is WIP as I found the myenergi API very slow to respond but good enough.

So I got as far as figuring out a way to set the value to charge at overnight in the front end and then send it via a switch, by heavily borrowing from the work above. Setting the times as well alluded me, mostly because the Octopus Go window is fixed so I wasnā€™t very motivated to figure out formating the times into something workable in the time that I had today. (Maybe Iā€™ll come back to that another time, but ideally I want to get something working with the solar forecast to automatically pick a charge rate for the battery after sunset each day.)

Hopefully this is formatted so that it can be imported in case someone else would find it usefulā€¦

[{"id":"e3d838c12c8b1eaa","type":"api-current-state","z":"6c4d4ceb2f682dd2","name":"ToU Charge Rate","server":"10c30ee8.cda2b1","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"input_number.tou_charge_rate","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"charge_rate","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":410,"y":140,"wires":[["9c248a8040ab9dd8"]]},{"id":"0dc79320d5d2bab1","type":"server-state-changed","z":"6c4d4ceb2f682dd2","name":"Switch TOU Power","server":"10c30ee8.cda2b1","version":4,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"switch.sonnen_tou_power","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"on","halt_if_type":"str","halt_if_compare":"is","outputs":2,"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"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":170,"y":200,"wires":[["ca0080b4a3377aa4","9c248a8040ab9dd8","e3d838c12c8b1eaa"],[]]},{"id":"ca0080b4a3377aa4","type":"delay","z":"6c4d4ceb2f682dd2","name":"","pauseType":"delay","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":380,"y":240,"wires":[["b133ad8685e5a265"]]},{"id":"b133ad8685e5a265","type":"api-call-service","z":"6c4d4ceb2f682dd2","name":"","server":"b9e4497071b772c2","version":5,"debugenabled":false,"domain":"switch","service":"turn_off","areaId":[],"deviceId":[],"entityId":["switch.sonnen_tou_power"],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":560,"y":240,"wires":[[]]},{"id":"9c248a8040ab9dd8","type":"function","z":"6c4d4ceb2f682dd2","name":"TOU Power","func":"msg.payload = { \"EM_ToU_Schedule\": \"[{\\\"start\\\":\\\"00:30\\\",\\\"stop\\\":\\\"04:30\\\",\\\"threshold_p_max\\\":\" + msg.charge_rate + \"}]\" }\nmsg.headers = {}\nmsg.headers['Auth-Token'] = 'YOUR_TOKEN'\nmsg.headers[\"Content-Type\"] = \"application/x-www-form-urlencoded\"\nmsg.url = \"http://YOUR_IP':80/api/v2/configurations\"\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":670,"y":180,"wires":[["d3a7fa5adc2498b9"]]},{"id":"d3a7fa5adc2498b9","type":"http request","z":"6c4d4ceb2f682dd2","name":"Set State","method":"PUT","ret":"obj","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"bearer","senderr":false,"headers":[],"x":820,"y":180,"wires":[["69a6265de8e6775d"]]},{"id":"69a6265de8e6775d","type":"debug","z":"6c4d4ceb2f682dd2","name":"debug 7","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":960,"y":180,"wires":[]},{"id":"10c30ee8.cda2b1","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":"b9e4497071b772c2","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}]

Hi,
I succeeded to control the charging/discharging manually via curl sending
curl -d ā€œā€ -X POST --header ā€˜Auth-Token: TOKENā€™ http://IP_ADRESS:80/api/v2/setpoint/charge/1000
or alternatively
curl -d -H -X POST --header ā€˜Auth-Token: TOKENā€™ http://IP_ADRESS:80/api/v2/setpoint/charge/1000
Oddly, even setting the charge when the operating mode is Self-Consumption, the setpoint charge will be enforced for a few seconds. Self-Consumption behaviour is however resumed automatically.

The PAC_total split is actually what I was just looking for and feared I have to do it myself. Iā€™ll have a look and check if I can make this work! Thanks!

1 Like

Iā€™m now starting the investigation on ToU mode to plan charging at night if I foresee the next day I wonā€™t produce power enough. So to stay on the safest side I was thinking to control the battery parameters to mimic what I would do through the interface, which means rely on the PUT configurations call and change EM_OperatingMode from 2 (self-consumption) to 10 (ToU) and maybe update the EM_ToU_Schedule (or, if too difficult to set through command because of the syntax, set it once through the interface and rely on that, as I see it is kept in memory). And then just control EM_OperatingMode parameter.
What are your experiences on that?

But I also see that it would be possible to revert back to self-consumption after sending a charge command:

This could be a good alternative to simplify the management. The fact is that the documentation is quite essential and I would like to understand how I can do that first.

@donoghdb @chrism751 how are you reverting the system to self-consumption, after you send a charge command? Which parameters get modified following this command and have to be controlled to revert? Do you maybe set EM_OperatingMode to 1 (along with the API command) and then back to 2?
Is anybody else doing this?

Thank you all for your comments and/or sharing your experiences

I did some testing by changing the settings from the interface. When you set ToU EM_ToU_Schedule is changed from 2 (self-consumption) to 10. Then you can set the schedules for the battery to be charged. What you found on the German forum is correct. From what I see you can set as many non-overlapping time windows as you want (within 24h limit of course) for the battery to be charged with a defined maximum power absorption. It seems the ā€œscheduleā€ is retained in memory when you revert to self-consumption.

EM_ToU_Schedule: [{"start":"09:00","stop":"12:00","threshold_p_max":2000},{"start":"12:00","stop":"14:00","threshold_p_max":2000}]

What is not clear to me is how can the interface allow me to set the max absorption to values that are higher than the inverter max power. Of course I would not exceed this (and default is 2000 W).

Just got my car charger installed and it comes with a Solar Charging mode where it will only start charging when power is being exported to the grid. What I want to do but cant see any way yet, is tell the Sonnen to stop charging from the PV at a certain battery percentage. Currently, the Sonnen has to hit 100%, then the car will start charging from then on. Turning it to manual mode then setting a 0 charge only effects charging from the grid, not PV. Any ideas?

Thats how I do it. Set it to manual and a charge rate of 3600, then set it back to Automatic once the time window I get for free power is over. I re-inject the node every 10 minutes to keep the charge rate up or it slowly backs off and I dont get the most of the free power.

1 Like

Iā€™ve found that when Iā€™m charging my car and want to charge the battery at the same time, I have to set the max power absorption to include the amount that the car charger is drawing. So it seems like the max power is the max grid power including anything else going on in addition to the Sonnen charging.

This time of year I wouldnā€™t need to charge the battery though, as solar has been quite plentiful, so Iā€™ve not used ToU in a while. (Also my inverter is broken and it took a month to get a new one and that was possibly DoA, so I actually canā€™t use my Sonnen system at all right nowā€¦)

Wouldnā€™t this correspond to disabling the Solar charging mode on your car charger when the battery hits your desired percentage?

But at that point isnā€™t it the same as starting charging only when the battery hits the desired percentage (and you have grid export)? The charger should be seen by Sonnen like any other load you have in your house and battery charge managed accordingly.

Basically do not use the Solar charging mode at all?
Sorry if I missed something.

Hopefully, this is a better explanation of my system and plan:

  • 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. 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)

Is anybody using the sonnen API with the Amber integration data to take advantage of high feed-in tariffs by discharging the battery when the feed-in price descriptor spikes and inversly blocking feed in when it the price goes negative?

Does anyone know if thereā€™s a way to ā€˜clearā€™ the ToU schedule via the API?

Currently the cheap electricity times from my supplier are always 00:30-4:30, but in August I will switch to a new tariff where the car will be charged at different times on different days, controlled by the electricity supplier, so in order to stop the battery filling the car I will need to tell it not to discharge at different

I think you should be able to use EM_ToU_Schedule

e.g. to set

"EM_ToU_Schedule=[{"start":"09:00","stop":"12:00","threshold_p_max":2000}] 

you should be able to use the following node-red flow (if your a node-red users):

[{"id":"402679171d35e0d2","type":"http request","z":"65840aa926d9c567","name":"Set State","method":"PUT","ret":"obj","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"bearer","senderr":false,"headers":[],"x":1360,"y":340,"wires":[["5bd08bcd972153bc"]]},{"id":"9efde64dbc00c864","type":"function","z":"65840aa926d9c567","name":"Manual Mode","func":"msg.payload = \"EM_ToU_Schedule=[{"start":"09:00","stop":"12:00","threshold_p_max":2000}]\"\nmsg.headers = {}\nmsg.headers['Auth-Token'] = 'YOUR-AUTH-TOKEN'\nmsg.headers [\"Content-Type\"] = \"application/x-www-form-urlencoded\"\nmsg.url = \"http://SYSTEM-IP:80/api/v2/configurations\" \nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1180,"y":340,"wires":[["402679171d35e0d2"]]}]

or:

curl -X PUT -d EM_ToU_Schedule=[{"start":"09:00","stop":"12:00","threshold_p_max":2000}] -d NVM_PfcIsFixedCosPhiActive=0 --header 'Auth-Token: TOKEN' http://SYSTEM-IP/api/v2/configurations`

Donā€™t forget to incert your Auth Token and change the SYSTEM-IP address to your batteryā€™s address. Iā€™ve not tested this.

1 Like

Robert
you appear to be in a similar situation with me. Amber customer and Sonnen battery. I am currently in a 4 way discussion with Amber, SAE (solar installers), SMA (my 3 inverters) and Sonnen.
I would have thought with a 15Kw solar array and a 10Kw battery I should not have to pay for power. I just have lots of wasted power in the day with no way of really controlling when my battery connects to the grid or not.
Pat