-
-
Notifications
You must be signed in to change notification settings - Fork 676
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
added lgess15 support #17432
Open
texperiri
wants to merge
1
commit into
evcc-io:feat/lgess15
Choose a base branch
from
texperiri:feat/lgess15
base: feat/lgess15
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+152
−35
Open
added lgess15 support #17432
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,9 +27,10 @@ type Com struct { | |
*request.Helper | ||
uri string // URI address of the LG ESS inverter - e.g. "https://192.168.1.28" | ||
authPath string | ||
password string // registration number of the LG ESS Inverter - e.g. "DE2001..." | ||
authKey string // auth_key returned during login and renewed with new login after expiration | ||
dataG func() (EssData8, error) | ||
password string // registration number of the LG ESS Inverter - e.g. "DE2001..." | ||
authKey string // auth_key returned during login and renewed with new login after expiration | ||
essType LgEssType // currently the LG Ess Home 8/10 and Home 15 are supported | ||
dataG func() (EssData, error) | ||
} | ||
|
||
var ( | ||
|
@@ -38,7 +39,7 @@ var ( | |
) | ||
|
||
// GetInstance implements the singleton pattern to handle the access via the authkey to the PCS of the LG ESS HOME system | ||
func GetInstance(uri, registration, password string, cache time.Duration) (*Com, error) { | ||
func GetInstance(uri, registration, password string, cache time.Duration, essType LgEssType) (*Com, error) { | ||
uri = util.DefaultScheme(strings.TrimSuffix(uri, "/"), "https") | ||
|
||
var err error | ||
|
@@ -49,6 +50,7 @@ func GetInstance(uri, registration, password string, cache time.Duration) (*Com, | |
uri: uri, | ||
authPath: UserLoginURI, | ||
password: password, | ||
essType: essType, | ||
} | ||
|
||
if registration != "" { | ||
|
@@ -120,53 +122,99 @@ func (m *Com) Login() error { | |
} | ||
|
||
// Data gives the data read from the pcs. | ||
func (m *Com) Data() (EssData8, error) { | ||
func (m *Com) Data() (EssData, error) { | ||
return m.dataG() | ||
} | ||
|
||
// refreshData reads data from lgess pcs. Tries to re-login if "405" auth_key expired is returned | ||
func (m *Com) refreshData() (EssData8, error) { | ||
func (m *Com) refreshData() (EssData, error) { | ||
var data EssData | ||
var err error | ||
if m.essType == LgEss8 { | ||
var meterResponse MeterResponse8 | ||
if err = refreshDataFromLgess[MeterResponse8](&meterResponse, m); err != nil { | ||
return EssData{}, err | ||
} | ||
essDataFromMeterResponse8(&data, &meterResponse) | ||
} else { | ||
var meterResponse MeterResponse15 | ||
if err = refreshDataFromLgess[MeterResponse15](&meterResponse, m); err != nil { | ||
return EssData{}, err | ||
} | ||
essDataFromMeterResponse15(&data, &meterResponse) | ||
} | ||
|
||
return data, nil | ||
} | ||
|
||
// read data from Lgess, reconnects if session expired | ||
func refreshDataFromLgess[T MeterResponse8 | MeterResponse15](meterResponse *T, m *Com) error { | ||
data := map[string]interface{}{ | ||
"auth_key": m.authKey, | ||
} | ||
|
||
req, err := request.New(http.MethodPost, m.uri+MeterURI, request.MarshalJSON(data), request.JSONEncoding) | ||
if err != nil { | ||
return EssData8{}, err | ||
return err | ||
} | ||
|
||
var resp MeterResponse8 | ||
|
||
if err = m.DoJSON(req, &resp); err != nil { | ||
if err := m.DoJSON(req, meterResponse); err != nil { | ||
// re-login if request returns 405-error | ||
var se request.StatusError | ||
if errors.As(err, &se) && se.StatusCode() == http.StatusMethodNotAllowed { | ||
err = m.Login() | ||
if err = m.Login(); err != nil { | ||
return err | ||
} | ||
|
||
if err == nil { | ||
data["auth_key"] = m.authKey | ||
req, err = request.New(http.MethodPost, m.uri+MeterURI, request.MarshalJSON(data), request.JSONEncoding) | ||
data["auth_key"] = m.authKey | ||
if req, err = request.New(http.MethodPost, m.uri+MeterURI, request.MarshalJSON(data), request.JSONEncoding); err != nil { | ||
return err | ||
} | ||
|
||
if err == nil { | ||
err = m.DoJSON(req, &resp) | ||
if err = m.DoJSON(req, meterResponse); err != nil { | ||
return err | ||
} | ||
} | ||
} | ||
|
||
if err != nil { | ||
return EssData8{}, err | ||
} | ||
return err | ||
} | ||
|
||
res := resp.Statistics | ||
if resp.Direction.IsGridSelling > 0 { | ||
res.GridPower = -res.GridPower | ||
// convert response from LgEss8/10 into interface EssData | ||
func essDataFromMeterResponse8(essData *EssData, meterResponse *MeterResponse8) { | ||
essData.GridPower = meterResponse.Statistics.GridPower | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This feels a bit awkward. An alternative would be to make EssData8 and EssData15 implement a common interface? |
||
essData.PvTotalPower = meterResponse.Statistics.PvTotalPower | ||
essData.BatConvPower = meterResponse.Statistics.BatConvPower | ||
essData.BatUserSoc = meterResponse.Statistics.BatUserSoc | ||
essData.CurrentGridFeedInEnergy = meterResponse.Statistics.CurrentGridFeedInEnergy | ||
essData.CurrentPvGenerationSum = meterResponse.Statistics.CurrentPvGenerationSum | ||
|
||
if meterResponse.Direction.IsGridSelling > 0 { | ||
essData.GridPower = -essData.GridPower | ||
} | ||
|
||
// discharge battery: batPower is positive, charge battery: batPower is negative | ||
if resp.Direction.IsBatteryDischarging == 0 { | ||
res.BatConvPower = -res.BatConvPower | ||
if meterResponse.Direction.IsBatteryDischarging == 0 { | ||
essData.BatConvPower = -essData.BatConvPower | ||
} | ||
} | ||
|
||
return res, nil | ||
// convert response from LgEss15 into interface EssData | ||
func essDataFromMeterResponse15(essData *EssData, meterResponse *MeterResponse15) { | ||
// Ess15 meter gives data in 100W units. | ||
essData.GridPower = float64(meterResponse.Statistics.GridPower * 100) | ||
essData.PvTotalPower = float64(meterResponse.Statistics.PvTotalPower * 100) | ||
essData.BatConvPower = float64(meterResponse.Statistics.BatConvPower * 100) | ||
essData.BatUserSoc = float64(meterResponse.Statistics.BatUserSoc * 100) | ||
essData.CurrentGridFeedInEnergy = float64(0) // data not provided by Ess15 | ||
essData.CurrentPvGenerationSum = float64(0) // data not provided by Ess15 | ||
|
||
if meterResponse.Direction.IsGridSelling > 0 { | ||
essData.GridPower = -essData.GridPower | ||
} | ||
|
||
// discharge battery: batPower is positive, charge battery: batPower is negative | ||
if meterResponse.Direction.IsBatteryDischarging == 0 { | ||
essData.BatConvPower = -essData.BatConvPower | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
template: lg-ess-home-15 | ||
products: | ||
- brand: LG | ||
description: | ||
generic: ESS Home 15 | ||
params: | ||
- name: usage | ||
choice: ["grid", "pv", "battery"] | ||
allinone: true | ||
- name: host | ||
- name: password | ||
help: | ||
en: > | ||
User password, see https://github.com/Morluktom/ioBroker.lg-ess-home/tree/master#getting-the-password. | ||
Alteratively, use registration id for admin login. | ||
de: > | ||
Benutzerpasswort, siehe https://github.com/Morluktom/ioBroker.lg-ess-home/tree/master#getting-the-password. | ||
Alternativ kann die Registriernummer für Administratorlogin verwendet werden. | ||
- name: registration | ||
advanced: true | ||
example: "DE200..." | ||
help: | ||
en: Registration id of the LG ESS HOME inverter. | ||
de: Registriernummer des LG ESS HOME Wechselrichters. | ||
- name: capacity | ||
advanced: true | ||
render: | | ||
type: lgess15 | ||
usage: {{ .usage }} | ||
# uri and password are only required once if multiple lgess usages are defined | ||
uri: https://{{ .host }} | ||
{{- if .password }} | ||
password: {{ .password }} | ||
{{- end }} | ||
{{- if .registration }} | ||
registration: {{ .registration }} | ||
{{- end }} | ||
capacity: {{ .capacity }} # kWh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about
and then call it with