CharlesGillanders / alphaess-openAPI

This Python library uses the Alpha ESS Open API to retrieve data on your Alpha ESS inverter, photovoltaic panels, and battery if you have one.
MIT License
9 stars 5 forks source link

When calling getEssList, code 6009 The request timestamp is not within the validity period #9

Closed xenomorpheus closed 9 months ago

xenomorpheus commented 9 months ago

Hello, I'm having problems migrating from the old to the new alphaess-openAPI. Perhaps I am doing something wrong, perhaps AlphaEss have changed their API, or something else entirely.

So far I haven't managed to get even the getEssList method to work.

I've added a minor logging to the alphaess-openAPI module for debug purposes. I've removed my security keys from the output.

The seconds since epoch - timestamp and timeStamp are both within a few seconds online tools that list UTC seconds.

Are you please able to help me?

Kind regards,

Logging follows

[Thu, 11 Jan 2024 20:44:21] INFO [alphaess.py.__get_data:237] path: https://openapi.alphaess.com/api/getEssList

headers: {'Content-Type': 'application/json', 'Connection': 'keep-alive', 'Accept': '/', 'Accept-Encoding': 'gzip, deflate, br', 'Cache-Control': 'no-cache', 'timestamp': '1704968061', 'sign': 'DELETED', 'appId': 'DELETED', 'timeStamp': '1704968061'}

json: {}

Response:

[Thu, 11 Jan 2024 20:44:22] ERROR [alphaess.py.__get_data:251] Unexpected json_response : {'code': 6009, 'msg': 'The request timestamp is not within the validity period'} when calling https://openapi.alphaess.com/api/getEssList

Poshy163 commented 9 months ago

if you try using the postman collection seen here what response do you get?

xenomorpheus commented 9 months ago

I haven't heard of postman collection before, so I request some help to use postman collection. Is this how to use it ? https://learning.postman.com/docs/getting-started/first-steps/creating-the-first-collection/

Thank you for your fast response.

Poshy163 commented 9 months ago

right, all good. here is the "public" collection. just click on folder (called AlphaESS open API), then on variables and replace all the current value fields in appID, Appsecret and systemSN.

Then control + s to save and click on the "get ess list" on the side bar. and click on the blue send button?

What sort of response do you get?

xenomorpheus commented 9 months ago

Same thing. {"code":6009,"msg":"The request timestamp is not within the validity period"}

Could my API keys be misconfigured?

Poshy163 commented 9 months ago

according to the docs,

6009 | Whitelist verification failed

Do you have IP enable whitelist enabled?

xenomorpheus commented 9 months ago

IP whitelist may have been the issue. I'm now getting error for too many attempts. I'm going to give it a rest, also close the phone app, then try again in an hour or so.

xenomorpheus commented 9 months ago

Issue - Python I enabled whitelist for 15 minutes. Then tried the python. [Fri, 12 Jan 2024 11:20:52] INFO [alphaess.py.__get_data:231] path: https://openapi.alphaess.com/api/getEssList

headers: {'Content-Type': 'application/json', 'Connection': 'keep-alive', 'Accept': '/', 'Accept-Encoding': 'gzip, deflate, br', 'Cache-Control': 'no-cache', 'timestamp': '1705020652', 'sign': '_DELETED', 'appId': '_DELETED', 'timeStamp': '1705020652'}

json: {} [Fri, 12 Jan 2024 11:20:52] ERROR [alphaess.py.__get_data:245] Unexpected json_response : {'code': 6053, 'msg': 'The maximum number of requests has been reached', 'expMsg': None, 'data': None, 'extra': None} when calling https://openapi.alphaess.com/api/getEssList

Successful - Postman output With the whitelist disabled:

{"code":200,"msg":"Success","expMsg":null,"data":[{"sysSn":"AL5001120090030","popv":6.60,"minv":"Smile5-INV","poinv":5.00,"cobat":10.30,"mbat":"SMILE-BAT-10.3P","surplusCobat":9.3,"usCapacity":90.00,"emsStatus":"Normal"}],"extra":null}

Poshy163 commented 9 months ago

Yeah, keep the whitelist disabled or only keep it for the external IP of your home assistant instance.

The response you with the whitelist disabled is the desired response for the call

xenomorpheus commented 9 months ago

What I don't understand is why the postman works, but my python script doesn't work. I'm struggling to see why Is there a difference between what postman sends and what the script sends? Is the postman website "whitelisted" to always permitted to send to AlphaEss, but not my IP address ? Any thoughts would be appreciated.

xenomorpheus commented 9 months ago

I might have worked out the problem. I do two different requests in quick succession. I thought it was the first request failing, but it might actually be the second request.

I might be as simple as putting a delay between my two requests.

CharlesGillanders commented 9 months ago

Just to confirm there's no difference between postman and the API library nor is postman whitelisted in any way.

xenomorpheus commented 9 months ago

Yep. Issue with my script. Sorry to have consumed some of your time. Best wishes.