ccremer / fronius-exporter

Prometheus Exporter for Fronius Symo Photovoltaics
Apache License 2.0
20 stars 15 forks source link

Battery SoC for Symo GEN24 #37

Closed frsteinb closed 3 years ago

frsteinb commented 3 years ago

Thank you for sharing your Fronius export code with the community! I have a Symo GEN24 with a BYD HVM battery at its side. It delivers an addition variable to export the battery's SoC. Please feel free to add the following patch to your code. Sorry, I am not familiar enough with Git, GitHub, Docker, so that I prefer to supply my few lines this way instead of a pull request.

diff --git a/metrics.go b/metrics.go
index 098f204..496d842 100644
--- a/metrics.go
+++ b/metrics.go
@@ -27,6 +27,11 @@ var (
                Name:      "inverter_power",
                Help:      "Power flow of the inverter in Watt",
        }, []string{"inverter"})
+       inverterSoCGaugeVec = promauto.NewGaugeVec(prometheus.GaugeOpts{
+               Namespace: namespace,
+               Name:      "inverter_soc",
+               Help:      "State of charge of the battery attached to the inverter in percent",
+       }, []string{"inverter"})

        sitePowerLoadGauge = promauto.NewGauge(prometheus.GaugeOpts{
                Namespace: namespace,
@@ -89,6 +94,7 @@ func parseMetrics(data *fronius.SymoData) {
        log.WithField("data", *data).Debug("Parsing data.")
        for key, inverter := range data.Inverters {
                inverterPowerGaugeVec.WithLabelValues(key).Set(inverter.Power)
+               inverterSoCGaugeVec.WithLabelValues(key).Set(inverter.SoC)
        }
        sitePowerAccuGauge.Set(data.Site.PowerAccu)
        sitePowerGridGauge.Set(data.Site.PowerGrid)
diff --git a/pkg/fronius/symo.go b/pkg/fronius/symo.go
index edd3b97..44f0d2c 100644
--- a/pkg/fronius/symo.go
+++ b/pkg/fronius/symo.go
@@ -49,6 +49,7 @@ type (
        Inverter struct {
                DT          float64 `json:"DT"`
                Power       float64 `json:"P"`
+               SoC         float64 `json:"SOC"`
                EnergyDay   float64 `json:"E_Day"`
                EnergyYear  float64 `json:"E_Year"`
                EnergyTotal float64 `json:"E_Total"`
ccremer commented 3 years ago

Hi! Thanks for raising this issue. Since I don't have a unit with battery, I couldn't really implement this.

Can you provide an example output of the JSON returned by the API? I'd like to double check and add it to the tests. I'm particularly also interested in special cases of the JSON value. e.g. special meaning of null value if any.

You can get raw JSON by simply using curl, e.g. curl http://ip-address/solar_api/v1/GetPowerFlowRealtimeData.fcgi

frsteinb commented 3 years ago

Hi, Chris

$ curl -s /solar_api/v1/GetPowerFlowRealtimeData.fcgi?Scope=System { "Body" : { "Data" : { "Inverters" : { "1" : { "Battery_Mode" : "normal", "DT" : 1, "P" : 435, "SOC" : 80.699996948242188 } }, "Site" : { "BackupMode" : false, "BatteryStandby" : false, "E_Day" : null, "E_Total" : null, "E_Year" : null, "Meter_Location" : "grid", "Mode" : "bidirectional", "P_Akku" : 461.0919189453125, "P_Grid" : -2.2000000000000002, "P_Load" : -433.51423339843751, "P_PV" : 18.371710777282715, "rel_Autonomy" : 100.0, "rel_SelfConsumption" : 99.495081906588027 }, "Version" : "12" } }, "Head" : { "RequestArguments" : { "Scope" : "System" }, "Status" : { "Code" : 0, "Reason" : "", "UserMessage" : "" }, "Timestamp" : "2021-06-26T19:48:22+00:00" } }

Am 26.06.2021 um 21:32 schrieb Chris @.***>:

Hi! Thanks for raising this issue. Since I don't have a unit with battery, I couldn't really implement this.

Can you provide an example output of the JSON returned by the API? I'd like to double check and add it to the tests. I'm particularly also interested in special cases of the JSON value. e.g. special meaning of null value if any.

You can get raw JSON by simply using curl, e.g. curl http://ip-address/solar_api/v1/GetPowerFlowRealtimeData.fcgi

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.

ccremer commented 3 years ago

Thanks for confirming.

Do you know what the value BatteryStandby means? It looks to be only true/false (or 1/0). Would that also be interesting to have as a metric?

frsteinb commented 3 years ago

I don’t know yet. The PV has been installed just yesterday, along with the BYD battery and a wallbox. There are many more things to learn. E.g., I will get a second Fronius Smartmeter attached to Modbus explicitly for monitoring the Wallbox energy output. I expect this to emit additional values via the fronius JSON API. I will keep you informed, when I learn about any new details.

Am 26.06.2021 um 21:57 schrieb Chris @.***>:

Thanks for confirming.

Do you know what the value BatteryStandby means? It looks to be only true/false (or 1/0). Would that also be interesting to have as a metric?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.

ccremer commented 3 years ago

Ok. we can still add more metrics later on. Enjoy your new PV :)