diff --git a/pkg/fronius/fronius_test.go b/pkg/fronius/fronius_test.go index 088ce06..503d80c 100644 --- a/pkg/fronius/fronius_test.go +++ b/pkg/fronius/fronius_test.go @@ -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() @@ -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() diff --git a/pkg/fronius/schedule.go b/pkg/fronius/schedule.go index 4e11fda..4ef471f 100644 --- a/pkg/fronius/schedule.go +++ b/pkg/fronius/schedule.go @@ -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 {