Skip to content

Commit

Permalink
feat(fronius::schedule): The battery reserve is checked first
Browse files Browse the repository at this point in the history
  • Loading branch information
atbore-phx committed Jan 19, 2025
1 parent 283c3bf commit 0a52154
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions pkg/fronius/fronius_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ func TestBatteryChargeMode5(t *testing.T) {
setup()

result, err := fronius.SetFroniusChargeBatteryMode(1000, 11000, 11000, 9000, 3500, 2500, "00:00", "23:59", modbus_ip, modbus_port)
assert.Equal(int16(31), result, "SetFroniusChargeBatteryMode returned wrong value")
assert.Equal(int16(22), result, "SetFroniusChargeBatteryMode returned wrong value")
assert.NoError(err)

teardown()
Expand Down Expand Up @@ -292,7 +292,7 @@ func TestBatteryChargeError(t *testing.T) {
setup()

result, err := fronius.SetFroniusChargeBatteryMode(1000, 11000, -11000, 9000, 3500, 0, "00:00", "23:59", modbus_ip, modbus_port)
assert.Equal(int16(-72), result, "SetFroniusChargeBatteryMode returned wrong value")
assert.Equal(int16(-200), result, "SetFroniusChargeBatteryMode returned wrong value")
assert.Error(err)

teardown()
Expand Down
8 changes: 4 additions & 4 deletions pkg/fronius/schedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ func SetFroniusChargeBatteryMode(pw_forecast float64, pw_batt2charge float64, pw
var ch_pc int16 = 0
pw_pv_net := pw_forecast - pw_consumption // Net solar power
pw_batt := pw_batt_max - pw_batt2charge // actual battery power
pw_net := pw_batt_reserve + pw_pv_net // net power available (reserve + Net solar power)
pw_net := pw_batt + pw_pv_net // net power available (actual battery power + Net solar power)

switch {
case pw_batt2charge == 0: // battery 100% => do not charge
u.Log.Info("Battery is full charged")
case pw_net < 0 && pw_batt < pw_batt_reserve: // net power is not enough and battery level is under the reserve => charge
u.Log.Infof("Battery is under the reserve and Net Power (battery reserve + Net solar power) is not enough: %f Wh", pw_net)
ch_pc = SetChargePower(pw_batt_max, -1*pw_net, max_charge)
case pw_batt < pw_batt_reserve: // battery is less than reserve => charge
u.Log.Infof("battery %f Wh < reserve %f Wh", pw_batt, pw_batt_reserve)
ch_pc = SetChargePower(pw_batt_max, pw_batt_reserve-pw_batt, max_charge)
case pw_net < 0: // net power is not enough => charge
u.Log.Infof("Net Power (actual battery power + Net solar power) is not enough: %f Wh", pw_net)
ch_pc = SetChargePower(pw_batt_max, -1*pw_net, max_charge)
default: // check if Actual battery is enough, charge oterwise
pw_grid, charge_enabled := ChargeBattery(pw_pv_net, pw_batt)
if charge_enabled {
Expand Down

0 comments on commit 0a52154

Please sign in to comment.