CJNE / pymyenergi

An async python library for interfacing with MyEnergi devices
MIT License
19 stars 15 forks source link

Support libbi export to grid #18

Open plord12 opened 9 months ago

plord12 commented 9 months ago

Since libbi 5.408 ( https://support.myenergi.com/hc/en-gb/articles/19276846239377-libbi-Firmware-Version-5-408 ) libbi supports export to grid. This is useful if you wanted to use your libbi to charge by cheap electricity (or solar) and export when export prices are high.

App now supports this :

Screenshot 2023-10-26 at 13 20 15
videojedi commented 9 months ago

Looks like the endpoints are...

to turn on https://s18.myenergi.net/cgi-libbi-mode-L24047041-5

and to turn off https://s18.myenergi.net/cgi-libbi-mode-L24047041-1

plord12 commented 9 months ago

Looks like the endpoints are...

to turn on https://s18.myenergi.net/cgi-libbi-mode-L24047041-5

and to turn off https://s18.myenergi.net/cgi-libbi-mode-L24047041-1

Yes, agreed. ( I was just typing this and you beat me to it ! )

videojedi commented 9 months ago

Early progress

image
plord12 commented 9 months ago

BTW, I don't think the official app displays the discharging status well. Overnight the app looked "good" ( ie asking me if I wanted to start export ) yet it was still in export mode. Battery drained overnight.

So we'll definatly want to see the status in home assistant -

$ myenergi -j libbi show
...
  "batteryDischargingBoost": false,
...
plord12 commented 9 months ago

Also need to fill in some more status. Guessing -

101 - slow charge ? 104 - idle & full 102 - some sort of discharging 12 - charging when in discharge mode

plord12 commented 9 months ago

Also need to fill in some more status. Guessing -

101 - slow charge ? 104 - idle & full 102 - some sort of discharging 12 - charging when in discharge mode

Maybe this helps ( from apk ) -

function F(e) {
    switch (e) {
        case 5:
            return p.LibbiStatus.charging;
        case 6:
            return p.LibbiStatus.discharging;
        case 7:
            return p.LibbiStatus.durationScheduledCharge;
        case 8:
            return p.LibbiStatus.durationScheduledDrain;
        case 11:
            return p.LibbiStatus.stopped;
        case 51:
        case 53:
        case 55:
            return p.LibbiStatus.boosting;
        case 251:
            return p.LibbiStatus.upgradingDSP;
        case 102:
        case 104:
            return p.LibbiStatus.full;
        case 252:
            return p.LibbiStatus.upgradingARM;
        default:
            return p.LibbiStatus.idle
    }
}
plord12 commented 9 months ago

Oh, we also need to add the new charging limit.

PUT https://myaccount.myenergi.com/api/AccountAccess/<serial>/TargetEnergy?targetEnergy=5100 
trizmark commented 9 months ago

I've got all the functionality in https://github.com/trizmark/pymyenergi, which is a fork of https://github.com/mattburns/pymyenergi, which has an open PR (https://github.com/CJNE/pymyenergi/pulls/16) on this repo. Once matthburns merges my PR, the open PR will update here as well and hopefully CJNE will have time to review/merge. I've got a PR ready to go on ha-myenergi as soon as pymyenergi is updated.

BTW, got the full status list from the app source:

    0: "Off",
    1: "On",
    2: "Battery Full",
    4: "Idle",
    5: "Charging",
    6: "Discharging",
    7: "Duration Charging",
    8: "Duration Drain",
    12: "Target Charge",
    51: "Boosting",
    53: "Boosting",
    55: "Boosting",
    11: "Stopped",
    101: "Idle?",
    102: "Full",
    104: "Full",
    151: "FW Upgrade (ARM)",
    156: "FW Upgrade (DSP)",
    234: "Calibration Charge",
    251: "FW Upgrade (DSP)",
    252: "FW Upgrade (ARM)",
trizmark commented 2 months ago

0.2.0 released today, which includes this functionality!