alphaess-developer / alphacloud_open_api

69 stars 4 forks source link

How to access the info after API created ? #76

Open stephanberger4 opened 1 month ago

stephanberger4 commented 1 month ago

Hi,

Sorry for, maybe, a stupid question but I've created an account and add my device. I've code a Developer ID (AppID), a Developer key (AppSecret) and my SN.

Now, what should I type to access the information of my battery ?

I've tried : https://api.alphaess.com/alphacloud_open_api/inverter_status?systemId=ALD000..... error : Status Code: 404; Not Found

What is the correct URL to access the informations ? I'm trying to do a python code to create an email notification when the battery is in OFF GRID mode.

def get_inverter_status():
    url = "https://api.alphaess.com/alphacloud_open_api/inverter_status?systemId={SYSTEM_ID}"
    headers = {
        "apiKey": API_KEY,
        "apiSecret": API_SECRET
    }
    response = requests.get(url, headers=headers)
    data = response.json()
    return data["Result"][0]["InvWorkMode"]

inverter_status = get_inverter_status()
previous_state = read_previous_state()

if "inverter_status" in previous_state:
    if previous_state["inverter_status"] == 4 and inverter_status != 4:
...etc..

Note : I've also tried, just to see if I can get connected :

import requests
import time
import hashlib

# Informations de connexion
api_account = "MY_API_ACCOUNT"
username = "MY_USERNAME"
password = "MY_PASSWORD"
api_secret = "MY_API_SECRET"

# Calcul du timestamp Unix
timestamp = int(time.time())

# Création de la signature
params = {
    "api_account": api_account,
    "timestamp": timestamp,
    "username": username,
    "password": password
}
sign_str = "&".join(f"{k}={v}" for k, v in sorted(params.items()) if k != "sign")
sign = hashlib.md5((sign_str + api_secret).encode('utf-8')).hexdigest()

# Données de la requête
login_url = "https://api.alphaess.com/ras/v2/Login"
login_data = {
    "api_account": api_account,
    "timestamp": timestamp,
    "sign": sign,
    "username": username,
    "password": password
}

# Envoi de la requête POST pour l'authentification
response = requests.post(login_url, data=login_data)
response_data = response.json()

# Vérification de la réponse
if response_data.get("ReturnCode") == 0:
    token = response_data.get("Token")
    print(f"Token d'authentification : {token}")
else:
    print(f"Erreur lors de l'authentification : {response_data.get('ReturnCode')}")

But it returns "None"

Thx

stephanberger4 commented 1 month ago

Ok I've tried differently but I can't create a 'token'. Is it necessary ? It returns 'ReturnCode: 8' but I'm sure that I've put the right api_account, secret_key, username and password. Anyone know why I've got this error ?

CharlesGillanders commented 1 month ago

I have some ugly but working python code that you might look at to see where the differences are between your code and what is already connecting https://github.com/CharlesGillanders/alphaess-openAPI - Just for a start I'm using SHA512 as the hashing algorithm and you look to be using MD5.

stephanberger4 commented 1 month ago

I have some ugly but working python code that you might look at to see where the differences are between your code and what is already connecting https://github.com/CharlesGillanders/alphaess-openAPI - Just for a start I'm using SHA512 as the hashing algorithm and you look to be using MD5.

Thank you very much ! I will take a look at it and try to understand what I did wrong.

Although, I still don't understand why AlphaESS didn't implemented the function to receive a notification when Off grid... Seems useful. But I will do it with python ! It must not be that hard.

Thx again !

CharlesGillanders commented 1 month ago

I have some ugly but working python code that you might look at to see where the differences are between your code and what is already connecting https://github.com/CharlesGillanders/alphaess-openAPI - Just for a start I'm using SHA512 as the hashing algorithm and you look to be using MD5.

Thank you very much ! I will take a look at it and try to understand what I did wrong.

Although, I still don't understand why AlphaESS didn't implemented the function to receive a notification when Off grid... Seems useful. But I will do it with python ! It must not be that hard.

Thx again !

Oh are you trying to obtain data that's not already exposed in the Alpha ESS OpenAPI? Just saw that your URL is also incorrect for the Open API. I need to let you know that is probably going to be difficult for you. My code used to use the non public API but Alpha asked all of us who had built integrations to move to this Open API, they had begun implementing somewhat adversarial code techniques to make using the unsupported web interface much harder to code against. You will find examples of older code using the non public API but my experience was that breaking changes to the unsupported web interface where happening too frequently without notice to be comfortable staying with it.

Any function they have not built in the existing Open API is supposed to go through their customer service teams to add to some request backlog, unfortunately I'm not sure how many of the requests are getting attention.

stephanberger4 commented 1 month ago

I have some ugly but working python code that you might look at to see where the differences are between your code and what is already connecting https://github.com/CharlesGillanders/alphaess-openAPI - Just for a start I'm using SHA512 as the hashing algorithm and you look to be using MD5.

Thank you very much ! I will take a look at it and try to understand what I did wrong. Although, I still don't understand why AlphaESS didn't implemented the function to receive a notification when Off grid... Seems useful. But I will do it with python ! It must not be that hard. Thx again !

Oh are you trying to obtain data that's not already exposed in the Alpha ESS OpenAPI? Just saw that your URL is also incorrect for the Open API. I need to let you know that is probably going to be difficult for you. My code used to use the non public API but Alpha asked all of us who had built integrations to move to this Open API, they had begun implementing somewhat adversarial code techniques to make using the unsupported web interface much harder to code against. You will find examples of older code using the non public API but my experience was that breaking changes to the unsupported web interface where happening too frequently without notice to be comfortable staying with it.

Any function they have not built in the existing Open API is supposed to go through their customer service teams to add to some request backlog, unfortunately I'm not sure how many of the requests are getting attention.

Oh thank you for this precision. Ok so it's not easy as I think it would have been. Damn it.

I guess I'll try to create a new request (again...) about the feature of receiving a notification when the battery is off grid....

Thank you again for your time