Closed fmarton closed 1 year ago
Hello @fmarton ,
Great!
Is it what you receive from the OpenApi request? Which endpoint/URL?
On my side I receive, only the accumulators... (Day, month & total)
I'll try to ask Huawei to update my API profile to get more data.
Thank you for your feedback, Olivier
I have solars and inverter with 3phases this is the python that I get from internet.
import requests import json import decimal userName="..." systemCode="..."
s = requests.Session() s.headers.update({'Connection': 'keep-alive', "Accept": "/","Accept-Encoding": "gzip,deflate,sdch", 'Content-Type': 'application/json'}); r = s.post(url='https://eu5.fusionsolar.huawei.com/thirdData/login', json={"userName":userName,"systemCode":systemCode},headers=s.headers) data=r.json() cook= r.cookies.get(name='XSRF-TOKEN') s.headers.update({'Connection': 'keep-alive', "Accept": "/","Accept-Encoding": "gzip,deflate,sdch", 'Content-Type': 'application/json', 'XSRF-TOKEN': cook}) r = s.post(url='https://eu5.fusionsolar.huawei.com/thirdData/getStationList', json={},headers=s.headers) data=r.json() sc=data['data'][0]['stationCode']
r = s.post(url='https://eu5.fusionsolar.huawei.com/thirdData/getDevList', json={"stationCodes":sc},headers=s.headers) data=r.json() devIds=data['data'][0]['id']
r = s.post(url='https://eu5.fusionsolar.huawei.com/thirdData/getDevRealKpi', json={"stationCodes":sc,"devIds":devIds, "devTypeId":"1"},headers=s.headers) data=r.json() dane=data.get("data")[0] print(decimal.Decimal(dane.get("dataItemMap").get("active_power"))) print(decimal.Decimal(dane.get("dataItemMap").get("day_cap"))) print(decimal.Decimal(dane.get("dataItemMap").get("total_cap")))
Thank you for the code example!
I'll have a look and let you know what I can do βΊοΈ
As I see the huawei forum doesnt show this request r = s.post(url='https://eu5.fusionsolar.huawei.com/thirdData/getDevRealKpi', json={"stationCodes":sc,"devIds":devIds, "devTypeId":"1"},headers=s.headers)
This gives more details. Br ferenc
You're right, and I was just playing with the script you mention.
The devTypeId should not be hardcoded as 1 in my case it's 38 π But now, I can see the data as well.
I've received the following from the support of Huawei: SmartPVMS V500R007C00 NBI Reference.pdf
There are some really intersting data like :
Do you need something else?
I'll try to make a test version this week.
Thank you again, Olivier
Sorry, GetDevList gives the devTypeId exactly.
r = s.post(url='https://eu5.fusionsolar.huawei.com/thirdData/getDevList', json={"stationCodes":sc},headers=s.headers) data=r.json() devIds=data['data'][0]['id'] devTypeId=data['data'][0]['devTypeId']
r = s.post(url='https://eu5.fusionsolar.huawei.com/thirdData/getDevRealKpi', json={"stationCodes":sc,"devIds":devIds, "devTypeId":devTypeId},headers=s.headers)
I think active_power and state is enough at this moment.
Best regards Ferenc
Olvier, Could you please check the total lifetime energy via kiosk and api? I have 50kwh difference. I see this deviation in web-mobile GUI also, so this is not integration issue.
It seems webgui doesnt calculate energy when it is unreachable (eg.: internet problem )
Thanks Ferenc
Hello, I have the same kind of lag between the web interfaces of Huawei. On the list view it told me: 298.67kWh lifetime: But when I go to device management, I have:
And I get the same information in OpenAPI as in device management. Which is quite logical based on the endpoint name: /getDevRealKpi
I don't know why there are differences π
Note: as you can see all this is new for me...
@fmarton, I've pushed the new version on feature/add-dev-real-kpi.
Can you try it and give some feedback?
I am new at Fusion api, new at Home Assistant. :) Could you please help me how I can change branch of yout openapi in HomeAssitant?
ps.: I found the way how can the historic (any month, day) data can download :)
Thanks Ferenc
@fmarton, I've pushed the new version on feature/add-dev-real-kpi.
Can you try it and give some feedback?
1.1.0-beta.1 gives the following error:
Error fetching FusionSolarOpenAPI data: Invalid response from API (missing active_power)
Hello @arboeh ,
Sometime the Huawei API sent bad responses...
The integration should recover from this and few minutes later the data should be updated. Can you confirm?
@fmarton , To try the test version you have to go in HACS -> Integrations Select "Fusion Solar OpenAPI" click Redownload and the enable "Show beta versions": and the version 1.1.0-beta.1 should be available.
I exactly did that and unfortunately the error still exists and isn't temporary.
It's maybe linked to your device type. I'll make a version with more logs. This will help me to diagnose the issue. In the meantime, go back to 1.0.0, thank you for your feedback.
@arboeh I've pushed a new version v1.1.0-beta.2, can you enable debug log for this integration?
logger:
default: info
logs:
custom_components.fusion_solar_openapi: debug
Normally you should see a debug line with: Request: getDevRealKpi Can you send me the Response part. Don't forget to scramble ids π
Thank you, Olivier
I had that in my logger config already lol Is it possible to send you the log information via e-mail or Twitter? There are too much personal informations inside.
Github is missing private messages π
You can send it to my email address: olivier.bossaer@gmail.com
I am oou of office, but I follow xou :)
Olivier Bossaer @.***> ezt Γrta (idΕpont: 2022. okt. 18., Ke 12:44):
Github is missing private messages π
You can send it to my email address: @.***
β Reply to this email directly, view it on GitHub https://github.com/olibos/Home-Assistant-FusionSolar-OpenApi/issues/1#issuecomment-1282188747, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFHUMKHAIEUWQG5DSSCLAYTWDZ5RLANCNFSM6AAAAAARGIAG6Q . You are receiving this because you were mentioned.Message ID: @.***>
@arboeh I've pushed a new version: v1.1.0-beta.3. Can you test it?
Yup, works for me. Thanks! Great and quick support. Like @fmarton wrote: More entities would be nice ;-)
Great to hear it's fixed on your side.
I'll first stabilize this feature but after we can make another "Issue" with missing data π
Hi, There is access restriction for all url, XSRF Token has a 30mins validity period. In section 7 (doc that you get from Huawei support), you can find all error codes that should be handled in code. StationCode, DevID should be stored statically and checked in error code case. I am so sorry, these are ideas/suggestion only
7 20007 The system does not have the desired power plant resources. 8 20008 The system does not have the desired device resources 13 20013 The device type is incorrect. The interface does not support operations on some devices. 23 305 You are not in the login state. You need to log in again 25 407 The interface access frequency is too high. 54 20400 The username or password of the third-party system is incorrect. 84 30029 Authentication failed
3.6.1 Real-Time Device Data Interface https://Domain name or IP address of the management system/thirdData/getDevRealKpi
Access Restrictions The maximum number of access times of each NBI account per minute is 10. The data on this interface is updated every 5 minutes. It is recommended that the interface be invoked every 5 minutes at most. If the access frequency exceeds the limit, the interface returns error code 407.
3.1 Login Interface Description ο¬ Before obtaining data, the login interface must be invoked to obtain the XSRF-TOKEN. The validity period of the XSRF-TOKEN is 30 minutes. ο¬ If the XSRF-Token does not expire, it can be reused. If the XSRF-TOKEN has expired, the login interface needs to be invoked again to obtain a new XSRF-TOKEN. ο¬ After this interface is invoked to log in to the system, the XSRF-TOKEN is returned in the response header. Request URL https://Domain name or IP address of the management system/thirdData/login Request Method HTTP method: POST Access Restrictions The maximum number of access times of each NBI account per minute is 1. It is recommended that the interface be invoked every 30 minutes. If the access frequency exceeds the limit, the interface returns error code 407.
@olibos , To try the test version you have to go in HACS -> Integrations Select "Fusion Solar OpenAPI"
Hi, Thank you for this help, I upgraded to beta3. active_power is available now. I follow te operation. :)
Best regards Ferenc
I handle the error this way:
r = s.post(url='https://eu5.fusionsolar.huawei.com/thirdData/getDevRealKpi', json={"stationCodes":sc,"devIds":devIds, "devTypeId":devTypeId},headers=s.headers) datareal=r.json() if r.status_code != 200: print(datareal) else: dane=datareal.get("data")[0] print('active_power: '+str(dane['dataItemMap']['active_power'])+" kW") print('day_cap: '+str(dane['dataItemMap']['day_cap'])+" kWh") print('tota_cap: '+str(dane['dataItemMap']['total_cap'])+" kWh")
In error case there is the description of error. {'errorCode': '49401021002', 'exceptionInfo': 'Request is rejected by api quotaControl. api:ies_PVMSNbiService_thirdData_1.0.78, key:/getDevRealKpi_POST'}
Hello @fmarton ,
Thank you for those details about the api and XSRF tokens. There are clearly room for improvements.
I think, in the first place I'll update the update interval to five minutes, that's an easy one π
To keep the XSRF token (for 30 minutes), StationCodes or DevIds, I have to refactor the way the FusionSolarOpenApi
is created / managed.
Lets see the result, Active power and state are collected. 5mins resoluton has noticable difference. The hourly stats is more accurate in energy card. Thank you for the openapi development. ferenc
Hi,
Could you change to get more KPI? Currently I miss active_power.
This is an output from current openapi. 'dataItemMap': {'pv2_u': 0.0, 'pv4_u': 0.0, 'pv22_i': 0.0, 'power_factor': 1.0, 'pv6_u': 0.0, 'mppt_total_cap': 0.0, 'pv24_i': 0.0, 'pv8_u': 0.0, 'open_time': 1665897972000, 'pv22_u': 0.0, 'a_i': 2.067, 'pv24_u': 0.0, 'mppt_9_cap': 0.0, 'c_i': 2.021, 'pv20_u': 0.0, 'pv19_u': 0.0, 'pv15_u': 0.0, 'a_u': 233.2, 'reactive_power': 0.002, 'pv17_u': 0.0, 'c_u': 232.7, 'mppt_8_cap': 0.0, 'pv20_i': 0.0, 'pv15_i': 0.0, 'pv17_i': 0.0, 'efficiency': 96.62, 'pv11_i': 0.0, 'pv13_i': 0.0, 'pv11_u': 0.0, 'pv13_u': 0.0, 'mppt_power': 1.482, 'run_state': 1, 'close_time': 1665851269000, 'pv19_i': 0.0, 'mppt_7_cap': 0.0, 'mppt_5_cap': 0.0, 'pv2_i': 0.0, 'active_power': 1.432, 'pv4_i': 0.0, 'pv6_i': 0.0, 'pv8_i': 0.0, 'mppt_6_cap': 0.0, 'pv1_u': 294.8, 'pv3_u': 0.0, 'pv23_i': 0.0, 'pv5_u': 0.0, 'pv7_u': 0.0, 'pv23_u': 0.0, 'pv9_u': 0.0, 'inverter_state': 512.0, 'total_cap': 6925.39, 'mppt_3_cap': 0.0, 'b_i': 1.997, 'pv21_u': 0.0, 'mppt_10_cap': 0.0, 'pv16_u': 0.0, 'pv18_u': 0.0, 'temperature': 27.1, 'bc_u': 414.1, 'b_u': 241.9, 'pv21_i': 0.0, 'elec_freq': 50.03, 'mppt_4_cap': 0.0, 'pv16_i': 0.0, 'pv18_i': 0.0, 'day_cap': 0.93, 'pv12_i': 0.0, 'pv14_i': 0.0, 'pv12_u': 0.0, 'mppt_1_cap': 0.0, 'pv14_u': 0.0, 'pv10_u': 0.0, 'pv1_i': 5.13, 'pv3_i': 0.0, 'mppt_2_cap': 0.0, 'pv5_i': 0.0, 'ab_u': 408.0, 'ca_u': 403.8, 'pv7_i': 0.0, 'pv10_i': 0.0, 'pv9_i': 0.0}
Sorry, I didnt find any docs about the params. Thanks Ferenc.