A library to interact with Sungrow's iSolarCloud API
Project description
pysolarcloud
A Python package to interact with the iSolarCloud API by Sungrow.
The package supports the following functionality:
- OAuth2 authentication
- Getting a list plants
- Getting details of a plant
- Getting devices of a plant
- Getting "real-time" data of a plant (Data is updated every 5 minutes according to Sungrow's documentation)
- Getting historical data
- Getting and updating grid control settings
Quirks
The iSolarCloud API is quite new and not very mature. Some tips:
- The authorisation flow is based on OAuth2 but doesn't work exactly as you would expect
- The
stateparameter is not passed back after to the authorisation step. This makes it more tricky to resume the flow in a client application. - User is asked to approve the authorisation if the flow is invoked again, e.g. in case the tokens have expired - unlike many OAuth2 implementations who will perform a "silent" authorisation if the user has already approved the access.
- The API documentation lists a lot of data points which do not seem to be returned from my inverter, it probably varies between models.
- There are different iSolarCloud servers for different regions, see the
pysolarcloud.Serverenum - API endpoints accept a language code but respond with Chinese text when when English is requested
Usage
Installation
pip install pysolarcloud
Register your app
- Create an account in the iSolarCloud Developer Portal
- Create an app in the developer portal
- Answer "Yes" to authorize with OAuth2.0
- Enter a Redirect URL for your app (this can be changed later)
- Wait for approval by Sungrow
- Find the needed configuration details in the developer portal. You will need:
- Appkey
- Secret Key
- Application Id (This is shown as a query parameter within the Authorize URL in the developer portal)
Example
from pysolarcloud import Auth, Server
from pysolarcloud.plants import Plants
app_key = "your app key"
secret_key = "your secret key"
app_id = "your app id"
redirect_uri = "your redirect uri"
auth = Auth(Server.Europe, app_key, secret_key, app_id)
url = Auth.auth_url(redirect_uri)
- Redirect user to
url - User selects plant(s) and grants authorisation
- iSolarCloud will redirect the user to
redirect_uriwith query parametercode
await auth.async_authorize(code, redirect_uri)
plants_api = Plants(auth)
plant_list = await plants_api.async_get_plants()
The Auth class keeps the access between calls and refreshes it when needed. If you prefer to manage this state yourself, you can create your own subclass of AbstractAuth.
Grid Control
The Control class enables retrieving and updating grid control settings. Parameters and value sets are documented in the iSolarCloud Developer portal.
Example
from pysolarcloud.control import Control
devices = await plants_api.async_get_plant_devices(plant_id, device_types=[DeviceType.ENERGY_STORAGE_SYSTEM])
device_uuid = devices[0]["uuid"]
control_api = Control(auth)
# Fetch current config
current_settings = await control_api.async_read_parameters(device_uuid)
print(current_settings)
# Make an update
await control_api.async_update_parameters(device_uuid, { "charge_discharge_command": "Charge" })
Contributions
Ideas or contributions are welcome. I am not afiliated with Sungrow, I'm just another user of the API. My main use case will be a HomeAssistant integration based on this package.
Enjoy!
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pysolarcloud-0.4.0.tar.gz.
File metadata
- Download URL: pysolarcloud-0.4.0.tar.gz
- Upload date:
- Size: 12.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7f861f5b77b1b976bb6090d98f9db0b12068307a33e069e31b5e27d17597660e
|
|
| MD5 |
66ced4492aeb532956855566650de189
|
|
| BLAKE2b-256 |
55a99b63297ab2b17a49e8f82dc387aec15ed6cd3628cef5ba92b9ce7946f67c
|
File details
Details for the file pysolarcloud-0.4.0-py3-none-any.whl.
File metadata
- Download URL: pysolarcloud-0.4.0-py3-none-any.whl
- Upload date:
- Size: 11.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e29e5f89cb7770be4c790de55c75c6f23569b437c2fa2d562353dbbb8cb90b20
|
|
| MD5 |
96da8865018cb53adfdfa13c7bb35b09
|
|
| BLAKE2b-256 |
aa9e64ffb048f485bdef15697676e2142bb3927c8082c8490f6f5eeeb375facd
|