Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Statistics #2

Open
dpoitou-tlse opened this issue Oct 23, 2023 · 3 comments
Open

Statistics #2

dpoitou-tlse opened this issue Oct 23, 2023 · 3 comments
Assignees

Comments

@dpoitou-tlse
Copy link

Hello,
Thanks a lot for your job to retrieve data from solarman.

I used to do it using a connection with the cookies from the browser but it does not work anymore.
In the data that I used to got I had the statistics by day/month/year/total.

By default your script get day and total energy. would it be possible to add month and year statics ?

In the doc SolarmanOpenAPI-global(v1.1.6)-EN.pdf of the API it seems to be possible (sec 3.4) -> historical data
https://globalapi.solarmanpv.com/ device/ v1.0 / historical
=> timeType
Value Type 1. Frame: Frame data
someday 2. Day: Daily statistics
( Less than 30 days) 3. Month:
Monthly statistics ( Less than 12
months) 4. Year:Yearly statistics

Best regards

@dpoitou-tlse
Copy link
Author

Hello
Is there any chance to add these data (month and year) ?

Regards

@hareeshmu
Copy link
Owner

Yeah, I will check it once get some time. Also, feel free to make a pull request if you can modify the mode to add this feature.

@dpoitou-tlse
Copy link
Author

I do know how to make a pull request.

I have modified the following function

def get_device_current_data(url, device_sn, token):
    """
    Return device current data
    :return: current data
    """
    print(f"{time_stamp()}: 🕵️  Fetching data for device: {device_sn}")
    try:
        conn = http.client.HTTPSConnection(url)
        payload = json.dumps({"deviceSn": device_sn})
        headers = {"Content-Type": "application/json", "Authorization": "bearer " + token}
        conn.request("POST", "//device/v1.0/currentData?language=en", payload, headers)
        res = conn.getresponse()
        data = json.loads(res.read())
        
        if device_sn==config["inverterId"] :
            # Get month data
            current_year_month = datetime.now().strftime("%Y-%m")
            payload = json.dumps({"timeType": 3,"startTime": current_year_month,"endTime": current_year_month,"deviceSn": device_sn}) #get current year...
            conn.request("POST", "//device/v1.0/historical?language=en", payload, headers)
            res = conn.getresponse()
            data2 = json.loads(res.read())

            for item in data2['paramDataList'][0]['dataList']:
                item['name'] = f"Month {item['name']}"            
            data['dataList'].extend(data2['paramDataList'][0]['dataList'])
            
            # Get year data
            current_year = datetime.now().year
            payload = json.dumps({"timeType": 4,"startTime": current_year,"endTime": current_year,"deviceSn": device_sn})
            conn.request("POST", "//device/v1.0/historical?language=en", payload, headers)
            res = conn.getresponse()
            data2 = json.loads(res.read())

            for item in data2['paramDataList'][0]['dataList']:
                item['name'] = f"Year {item['name']}"
            data['dataList'].extend(data2['paramDataList'][0]['dataList'])

        print(f"{time_stamp()}: 🔥 Device data received successfully")
        return data
    except Exception as error:  # pylint: disable=broad-except
        print(f"{time_stamp()}: 😡 Unable to fetch device current data: {str(error)}")
        return None

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants