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

X3 Hybrid G4 - swapped data #12

Open
darmach opened this issue Nov 23, 2024 · 13 comments · Fixed by #13
Open

X3 Hybrid G4 - swapped data #12

darmach opened this issue Nov 23, 2024 · 13 comments · Fixed by #13

Comments

@darmach
Copy link

darmach commented Nov 23, 2024

Just wanted to tag you @nazar-pc to let you know that it seem in here we have two fields a bit wrong for X3 Hybrid G4.

I worked today on squishykid/solax#178 in the solax library, you can see there in detail what I changed to sort it out. I think it's still worth it to investigate and correct here in api docs if applicable (unless like with that other issue of mine it would make updating this a chore).

The problem in API docs seem to be lines 252-253 here:

Data[86], Data[87] seem to be a total increasing value for FeedInEnergy, same applies to Data[88], Data[89] for ConsumeEnergy.

Also we seem to be missing the following:

  • Data[90], Data[91] as FeedInEnergy_Today
  • Data[92], Data[93] as ConsumedEnergy_Today

In general it would boil down to the below:

            "Feed-in Energy today": (pack_u16(90, 91), DailyTotal(Units.KWH), div100),
            "Consumed Energy today": (pack_u16(92, 93), DailyTotal(Units.KWH), div100),
            "Feed-in Energy total": (pack_u16(86, 87), Total(Units.KWH), div100),
            "Consumed Energy total": (pack_u16(88, 89), Total(Units.KWH), div100),

I can work on fixing this, will open PR once done if you don't mind - let me know if I got something wrong!

@nazar-pc
Copy link
Owner

It looks like this in the app:

                    FeedInEnergy: {value: .01 * ue["a"].bit32(1, t[86], t[87])},
                    ConsumeEnergy: {value: .01 * ue["a"].bit32(1, t[88], t[89])},
bit32: function (e, t, a) {
    if (1 == e) return t + 65536 * a;
    if (0 == e) {
        if (a < 32768) return t + 65536 * a;
        if (a > 32768) return t + 65536 * a - 4294967296
    }
}

With first argument being 1 above simplifies to this:

bit32: function (t, a) {
    return t + 65536 * a;
}

Which is why in pseudo-code I wrote this:

function read32BitUnsigned(a, b) {
  return b + 65536 * a;
}

  FeedInEnergy: read32BitUnsigned(Data[86], Data[87]) / 100,
  ConsumeEnergy: read32BitUnsigned(Data[88], Data[89]) / 100,

Now looking at this I see that the issue is read32BitUnsigned, it should have been this:

function read32BitUnsigned(a, b) {
  return a + 65536 * b;
}

Not sure how I messed that up. Does it result in correct values with that change?

I'll check other places and submit a PR soon, thanks!

@darmach
Copy link
Author

darmach commented Nov 23, 2024

@nazar-pc Oh, I don't think we are talking about the same thing :D from my point of view, the data was just fine.

Just the data in the list for positions 86, 87 and 88, 89 (feed-in and consumed respectably) is the data showing total, increasing, aggregate value for these metrics. That's why it would be nice to rename it, adding _Total,

Meanwhile, the data that I think is missing in your API docs for X3 Hybrid G4 are positions 90,91 and 92,93 (feed-in and consumed respectably) - this one is actual "daily" usage, reset every day. It might not be present in the app, that would explain why it's not in this API docs ;)

(With list positions above - I mean the list of metrics from the local API payload as grabbed off the WiFi dongle.)

@nazar-pc nazar-pc reopened this Nov 23, 2024
@nazar-pc
Copy link
Owner

I see. I guess those entries were not used in the app, hence I had no credible information to go off and I was trying to not make things up.

I wouldn't mind adding them and renaming the already existing names for clarity, but let's have in-line comment that those are not from the app itself (so we will not have similar information for other inverters).

Also I see the latest version is 6.3.0 and I last looked at 0.4.5 in August last year, probably worth extracting the latest version and see what they have in there now.

@nazar-pc
Copy link
Owner

6.3.0 doesn't minify the source code anymore, which makes reading A LOT easier. They still don't mention the other FeedInEnergy variant though.

