Custom Integration: Sonnenbatterie

Here is the information to make sensors for us in the energy dashboard: HA Energy Dashboard · Issue #14 · weltmeyer/ha_sonnenbatterie · GitHub

Great tip, worked for me!

Hi again, can you help me, I can’t integrate or convert the data into kwh and integrate it into the energy panel.
Thank you

Good morning, after several attempts and studies I managed to set everything up. Now let’s see if everything works perfectly.

Hi, someone can share the code of integration of sonnen batterie?
Everyting i tryed doesen’t worked properly.
I would use the energy dashboard but in the most of the case that i tryed i can’t saw the sensors.
Thanks

The explanation is here: HA Energy Dashboard · Issue #14 · weltmeyer/ha_sonnenbatterie · GitHub

Either edit your configuration.yaml files and add the following under the sensor section:

sensor:
  - platform: integration 
    source: sensor.sonnenbatterie_XXXXX_meter_consumption_4_2_w_total 
    name: PowerConsumption
    round: 3
    unit_prefix: k
    unit_time: h
    method: left

  - platform: integration
    source: sensor.sonnenbatterie_XXXXX_meter_production_4_1_w_total
    name: PowerProduction
    round: 3
    unit_prefix: k
    unit_time: h
    method: left

  - platform: integration 
    source: sensor.sonnenbatterie_XXXXX_state_grid_input
    name: GridInput
    round: 3
    unit_prefix: k
    unit_time: h
    method: left

  - platform: integration 
    source: sensor.sonnenbatterie_XXXXX_state_grid_output
    name: GridOutput
    round: 3
    unit_prefix: k
    unit_time: h
    method: left

  - platform: integration 
    source: sensor.sonnenbatterie_XXXXX_state_battery_input
    name: BatteryInput
    round: 3
    unit_prefix: k
    unit_time: h
    method: left

  - platform: integration 
    source: sensor.sonnenbatterie_XXXXX_state_battery_output
    name: BatteryOutput
    round: 3
    unit_prefix: k
    unit_time: h
    method: left

Replace the XXXXX with your battery serial number. Look for the Sonnen sensors created by Sonnenbatterie HACS in Developer Tools , States (just search for sonnen). These are the sources to use.

Alternatively (and probably preferably) set these sensors up in Helpers (use this link Link to Integrations: Add integration – My Home Assistant ). This is the more recent way to set up an ‘Integration’ sensor.

I have been playing on and off with this integration. Mucho thanks to many of you who are unaware how much help you’ve already been.

However, there is still something I am struggling with.
WHEN there is a power outage - pretty common where I live - the house happily carries on running (without anybody in the house being aware the very finite battery is running down fast)

I used to have a python script that was a simple loop, and would poll the api and retrieve SystemStatus which is either OnGrid, Grid Status Pending or OffGrid. (at least these were the values I uncovered)
Then, if it stayed in this OffGrid state for more than a minute it would send me a Telegram Message. It worked - but not neat. Nomanagement, no dashboard etc.

I built a version in node-red, but I am looking to do the same but within the HA framework.

When I look at @weltmeyer code, I don’t see the SystemStatus field being captured.
I had hoped that sensor.sonnenbatterie_nnnnn would be sufficient, but this is very chatting as the battery goes between charging and discharging and standby. It isn’t quite what I am looking for.

Am I missing the entity?
Or how would I adapt the original code to add SystemStatus?

I added a sensor for SystemStatus on latest version:


just update :slight_smile:
Here is how its done: Add Systemstatus Sensor · weltmeyer/ha_sonnenbatterie@e1a0809 · GitHub

1 Like

Please help me make flow for manual discharge 1000w and manual charge 1000w
I can switch from manual to auto-self use
I can change from auto-self use to manual but the charge or discarge stay the same as in auto at the moment.
I have sonnencore+

Thank you


this is instruction from inverter for put and it works as instructed above

