thomluther / anker-solix-api Goto Github PK
View Code? Open in Web Editor NEWPython library for Anker Solix API
License: MIT License
Python library for Anker Solix API
License: MIT License
Add the new fields to the monitor
This is helpful to keep existing device details up to date, even if device details query is not run.
The HA integration does device details queries less frequently than site details queries due to amount of additional Api requests needed for all device details.
However, the last known device details are provided to the integration with each sites update interval.
If any other method will be triggered that contains device related details, this should automatically refresh the api devices dict as well with the latest information to make them directly available to the integration.
A helper function is needed (also for Home Assistant integration) to simplify change of the set home load.
Points to clarify and validate before this can be provided:
The help function should provide option switches for:
For my personal use I've moved the credentials to a single file (settings.py)
Since I dont know if this is of use for others and I've no clue how PR are created from shell
I'll provide the changes via this gitea repo https://git.grml.de/robin/anker-solix-api-PR
This is to prevent that actual debug logs will reveal used tokens per default.
Full debug can be re-enabled via class attribute
I would be happy to add pre-commit (https://pre-commit.com/) with some linters like
An outstanding firmware upgrade per device should be reflected in the api data structures if possible.
Investigate api capabilitiies for OTA queries and explore mechanism to report outstanding upgrades.
Explore if and how update can be performed with Api.
Hi tholu,
as requested there are some sample data from the export script.
SETUP:
HM 1600 Inverter
2x 410w panels.
1x solarbank e1600
regards
florian
Attachment removed, see #15 (comment)
A system member cannot list the device schedule, that contains detailed fields for site pre-set and device shared pre-set output.
The member only receives fields from the scene info query, however this is empty for the device details.
A work around must be implemented to share the given retain load for the site down to the installed solarbanks for the site in case the device pre-set output is not filled otherwise.
The value displayed for "charge power" is not the correct value. This is related to our conversation over at the forum.
My two banks are set to charge and in the app the charge is displayed roughly the same value as the solar power.
No energy to the house.
solarbank_monitor.py output looks like this:
Solar Power : 79 W Charge Power: 0 W
Output Power : 0 W (Output Preset: 0 W)
Solar Power : 80 W Charge Power: 0 W
Output Power : 0 W (Output Preset: 0 W)
AC Power : 0.00 W
Auto upgrade is controlled with a main switch and a switch per device.
When main switch is disabled, it will disable automatically all device switches as well.
When a device should be enabled, the main switch must be enabled as well as the device switch.
The method should simplify the approach by simply demanding dictionary with the device serial and the desired switch setting.
The method must query the actual switch settings and control the main switch settings based on the actual settings and the desired changes.
Note: When the main switch will be disabled, all device switches will be automatically disabled as well. So there is no unintentional enablement possible when the main switch is turn on in order to enable a specific device
Currently the active schedule is not part of the solarbank device details.
They should be added for better data serving to the Home Assistant integration.
Created Enums for device types and device param.
Also figured out that there is another operation mode while reporting status 3 Bypass:
When Charge priority is enabled, 0W will go home but solarbank reports Bypass mode.
Introduced new mode for charge_priority which is set when 3 is reported but 0W go to home (no bypass power)
Mapped set home load power acordingly to system and device details.
The api reports the settings in different fields, depending on the system constellation with 1 or 2 solarbanks. This is now properly mapped for each device (hopefully)
Solarbank Monitor:
<class 'UnboundLocalError'>: cannot access local variable 'use_file' where it is not associated with a value
Traceback (most recent call last):
File "/Users/js/repos/anker-solix-api/./solarbank_monitor.py", line 263, in <module>
if not asyncio.run(main()):
^^^^^^^^^^^^^^^^^^^
File "/Users/js/.pyenv/versions/3.12.1/lib/python3.12/asyncio/runners.py", line 194, in run
return runner.run(main)
^^^^^^^^^^^^^^^^
File "/Users/js/.pyenv/versions/3.12.1/lib/python3.12/asyncio/runners.py", line 118, in run
return self._loop.run_until_complete(task)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/js/.pyenv/versions/3.12.1/lib/python3.12/asyncio/base_events.py", line 684, in run_until_complete
return future.result()
^^^^^^^^^^^^^^^
File "/Users/js/repos/anker-solix-api/./solarbank_monitor.py", line 93, in main
if use_file:
^^^^^^^^
UnboundLocalError: cannot access local variable 'use_file' where it is not associated with a value
This happens, when coding USER
to the script
This will introduce some extra fields in the device details dict that have been seen only in inverter devices example outputs.
Details are listed in the fittings output
Example data from fittings request
"data": [
{
"device_sn": "ZDL32D6A3HKXUTN1",
"product_code": "A17Y0",
"device_name": "E1600 0W Output Switch",
"alias_name": "E1600 0W Output Switch",
"img_url": "https://public-aiot-fra-prod.s3.dualstack.eu-central-1.amazonaws.com/anker-power/public/product/2024/01/10/iot-admin/EPBsJ3a5JyMGqA1j/picl_A17Y0_normal.png",
"bt_ble_id": "",
"bt_ble_mac": "FC1CEA253CDB",
"link_time": 1707127936
}
The power cutoff details are already added to the device details.
Method is needed to change the power cutoff data allowing Home Assistant to easily select another id of the available settings list.
Setup 2 solarbanks, 1 MWR MI 80
The system export needs fixes for following problems:
Hey Guys,
I am a Creator of Home Assistant Content in Germany and I'm currently trying to figure out, how to set the output values of the Anker Solix Solarbank.
I got so far, that I tried reverse-Engineering the App-Communication via "Surge" (Can get Flutter-App Traffic), but it seems like the Body is somehow encrypted. Here are some details, hoping it helps:
Request | Response |
---|---|
MTcwODEwMzc5NzQwNDkwOP/5wqXxK2EGqFpTU0MKvYV8+4IPoaFWGz54ERQjoOYZJBgyqb+CdG3KGgsvZEmNIbEIOSK/EdNHQdRq4Ybq3TqvribSUVlzFCWsaSvVQXHvImu5dqFZ45VMR2gCW0JVIDqBk4UuoHI9dVRsV70DWqb8rH1iZ1dqzdRn99obqwQZSdNPld6umOZ271AjgufiWOfXBP8HaMcgq8NTJUjH4WuHsaQF1v64rYtY0E0byDM4B9kklQ4DRIdwJryNFd9IhjK7a2UL5EU/TK/eWpB6wEXLEKc5pleLkij9QVy+r8VQ+vW9M9F69U5yBVnWQ8IBrCZFB/TuIMmJYjNp6JWh7rVlMpYYHaag77981HTmhAYlpP7AGDhAqiUCOUxv0hgHi6btchPfsHVynZ5wuANGwu2ipTb296zQXOSYgbBzHDJbro9aAZB560XUHrW4ICDFqdQ48rFRvqozHDxehIv94pR6qzGz5MlVdTbzUjgj8weIGDnA2jWNTLirW/lEkBnoI2Wmo2TBREgru1698XXhDnqj+tiwuzDTtfcK/SL9dMs8aZccyETrF98z/rKeW/nXPDIGtoUvEO73HpNoZ42OAu6zv7XvcmxSiAErL+fKpbHdZ6rrjntLNu/qEDxRX6dy8n3EHSbkBAQDNnWGnN50SxaNnxLnYRJFl5UHKV7J0JZmc2p7iH2zT2NIi5nOJrNJ4sbj/5XQF3YUTvxaXVAeuWjAS3LGgc2khL3RjBYQbJbh6Hi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PQsfo/WWOxmcqDYBqbiX6C96A==
I already tried to write a function to get it decrypted, but no luck so far. Maybe someone could figure out a way, on how to do this? The Command should show (when decrypted) how to set the Power-Output of the current timeframe to 100W or 140W, not quite sure which command this was 😅.
By the way, here in this other Repo it seems like already implemented: https://github.com/energychain/AnkerSolixE1600-APIServices/blob/main/index.js#L289C1-L289C44
The message contains error messages visible in the app.
Need to investigate how they are structured and how they can be best reported with the api routines in the api data structures, so they become available for api users.
On Mac / Linux you can simply call the script with ./solarbank_monitor.py
instead of python solarbank_monitor.py
Therefore the script needs the executable bit and the first line must contain a shebang
Currently the device details dictionary is not recycled at all for obsolete devices.
This may cause invalid device details data when devices are removed from a site, or when the API is switched to test mode and switching example folders with different data sets.
While the sites dict is recreate on each update_sites query, the devices dict is just being updated and enhanced, but not recycled for devices that are no longer managed by the found sites.
Actually the charge is same as output....
Need to investgate why this is still reported incorrectly.
line 287 is missing the string formatter character to replace the parameter in the filename
Changed and additional device details field require changes in the device_monitor module
Change to use:
ANKERUSER
ANKERPASSWORD
ANKERCOUNTRY
The device details in the scene info do not show the connected wireless network anymore. This is shown only in bind devices, when the device is not assigned to a site yet.
Code will be changed to avoid that existing network name is overwritten with empty fields during updates.
Additional details from site wifi networks is added to the device details, like network name and signal strength.
It is assumed, that the wireless_type in scene info is an index to the wireless network listed for site networks.
Currently the documentation states what are the direct deps. If not using pyenv
collisions of versions are very possible.
To use isolated envs there are tools like pipenv (https://pipenv.pypa.io/en/latest/) or more modern ones like poetry (https://pypi.org/project/poetry/).
If accepted and decision for one of these tools I would be happy to add this
Initially, the device status code of 0 and 1 was interpreted as On or Off.
However, it appears to reflect the cloud connection status.
Observed for example that the solarbank was 1 over night and went to 0 during the day while feeding power to home.
So it defenitely cannot be the 'power' state of the device. But noticed that when opening the Anker App while device status was 0, the device was shown offline.
So a change will be done on the description of the device status
0 = offline
1 = online
I have found situations where the charging status description does not reflect the situation as originally assumed.
0: Just saw it once, but cannot say which meaning it was
1: Was assumed charging only, but is actually Bypass only
2: Remains discharging
3: was assumed bypass and is seen in various situations, may need more monitoring for accurately distinguish what this can mean in combination with charge and output values
4: Remains wakeup....short periods of 2 minutes seen over night about every 2 hours. Maybe some kind of status checking....
5: ???
6: ???
7: Remains Standby
I changed the 'sn' to 'device_sn' and 'pn' to 'device_pn' in the api.devices dictionary for more communality
The response body contains more details why the request failed, e.g. which field was missing.
This information needs to be logged with the error message to provide more reasoning why the request failed.
Changed:
'status_description' to 'charging_status_desc' to avoid mixing this up with the extra 'status' field provided by most? solix devices
Currently there are 2 fields reporting a numerical state:
'status': Found "0" and "1" so far, potential meaning is off and on?
'charging_status' for solarbank already revealed following numerical states:
charging = "1"
discharging = "2"
bypass = "3"
bypass_charging = "35" # pseudo state, the solarbank does not distinguish this
wakeup = "4" # Not clear what happens during this state, but observed short intervals during night as well
# There is also a deep standby / full bypass mode at cold temperatures when the battery cannot be loaded.
# full_bypass = "unknown"
standby = "7"
As it turns out, the fields presented in the solarbank info for the set load and the fields presented in get_device_load may have a different mapping.
When 2 solarbanks are used in a system, the set home load per System will be 50% of the site home load that is being defined in the schedule. Each solarbank reports both pre-set values, but the individual setting (parallel_home_load) appears to be set only when 2 solarbanks are used. However, the solarbank info details from the scene query as used for the sites update will show the active pre-set per device.
Furthermore the schedule is currently a common property for the site. Solarbank devices share the same schedule, but it cannot be modified independently at this point in time.
To maintain flexibility for the future, the schedule will continue to be reported along the device details, although it cannot be set independently yet. The home load pre-sets for Site details and device details will be adjusted and properly mapped.
This will also support future set home load helper function that can act for a specific device. The site_id, device_sn and schedule is available in the device details and can be used by the helper to have all details for changing / updating the corresponding schedule with the new home load settings.
On checkout you run into the problem that cachefiles need to be deleted
robin@debian:/opt/build2/anker-solix-api$ git checkout v1.1.0
Fehler: Ihre lokalen Änderungen in den folgenden Dateien würden beim Auschecken
überschrieben werden:
export_system.py
Bitte committen oder stashen Sie Ihre Änderungen, bevor Sie Branches
wechseln.
Fehler: Die folgenden unversionierten Dateien im Arbeitsverzeichnis würden durch
den Checkout überschrieben werden:
api/__pycache__/__init__.cpython-311.pyc
api/__pycache__/api.cpython-311.pyc
api/__pycache__/errors.cpython-311.pyc
Bitte verschieben oder entfernen Sie diese, bevor Sie Branches wechseln.
Abbruch
The solar_info request actually shows the defined inverter type for given solarbank sn:
This info was added to device details as well.
Following new methods have been added:
Status 1: Charging
Status 2: Discharging
Status 3: Bypass or Bypass Charging (depends if charging power > 0
Status 4 occurs shortly at night times, but its not clear what it means, called it 'wakeup'
Status 5 and 6 are were not seen yet, one could be for fully bypass / deep standby which happens at cold temperatures when battery cannot charge.
Status 7: Standby
anker-solix-api/pyproject.toml
Line 2 in e298a98
White spaces are not allowed in the name, thus pip fails to install. When i change it to "Anker-Solix-Api", the installation succeeded.
I made no PR because i don't know what you prefer, no white spaces, a dash, dot or underline.
This requires expanding the dict structure of the sites with a nested dict for site details. These should be updated less frequently and can also be used to lookup old information when modifying individual parameters related to site prices, Units or CO2.
When this is clear, update the device details field naming accordingly.
The Api library was expanded with another method to update site details and add this information to the sites dictionary.
The export_system picked up this additional method to list the details in the api_sites output.
The capacity calculation should be less dependent on device_name to report this also for shared accounts, which do not receive device_name but only device alias information from scene info.
Known PNs such as the Solarbank are now defined as Enumeration with their capacity value.
The export folder should be created in the local path of the tool
This works now, a given id must be set from the get_power_cutoff endpoint.
python3 solarbank_monitor.py
Device : MI80 Microinverter(BLE) (Admin: NO)
SN : E0710000****
PN : A51**
Type : Unknown
<class 'AttributeError'>: module 'sys' has no attribute 'stdoutf'
Aborted!
It is assumed that the current version of the Api supports only European countries due to the Cloud server location.
Other Geos / Regions may need to contact different Anker Api servers, distinguished by the used country ID.
This isssue addresses the preparation for supporting various server urls depending on the country code.
This creates 2 more files in the output
api_devices.json
api_sites.json
This can be used as examples how the internal dictionaries will be structured for site and device information.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.