# Sonnen sonnenBatterie

Source: https://docs.evcc.io/en/meters/sonnen-sonnenbatterie

For active battery control, the "JSON Write API" must be activated via the sonnenBatterie web interface (under Software-Integration) and the API token generated there must be entered in the battery configuration under `token`.
The two operating modes supported for the sonnenBatterie are "self-consumption" (default) and "time-of-use". The mode can be adapted to the configuration of the sonnenBatterie via the 'defaultmode' parameter.
The power for grid charging can be adapted to the inverter power of the sonnenBatterie via the `maxchargepower` parameter.

Supported features: battery-control

## Parameters

| Name | Description | Default / example | |
| --- | --- | --- | --- |
| host | IP address or hostname | 192.0.2.2 |  |
| defaultmode | Default mode for battery control Inverter falls back to this mode after charging the battery or after stopping discharge. (self-consumption, time-of-use) | self-consumption |  |
| port | Port | 8080 |  |
| capacity | Battery capacity | 50 kWh |  |
| minsoc | Minimum charge Lower limit as configured on the battery system. Used by optimizer. | 0 % |  |
| maxsoc | Maximum charge Upper limit as configured on the battery system. Used by optimizer and for grid charging. | 100 % |  |
| token | Token API Token (required for active battery control) |  |  |
| maxchargepower | Maximum charge power For forced charging of the battery. | 3300 W | advanced |
| maxdischargepower | Maximum discharge power Maximum discharge power of the storage. |  W | advanced |
| cache | Cache Time interval for data refresh | 1s | advanced |

## Configuration example for evcc.yaml

```yaml
meters:
    - name: my_grid
      type: template
      template: sonnenbatterie
      usage: grid
      host: 192.0.2.2 # IP address or hostname
      port: 8080 # Port, optional
      cache: 1s # Cache, Time interval for data refresh (optional)
```

```yaml
meters:
    - name: my_pv
      type: template
      template: sonnenbatterie
      usage: pv
      host: 192.0.2.2 # IP address or hostname
      port: 8080 # Port, optional
      cache: 1s # Cache, Time interval for data refresh (optional)
```

```yaml
meters:
    - name: my_battery
      type: template
      template: sonnenbatterie
      usage: battery
      host: 192.0.2.2 # IP address or hostname
      defaultmode: self-consumption # Default mode for battery control, Inverter falls back to this mode after charging the battery or after stopping discharge. [self-consumption, time-of-use]
      port: 8080 # Port, optional
      capacity: 50 # Battery capacity (kWh), optional
      minsoc: 0 # Minimum charge (%), Lower limit as configured on the battery system. Used by optimizer. (optional)
      maxsoc: 100 # Maximum charge (%), Upper limit as configured on the battery system. Used by optimizer and for grid charging. (optional)
      token: # Token, API Token (required for active battery control) (optional)
      maxchargepower: 3300 # Maximum charge power (W), For forced charging of the battery. (optional)
      maxdischargepower: # Maximum discharge power (W), Maximum discharge power of the storage. (optional)
      cache: 1s # Cache, Time interval for data refresh (optional)
```
