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 authorisation page is a single-page application. To have the OAuth2
stateparameter returned, it must be placed in the URL query before the#;Auth.auth_url(..., state=...)handles this layout. - 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"
state = "an opaque value used to resume your flow"
auth = Auth(Server.Europe, app_key, secret_key, app_id)
url = auth.auth_url(redirect_uri, state=state)
- Redirect user to
url - User selects plant(s) and grants authorisation
- iSolarCloud will redirect the user to
redirect_uriwith query parameterscodeandstate
await auth.async_authorize(code, redirect_uri)
plants_api = Plants(auth)
plant_list = await plants_api.async_get_plants()
if plant_list:
print(f"{len(plant_list)} plants found:")
for plant in plant_list:
print(f"Plant ID: {plant["ps_id"]}, Name: {plant["ps_name"]}")
else:
print("No plants found.")
return
print("\nFetching detailed information for each plant...\n")
plant_ids = [str(plant["ps_id"]) for plant in plant_list]
plant_details = await plants_api.async_get_plant_details(plant_ids)
for plant in plant_details:
print(f"Details for Plant ID {plant["ps_id"]}: {plant}")
print("\nFetching real-time data for each plant...\n")
real_time_data = await plants_api.async_get_realtime_data(plant_ids)
for plant_id, data in real_time_data.items():
# Print only the data points where value is not None
data_values = {k: v for k, v in data.items() if v and v.get("value") is not None}
print(f"Real-time data for Plant ID {plant_id}: {data_values}")
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!
Metadata
Release files for pysolarcloud 0.5.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pysolarcloud-0.5.0.tar.gz | 13.5 kB | Without provenance | Details for pysolarcloud-0.5.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pysolarcloud-0.5.0-py3-none-any.whl | Python 3 | none | any | Details for pysolarcloud-0.5.0-py3-none-any.whl |
Total release size: 25.8 kB
Release files / pysolarcloud-0.5.0.tar.gz
| Download URL | pysolarcloud-0.5.0.tar.gz |
|---|---|
| Size | 13.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f2bb080c5cd7a222b153371d266ec0a0685c510b664260b4323552bc6c1628fb
|
|
BLAKE2b-256 checksum How to use checksums |
25251b8a78ea811e95cbff557a2d705f6d34b6e5f1738466f5eed805bcdebccb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.8.17
|
Release files / pysolarcloud-0.5.0-py3-none-any.whl
| Download URL | pysolarcloud-0.5.0-py3-none-any.whl |
|---|---|
| Size | 12.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2aedf9c5a36d79fe91eaa115c6f36e0c7d80c60edb57f8bb7d0341185f221045
|
|
BLAKE2b-256 checksum How to use checksums |
36cbe2fe3ed0eb20af7bf24e0b26d9176d4572f45e0f9abdd2722defe5647180
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.8.17
|
Security for pysolarcloud 0.5.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.