Skip to content

Commit

Permalink
feat(fronius): tuning
Browse files Browse the repository at this point in the history
  • Loading branch information
atbore-phx committed Mar 2, 2024
1 parent 3301013 commit 0f17e4e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
21 changes: 13 additions & 8 deletions pkg/fronius/configure.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,22 @@ func Setdefaults(modbus_ip string) error {
}

func ForceCharge(modbus_ip string, power_prc int16) error {
regList := mdsc
if power_prc > 0 {
regList := mdsc

regList[StorCtl_Mod] = 2 // Limit Decharging
regList[OutWRte] = -100 * power_prc
regList[StorCtl_Mod] = 2 // Limit Decharging
regList[OutWRte] = -100 * power_prc

OpenModbusClient(modbus_ip)
OpenModbusClient(modbus_ip)

WriteFroniusModbusRegisters(regList)
ReadFroniusModbusRegisters(regList)

ClosemodbusClient()
WriteFroniusModbusRegisters(regList)
ReadFroniusModbusRegisters(regList)

ClosemodbusClient()
} else if power_prc == 0 {
Setdefaults(modbus_ip)
} else {
panic(fmt.Errorf("someting goes wrong when force charging, percent of charging is negative: %d", power_prc))
}
return nil
}
15 changes: 8 additions & 7 deletions pkg/fronius/schedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,26 @@ func SetFroniusChargeBatteryMode(pw_forecast float64, pw_batt2charge float64, pw
var ch_pc int16 = 0
time, _ := CheckTimeRange(start_hr, end_hr)

if !time || pw_batt2charge == 0 { // out of the time range => do not charge
if !time || pw_batt2charge == 0 { // out of the time range or battery 100% => do not charge
fmt.Printf("Out time range start_time: %s - end_time: %s\n", start_hr, end_hr)
Setdefaults(fronius_ip)
} else { // in the time range
pw_pv_net := pw_forecast - pw_consumption
// TODO: we know that from Estimate via Solar API, use that vaule instead.
OpenModbusClient(fronius_ip)
pw_max, _ := ReadFroniusModbusRegister(WChaMax)
ClosemodbusClient()
if pw_pv_net > 0 { // there is pv power available
if pw_pv_net <= 0 { // net pv power is not enough => charge the diff
ch_pc = SetChargePower(float64(pw_max), -1*pw_pv_net, float64(max_charge))
ForceCharge(fronius_ip, ch_pc)
} else { // there is pv power available
pw_grid := pw_batt2charge - pw_pv_net
if pw_grid > 0 { // and it's less than battery capacity to charge => charge the the diff
if pw_grid > 0 { // it's less than the battery's capacity to charge => charge the the diff
ch_pc = SetChargePower(float64(pw_max), pw_grid, float64(max_charge))
ForceCharge(fronius_ip, ch_pc)
} else { // or it is bigger than than battery capacity to charge => do not charge
} else { // it is bigger than than battery capacity to charge => do not charge
Setdefaults(fronius_ip)
}
} else { // or pv power is not enough => charge the diff
ch_pc = SetChargePower(float64(pw_max), -1*pw_pv_net, float64(max_charge))
ForceCharge(fronius_ip, ch_pc)
}
}
return ch_pc, nil
Expand Down

0 comments on commit 0f17e4e

Please sign in to comment.