Giter Club home page Giter Club logo

anker-solix-api's People

Contributors

stuertz avatar thomluther avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

anker-solix-api's Issues

Automatically update devices dict with other device details related methods

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.

Need helper function to change the home load

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:

  • Can the set_home_load endpoint be used with the same schedule parameter dict as the set_device_parm endpoint?
  • Does the schedule parameter dict require a full schedule as received with either get_home_load or get_device_parm endpoints?
  • Is it sufficient to modify only the active schedule slot with the new parameters for home load and discharge setting, or may this delete the other slots in the schedule?
  • If only a single slot is supported, what happens if the times of the slot are changed? Will the modified timings delete/modify the adjacent slots like in the App?

The help function should provide option switches for:

  • new home load value
  • setting of discharge switch
  • whether the change should be applied to current slot only or all slots
    If the whole schedule or parts of it needs to be changed, this should be done via the set_device_parm method providing the full schedule json.

Mask credentials in debug output

This is to prevent that actual debug logs will reveal used tokens per default.
Full debug can be re-enabled via class attribute

Work around for empty device preset output when using shared account

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.

Bug in Solar power/Charge power

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

Implement helper method to set auto-upgrade mode

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

Code simplifications and new operational mode

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)

UnboundLocalError: cannot access local variable 'use_file' where it is not associated with a value

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

Add 0W output switch details to device details

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
}

Implement method to change the power cut off

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.

Findings in system exports

The system export needs fixes for following problems:

  • Device SN does not seem to get randomized for fittings dictionary
  • Wifi Network name randomization may cause extra 'network' aliases in randomized output?
  • new battery capacity and battery energy fields not created for dual solarbanks / or changed alias names?
  • new set_output_power field not created for dual solarbanks?

Question about encryption & (hopefully) some useful data

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
DE8B602F-2203-49A9-AE32-CA6BD0A2C2F7_1_102_o 271DD43C-C2F4-48FF-80AE-D49EA5F97E6F_1_102_o
26694898-7CD0-4EF0-931B-A08A79585FEE_1_102_o 2ACB43DC-C5AD-42A2-80E4-FB7A65A8EF4C_1_102_o

## Full Body (Request)

MTcwODEwMzc5NzQwNDkwOP/5wqXxK2EGqFpTU0MKvYV8+4IPoaFWGz54ERQjoOYZJBgyqb+CdG3KGgsvZEmNIbEIOSK/EdNHQdRq4Ybq3TqvribSU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v00/XlrtQRnZOW2YfkHTNNiKkG/hvkoeMj0Qgyse3rNioSvCHWlnTiiwvvxiTmhJ4SUr4Aq1BNUuI8ks6PQQjS5LWylXIzE/79O+cYdPhy8n7utgF8+k2IFrKpNtuuryx6QgZXG+WAJdTz5Cf09b6BKcFQE1XCbALWEN5K7zobu6Y2w9fJ+GYv21pwucha6kQ0emLrRUmuc1f4Qp2q1z+5hI/Z3efzihtLhenbzzi0fVazoZoOsKk2U4TGCrL9Lm/4ltke1Jud4AviKYEVZV5+lYeO6L7qgUF3k2v7PO5kb6TNHselHGEMH4YIJbZeRQ/nt0hldrMmWlNsZeJu2ZKUP/jjvBfY4C5ich6VFw4T/ke1AKV3lazJaRlkwJYZ3N07SXE+NGjmRW9colg1oY3wkGUT6FX1+O99eqG2svywAF51/Yp/xc65Zfr9QIYXckUqpAHegsKwRfHMfaeQSWnK9rokLro75DDuaf3XZutKPnL0c/138IWv1VDrSfE+/ZniKUHa3OA64U5aMQnnD6bZOY3v3Qq8FUg2cGkiOIirRlVRoDLbadxXg0s9Tv7fNcTGCvMIFJ4NdLV4g0TDb0uJYjRgCXDo4MKLHEY/EagQjHSZ4WwUzyxVWZ2RZawcy/Y7KnmtPQsfo/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

Implement method to query messages for site

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.

feat: make py scripts executable

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

Recycle the device details dict with each sites query to remove obsolete devices

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.

Add Wifi details to device details

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.

Device status intepretation probably wrong

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

Wrong charging status description

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

Add http request response text upon error

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.

Add descriptions for numerical states reported by api

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"

Allign output presets in device details

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.

Cache dir/files is not in .gitignore

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

Add methods for additional endpoint and correct the solar_info request

The solar_info request actually shows the defined inverter type for given solarbank sn:

  • get_solar_info(self, solarbankSn: str, fromFile: bool = False) -> dict:
    Get the solar info that is condigured for a solarbank.

This info was added to device details as well.
Following new methods have been added:

  • get_compatible_info(self, solarbankSn: str, fromFile: bool = False) -> dict:
    Get the solar info and OTA processing info for a solarbank
  • get_ota_info(self, solarbankSn: str = "", inverterSn: str = "", fromFile: bool = False) -> dict:
    Get the solar info and OTA processing info for a solarbank.
  • get_ota_update(self, deviceSn: str, insertSn: str = "", fromFile: bool = False) -> dict:
    Usage not Clear, process OTA update with confirmation in insertSn?
  • get_upgrade_record(self, recordType: int = 2, fromFile: bool = False) -> dict:
    Get upgrade record, shows device updates with their last version. Type 0-3 work.

Added solarbank status description field into device details dict.

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

Implement methods to query site prices and change price or unit

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.

Define capacity for known PNs

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.

Prepare for Globalization

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.