Skip to main content

"Access Sonnenbatterie REST API"

Project description

python_sonnenbatterie

Python module to access the REST API of a Sonnenbatterie.

This modules contains two distinct sets of APIs:

  • the original sonnen API (v1)
  • the new v2 API

Both are available in a synchronous and an asynchronous version:

  • sonnenbatterie - SonnenAPI v1, synchronous
  • AsyncSonnenBatterie - SonnenAPI v1, asynchronous
  • SonnenBatterieV2 - SonnenAPI v2, synchronous
  • AsyncSonnenBatterieV2 - SonnenAPI v2, asynchronous

The major difference between those two is the method to authenticate. With API v1 you need to login using a username and a password. The newer API requires a token that can be found in the web UI of your Sonnenbatterie. Also, the v2 API provides a unified view across the different Sonnenbatterie models wheres the v1 API may provide more details in specific setups.

When using the v1 API you'll autmatically get access to the v2 API by using the sb2 attribute of the v1 client object.

Installation

Using pip

pip3 install sonnenbatterie

Manual installation

Download the archive from pypi.org and unpack where needed ;)

Usage

SonnenAPI v1 - sync

# API v1
from sonnenbatterie import sonnenbatterie

sb_host = '192.168.1.2'
sb_user = 'User'
sb_pass = 'Password'

# Init class, establish connection
sb = sonnenbatterie(sb_host, sb_user, sb_pass)

print(sb.get_status())	        # retrieve general information
print(sb.get_powermeters())     # retrieive power meter details
print(sb.get_batterysystem())   # retrieve battery system data
print(sb.get_inverter())        # retrieve inverter status
print(sb.get_systemdata())      # retrieve system data
print(sb.get_battery())         # get battery information

SonnenAPI v1 - async

# API v1
from sonnenbatterie import AsyncSonnenBatterie

sb_host = '192.168.1.2'
sb_user = 'User'
sb_pass = 'Password'

# Init class, establish connection
sb = AsyncSonnenBatterie(sb_host, sb_user, sb_pass)

print(await sb.get_status())	      # retrieve general information
print(await sb.get_powermeters())     # retrieive power meter details
print(await sb.get_batterysystem())   # retrieve battery system data
print(await sb.get_inverter())        # retrieve inverter status
print(await sb.get_systemdata())      # retrieve system data
print(await sb.get_battery())         # get battery information

# Async needs to close the connection!
await sb.logout()

SonnenAPI v2 - sync

# API v2
# can either be access directly, see below, or
# via sb.sb2 (gets initialiazed automatically when creating a V1 object)

from sonnebatterie2 import SonnenBatterieV2

sb_host = '192.168.1.2'
sb_token = 'SeCrEtToKeN'        # retrieve via Web UI of SonnenBatterie

sb2 = SonnenBatterieV2(sb_host, sb_token)
print(sb2.get_configurations())         # retrieve configuration overview
print(sb2.get_battery_module_data())    # get battery module data
print(sb2.get_inverter_data())          # retrieve inverter data
print(sb2.get_latest_data())            # get latest date from sonnenbatterie
print(sb2.get_powermeter_data())        # get data from power meters
print(sb2.get_status())                 # get overall status information
print(sb2.get_io_data())                # get io status

SonnenAPI v2 - async

# API v2
# can either be access directly, see below, or
# via sb.sb2 (gets initialiazed automatically when creating a V1 object)

from sonnebatterie2 import AsyncSonnenBatterieV2

sb_host = '192.168.1.2'
sb_token = 'SeCrEtToKeN'        # retrieve via Web UI of SonnenBatterie

sb2 = AsyncSonnenBatterieV2(sb_host, sb_token)
print(await sb2.get_configurations())         # retrieve configuration overview
print(await sb2.get_battery_module_data())    # get battery module data
print(await sb2.get_inverter_data())          # retrieve inverter data
print(await sb2.get_latest_data())            # get latest date from sonnenbatterie
print(await sb2.get_powermeter_data())        # get data from power meters
print(await sb2.get_status())                 # get overall status information
print(await sb2.get_io_data())                # get io status
# Async needs to close the connection!
await sb.logout()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sonnenbatterie-0.5.2.tar.gz (30.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sonnenbatterie-0.5.2-py3-none-any.whl (25.5 kB view details)

Uploaded Python 3

File details

Details for the file sonnenbatterie-0.5.2.tar.gz.

File metadata

  • Download URL: sonnenbatterie-0.5.2.tar.gz
  • Upload date:
  • Size: 30.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.3

File hashes

Hashes for sonnenbatterie-0.5.2.tar.gz
Algorithm Hash digest
SHA256 39b19eeb1ee4aa3cc5e180a01511ca2a23374d0388216343152bf3a5a91da584
MD5 3b400b3fa5719d6121abb81eb7a5e1fc
BLAKE2b-256 234b24f87f7e625679ee5432891a9c68e554e393167b0984f0159a3344088cac

See more details on using hashes here.

File details

Details for the file sonnenbatterie-0.5.2-py3-none-any.whl.

File metadata

  • Download URL: sonnenbatterie-0.5.2-py3-none-any.whl
  • Upload date:
  • Size: 25.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.3

File hashes

Hashes for sonnenbatterie-0.5.2-py3-none-any.whl
Algorithm Hash digest
SHA256 245bddc50b0e9aeada039d546006eaccef5b8d4279a7238d48a448fd7562e6f6
MD5 4c3b94fd3d33cc098f59f559cffd4f4c
BLAKE2b-256 852d152002eb78e7f618b5670dc995e8cbf7fb55350b808f29ff4bce9f2c3e01

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page