-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved home load calculation to seperate file and changed calculation
- Loading branch information
Showing
2 changed files
with
35 additions
and
8 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package control | ||
|
||
import ( | ||
"gijs.eu/vonkje/metrics" | ||
) | ||
|
||
// calculateHomeLoad calculates the home load based on the active power of the inverter and power meter. | ||
// If the sun is out, the home load is calculated based on the active power of the inverter. | ||
// Many hours have been spent on trying to find a calculation for this any many more will be spent :/. | ||
func calculateHomeLoad() (float64, error) { | ||
var homeLoad float64 | ||
|
||
inverterInputPower, err := metrics.GetMetricLastEntrySum("sun2000", "active_power") | ||
if err != nil { | ||
return 0, err | ||
} | ||
|
||
powerMeterActivePower, err := metrics.GetMetricLastEntrySum("power_meter", "active_power") | ||
if err != nil { | ||
return 0, err | ||
} | ||
|
||
// Calculate home load when sun is out. | ||
homeLoad = (inverterInputPower * 1000) - powerMeterActivePower | ||
|
||
// If sun is not out, calculate home load based on power meter. | ||
if homeLoad < 0 { | ||
homeLoad = powerMeterActivePower - (inverterInputPower * 1000) | ||
} | ||
|
||
return homeLoad, nil | ||
} |
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