indykoning / PyPi_GrowattServer

MIT License
70 stars 32 forks source link

What happened to currentPower #24

Closed Derko01 closed 2 years ago

Derko01 commented 2 years ago

Hi, As of today the currentPower is constantly 0. (Not in the Growatt Android APP). But via my Pythoncode it is. I used Sjoerd's plain Python-example for a couple of years now. And now I found this package. But that also gives currentPower:0 Looks like a problem in the Growatt-API? Anybody same problem?

Thanks in advance, Derko

Sjaak1982 commented 2 years ago

You are not the only one. Same problem here. Last correct reading was 8.45 CET

muppet3000 commented 2 years ago

Strange that the App is still working as expected. This suggests that they've possibly changed the API call that the App is making but the old one is still active. Later tonight I'l fire up the app we use to trace the API calls and see if the ShinePhone app is making a different call all of a sudden. Can you both confirm that you're making the same sorts of calls in your code as is seen in this ticket: https://github.com/indykoning/PyPi_GrowattServer/issues/20 ? (That will help me to run exactly the same commands when re-testing). NOTE - When I re-test later it'll be dark so my system will legitimately NOT be producing any power.

However, throughout today I've seen no issue with the readings either in the Growatt Android App, Growatt Website or my usage of this library (which is via the HomeAssistant plugin).

muppet3000 commented 2 years ago

Right, so I've had a bit of a play. Can you all please confirm whether you're running something similar to this:

#!/usr/bin/python3

import growattServer
import datetime
import getpass
import pprint

pp = pprint.PrettyPrinter(indent=4)

#Prompt user for username
username=input("Enter username:")

#Prompt user to input password
user_pass=getpass.getpass("Enter password:")

api = growattServer.GrowattApi()
login_response = api.login(username, user_pass)

plant_list = api.plant_list(login_response['user']['id'])
pp.pprint(plant_list)

Which would give output something like this:

$ ./current_power_test.py 
Enter username:***********
Enter password:***********
{   'data': [   {   'currentPower': '0 W',
                    'isHaveStorage': 'false',
                    'plantId': 'XXXXXX',
                    'plantMoneyText': '229.4 ',
                    'plantName': 'growatt',
                    'todayEnergy': '15 kWh',
                    'totalEnergy': '4.59 MWh'}],
    'success': True,
    'totalData': {   'CO2Sum': '1.84 KT',
                     'currentPowerSum': '0 W',
                     'eTotalMoneyText': '229.4 ',
                     'isHaveStorage': 'false',
                     'todayEnergySum': '15 kWh',
                     'totalEnergySum': '4.59 MWh'}}

And you're referring to the currentPower returned in the data block?

Now, after a bit of investigation, I don't believe this value is used anywhere in the ShinePhone app - which explains why the app still appears to work. NOTE - As I stated earlier it is now dark here in the UK so I can't test whether that value returns anything other than 0 currently - I will check again tomorrow though.

Personally, I have never used that value, instead I've queried the value from the API based on calls specific to my system. e.g. in the case of my system (a 'mix' system) see an extended version of the above script but with a call to mix_system_status which contains the values specific to a mix system.

#!/usr/bin/python3

import growattServer
import datetime
import getpass
import pprint

pp = pprint.PrettyPrinter(indent=4)

#Prompt user for username
username=input("Enter username:")

#Prompt user to input password
user_pass=getpass.getpass("Enter password:")

api = growattServer.GrowattApi()
login_response = api.login(username, user_pass)

plant_list = api.plant_list(login_response['user']['id'])
pp.pprint(plant_list)

print("")

for plant in plant_list['data']:
  plant_id = plant['plantId']
  plant_info=api.plant_info(plant_id)

  for device in plant_info['deviceList']:
    device_sn = device['deviceSn']
    device_type = device['deviceType']
    print("Device type: %s" % (device_type))

    mix_status = api.mix_system_status(device_sn, plant_id)
    print("PV total wattage - KW: %s"%(mix_status['ppv']))

It would be good to know what deviceType your systems are so I can help you to get the specific value back. However, I'm confident that's the reason you are seeing 0 values for that particular value on the API because it's not actually used in the App from what I can tell.

Anyway, I'm happy to help out more if I can, if you can respond to some of the above I'll see what I can do.

Derko01 commented 2 years ago

Hi,