@darmach
Copy link
Author

darmach commented Nov 23, 2024

Uuuh, now you've got my attention! :D

Do you think we (well, you, It's way above my head) might find some new metrics in the newer app?

I wonder if we might get the metrics for the actual Phase 1/2/3 power pulled from the grid - as said here those called Grid 1/2/3 are actually not what inverter pulls from the grid. The best thing is - the inverter 'know' how much it pulls from the current clamp meter, and it shows it on the LCD display. It might be that the API just not expose that...

(EDIT - the above was response to your previous message, you're just too fast!)

I guess App does not use daily data for feed-in and consumed - tbh, it's not necessary, you could just subtract yesterday's total from current.

@darmach
Copy link
Author

darmach commented Nov 23, 2024

As we're looking at the metrics from two different points of view, just wanted to show you what I get off local API:

curl -sd "?optType=ReadRealTimeData&pwd=<redacted>" -X POST http://192.168.1.10 | jq .Data[85,86,87,88,89,90,91,92]
0
160
0
29850
0
10
0
1090

This represents:

Feed In Total 1.6kWh
Consumed Total 298,5kWh
Feed In Today 0.1kWh
Consumed Today 10,9 kWh

@nazar-pc
Copy link
Owner

For #11 I'm wondering if latest PR fixes the measurements you see, I'm going through latest app version now and will update the docs if there is anything to update

@nazar-pc
Copy link
Owner

Found issue with power for X3 Hybrid G3 as well

@darmach
Copy link
Author

darmach commented Nov 23, 2024

I wonder if value calculation part is right in squishykid/solax library - used in Home Assistant Solax integration

@nazar-pc
Copy link
Owner

nazar-pc commented Nov 23, 2024

Some of it was right, some of it was wrong (two issues were fixed in the today's release for my X1 Hybrid Gen 4). They (Solax engineers) have a very confusing way to represent data structures and mobile app is VERY badly designed IMHO. They don't reuse constants or anything, you literally see indices of random data structures all over the place and there is absolutely no indication of what is what. They don't make life easy for themselves.

I corrected and extended Data1 and Data2 locally, now need to finally decipher how they distinguish between the two because there were reports in the past that inverters were not correctly identified according to current instructions I deciphered.

I wish Solax Power open sourced the app and documentation properly, it is a big benefit to have Home Assistant integration IMHO.

@nazar-pc
Copy link
Owner

So I looked around and... something is clearly missing. The app doesn't know the description of the data fields of my X1 Hybrid Gen4 and when I loaded Android app's UI on my desktop (with a proxy and some slight code changes) it indeed wasn't able to load the data, yet the Android app somehow works 🤯

It is as if there is some kind of translation/conversion in the native code that I can't find despite all attempts. It shouldn't work, yet it does.

There are many inverters missing in the latest version and I don't understand how it can possibly support them all. Also all the EV charger support seems to be gone too 🤔

Pinged Solax again, but don't have high hopes about it. Since the app was compiled as release version I can't do live debugging of it either.

@darmach
Copy link
Author

darmach commented Nov 24, 2024

They (Solax engineers) have a very confusing way to represent data structures and mobile app is VERY badly designed IMHO. They don't reuse constants or anything, you literally see indices of random data structures all over the place and there is absolutely no indication of what is what. They don't make life easy for themselves.

It wouldn't hurt either if in the local API responses they would send a dict with proper key names instead of a hundred or so numebrs... Well, it is what it is :)

Are you getting any replies from solax, is there any dialogue? I've been wondering myself about getting in touch with them.

@nazar-pc
Copy link
Owner

It wouldn't hurt either if in the local API responses they would send a dict with proper key names instead of a hundred or so numebrs...

It is an embedded system, it is probably easier for them to dump it like that.

Are you getting any replies from solax, is there any dialogue? I've been wondering myself about getting in touch with them.

They do respond, though they don't like Open Source as much as I do and don't seem to get the value of their inverters being one of the very few supported out of the box in offline setting by Home Assistant.

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

Successfully merging a pull request may close this issue.

2 participants