[{"id":"8b451feac09c6968","type":"http request","z":"905cb3bda191e36b","name":"Status Request","method":"GET","ret":"obj","paytoqs":"body","url":"http://192.168.1.55/api/v2/status","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[],"x":440,"y":300,"wires":[["7bfafa67f301d268"]]},{"id":"b72006dede4a9cfa","type":"inject","z":"905cb3bda191e36b","name":"set_manual_if_auto","props":[],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":200,"y":300,"wires":[["8b451feac09c6968"]]},{"id":"7bfafa67f301d268","type":"switch","z":"905cb3bda191e36b","name":"Auto?","property":"payload.OperatingMode","propertyType":"msg","rules":[{"t":"eq","v":"2","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":590,"y":300,"wires":[["e6627ee7a09460bc"]]},{"id":"9d2c8238b9479dfa","type":"http request","z":"905cb3bda191e36b","name":"Set Manual","method":"PUT","ret":"obj","paytoqs":"ignore","url":"http://192.168.1.55/api/v2/configurations","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"bearer","senderr":false,"headers":[],"credentials":{"user":"","password":""},"x":592,"y":354,"wires":[["f647c176bb65c26c"]]},{"id":"e6627ee7a09460bc","type":"function","z":"905cb3bda191e36b","name":"API-Nyckel TOU 10","func":"msg.payload = \"EM_OperatingMode=1\"\nmsg.headers = {}\nmsg.headers['Auth-Token'] = '5a61c845-79d8-4a9b-a149-2bc2c1babec7'\nmsg.headers [\"Content-Type\"] = \"application/x-www-form-urlencoded\"\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":396,"y":354,"wires":[["9d2c8238b9479dfa"]]},{"id":"f647c176bb65c26c","type":"debug","z":"905cb3bda191e36b","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":772,"y":354,"wires":[]}]

this is instruction from inverter for post the discharge wattage

and my implementation of node red flow that does not work

[{"id":"dcf72bf2f1dc306f","type":"http request","z":"905cb3bda191e36b","name":"Status Request","method":"GET","ret":"obj","paytoqs":"body","url":"http://192.168.1.55/api/v2/status","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[],"x":440,"y":480,"wires":[["87bcfaa51d752411"]]},{"id":"c616cb50e3f013e5","type":"inject","z":"905cb3bda191e36b","name":"Paus","props":[],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":160,"y":480,"wires":[["dcf72bf2f1dc306f"]]},{"id":"87bcfaa51d752411","type":"switch","z":"905cb3bda191e36b","name":"Manual?","property":"payload.OperatingMode","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":600,"y":480,"wires":[["a4416f6395e5ca12"]]},{"id":"897a4830c2cbfc78","type":"http request","z":"905cb3bda191e36b","name":"setpoint","method":"POST","ret":"obj","paytoqs":"ignore","url":"http://192.168.1.55/api/v2/setpoint/discharge","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"bearer","senderr":false,"headers":[],"x":582,"y":534,"wires":[["90072c2b3468d0b7"]]},{"id":"a4416f6395e5ca12","type":"function","z":"905cb3bda191e36b","name":"API-Nyckel TOU 10","func":"msg.payload = \"1000\"\nmsg.headers = {}\nmsg.headers['Auth-Token'] = '5a61c845-79d8-4a9b-a149-2bc2c1babec7'\nmsg.headers [\"Content-Type\"] = \"application/x-www-form-urlencoded\"\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":396,"y":534,"wires":[["897a4830c2cbfc78"]]},{"id":"90072c2b3468d0b7","type":"debug","z":"905cb3bda191e36b","name":"","active":false,"tosidebar":true,"console":true,"tostatus":true,"complete":"true","targetType":"full","statusVal":"payload","statusType":"auto","x":772,"y":534,"wires":[]}]

I cant make it work
Please help
Borut

Hello.
we have got a sonnenbatterie 8.0 with a sonnenHeater installed. The sonnenHeater takes the energy that is left - after the battery is full - and heats our water buffer tank (for hot water and underfloor heating). The sonnenHeater is controlled by the sonnenbattery via modbus, but without an explicit IP address.

Here is what I’d like to do:

My problem with the first step is, that the two values are not readable via the API, only over the portal of sonnen (sonnen Customer Portal).
Therefor you have to login first via sonnenID, then a token is created, which can then be used in the query on the above website.
The query works, when I login to the website via webbrowser first and then use the created token in the query in HA:

 - resource: https://my-api.sonnen.de/v1/sites/pNab8MhUTyqHiAjaVHhhUsobQ11pO9rJyAw5UaRZelQ/live-state
    method: GET
    headers:
      User-Agent: Home Assistant
      Content-Type: application/json
    scan_interval: 60
    timeout: 15
    sensor:
      - name: heater_water_temp
        value_template: '{{ value_json["heater_water_temp"] }}'
        unit_of_measurement: '°C'
        device_class: temperature
      - name: heater_power
        value_template: '{{ value_json["heater_power"] }}'
        unit_of_measurement: 'W'
        device_class: power

Can anyone help me on this or point me in the right direction?
How can I manage to login on the login page, save the created token for the query on the actual value page all in HA?

For the second step I have been asking the sonnen-service, but their answers did not match to my question … :-((
Any help, ideas, etc. are appreciated.
Thanks

Anyone ?
I’d like to do the login on the login page and then use the created session-token for the query on the then accessable value page?

A hint for all Smart E-Grid users in Belgium:

Your sonnnenbatterie is installed with its UTP connection wired to the Smart E-Grid controller (with a usb->eth dongle) which on its turn connects through UTP to your main LAN.
The Sonnen app and webpage are tunnelled over a VPN connection, however you cannot access the battery anymore in Home Assistant (since an interface modification in November 2022).

Instead, you can directly connect your battery to main LAN and then connect to it using the regular procedure listed above. The Smart E-grid controller will still operate the battery and manage peak shaving and net imbalance corrections.

Finally after 6 months it helped me to get my HA setup working again :slight_smile:

2 Likes

Did you check if these values are visible when logging in to you batterie directly?

Hello weltmeyer,
thanks for your reply. I checked it with the user-login, but the info is not there, only in the portal of sonnen, which is kind of weared, because the information comes from my sonnen battery …

Hi weltmeyer,

I installed your integration via HACS and then wanted to do the configuration. Unfortunately, the configuration is not loaded. Do you perhaps know what that is?

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