Thanks so far. Yes, I am referring to currentPower-key in the json. My deviceType turns out as 'inverter'. In the Growatt Android APP there is a "Huidig vermogen" which translates to currentPower. And there I saw positive values all the day (very sunny in The Netherlands).

My simplified code:

#!/usr/bin/env python

import growattServer
import pprint

pp=pprint.PrettyPrinter(indent=4)

username = '****'
password = '****'
api = growattServer.GrowattApi()
login_response = api.login(username, password)
pp.pprint(api.plant_list(login_response['user']['id']))

Output:

{   'data': [   {   'currentPower': '0 W',
                    'isHaveStorage': 'false',
                    'plantId': '****',
                    'plantMoneyText': '1064.8 (€)',
                    'plantName': '****',
                    'todayEnergy': '6.4 kWh',
                    'totalEnergy': '5.07 MWh'}],
    'success': True,
    'totalData': {   'CO2Sum': '3.04 KT',
                     'currentPowerSum': '0 W',
                     'eTotalMoneyText': '1064.8 (€)',
                     'isHaveStorage': 'false',
                     'todayEnergySum': '6.4 kWh',
                     'totalEnergySum': '5.07 MWh'}}

Regards, Derko

muppet3000 commented 2 years ago

Thanks Derko.

Looking at the logic we have in the Home Assistant plugin for "inverter" type systems you should be able to extend your code similar to mine from above, but for your own system:

for plant in plant_list['data']:
  plant_id = plant['plantId']
  plant_info=api.plant_info(plant_id)

  for device in plant_info['deviceList']:
    device_sn = device['deviceSn']
    device_type = device['deviceType']
    print("Device type: %s" % (device_type))

    inverter_info = api.inverter_detail(device_sn)
    pp.pprint(inverter_info)

That will print out ALL values for your 'inverter' system. All of the ones with 'ppv' in the name are to do with Wattage, you can see how they're mapped in the home-assistant plugin here: https://github.com/home-assistant/core/blob/dev/homeassistant/components/growatt_server/sensor_types/inverter.py

Each GrowattSensorEntityDescription is a specific statistic. The api_key value is what it appears on the Growatt API as e.g. ppv1 (line 53) and the name is it's 'human friendly' name e.g. Input 1 Wattage (line 52). I don't know what the specific one is that you're looking for to replace currentPower but I bet it's one of those values, I'm certain that's what the app will be using.

You should be able to run that command now to check what it outputs and then run it again tomorrow when the sun is shining and compare it to the app to work out what the correct value is.

Let me know your results.

muppet3000 commented 2 years ago

@Derko01 I ran my script again today and I can confirm that the currentPower value doesn't appear to work consistently any more:

/current_power_test.py 
Enter username:*************
Enter password:
{   'data': [   {   'currentPower': '0 W',
                    'isHaveStorage': 'false',
                    'plantId': 'XXXXXX',
                    'plantMoneyText': '229.4 ',
                    'plantName': 'growatt',
                    'todayEnergy': '0 kWh',
                    'totalEnergy': '4.59 MWh'}],
    'success': True,
    'totalData': {   'CO2Sum': '1.84 KT',
                     'currentPowerSum': '0 W',
                     'eTotalMoneyText': '229.4 ',
                     'isHaveStorage': 'false',
                     'todayEnergySum': '0 kWh',
                     'totalEnergySum': '4.59 MWh'}}

Device type: mix
PV total wattage - KW: 0.17
PV1      wattage - KW: 0.01
PV2      wattage - KW: 0.17

The API provides values for each PV group (I have two) and then the total is the combined amount. I reckon that's what you need to do, you need to get the values from your specific API call rather than the one at the top level. Let me know how you get on.

Derko01 commented 2 years ago

@muppet3000 It looks as if api-key pac (or pacr, because they show identical values) is what I am looking for. The value of these corresponds to "Huidig vermogen" that I see in the Android APP. Great to see there is far more information to get out of the API. I will change my Python-code so that the correct data is loaded into InfluxDB and my graph is up-tp-date. Now it misses nice little yellow waves. Thank you very much! image

muppet3000 commented 2 years ago

No problem at all @Derko01 I think we should consider this bug as "fixed" now. Ultimately, we (the maintainers of this library) have no control over what the Growatt Servers respond, we've just written wrappers around it. So we have no control over what the currentPower call returns, the important thing is that there is the correct values coming from the relevant API call for each specific type of system.

oantons commented 2 years ago

How do I change Sjord's script to include pac or pacr in the output?