Skip to content

Commit

Permalink
Change to maximum (dis)charge battery for inverter
Browse files Browse the repository at this point in the history
  • Loading branch information
GJSBRT committed Mar 17, 2024
1 parent c3c534b commit 9a5a09f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
6 changes: 2 additions & 4 deletions control/control.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,7 @@ func (c *Control) Start() {
}
} else {
c.logger.WithFields(logrus.Fields{"inverter": battery.inverter, "battery": battery.battery, "watts": batteryChargeWatts}).Info("Battery is fully charged, stopping charge")
// Charge with zero watts as the stop command doesn't do anything
err := c.modbus.ChangeBatteryForceCharge(battery.inverter, battery.battery, modbus.MODBUS_STATE_BATTERY_FORCIBLE_CHARGE_DISCHARGE_CHARGE, 0)
err := c.modbus.ChangeBatteryForceCharge(battery.inverter, battery.battery, modbus.MODBUS_STATE_BATTERY_FORCIBLE_CHARGE_DISCHARGE_STOP, 0)
if err != nil {
c.errChannel <- err
continue
Expand Down Expand Up @@ -193,8 +192,7 @@ func (c *Control) Start() {
} else {
c.logger.WithFields(logrus.Fields{"inverter": battery.inverter, "battery": battery.battery}).Info("Battery is not required, stopping discharge")

// Charge with zero watts as the stop command doesn't do anything
err := c.modbus.ChangeBatteryForceCharge(battery.inverter, battery.battery, modbus.MODBUS_STATE_BATTERY_FORCIBLE_CHARGE_DISCHARGE_CHARGE, 0)
err := c.modbus.ChangeBatteryForceCharge(battery.inverter, battery.battery, modbus.MODBUS_STATE_BATTERY_FORCIBLE_CHARGE_DISCHARGE_STOP, 0)
if err != nil {
c.errChannel <- err
}
Expand Down
2 changes: 2 additions & 0 deletions modbus/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ var (
"forcible_charge_discharge_battery_1": Register{Namespace: "luna2000", Name: "forcible_charge_discharge", Fields: map[string]string{"battery": "1"}, Address: 47100, Unit: "", Gain: 1, Quantity: 1, Type: RegisterTypeUint16, Writeable: true},
"forcible_charge_power_battery_1": Register{Namespace: "luna2000", Name: "forcible_charge_power", Fields: map[string]string{"battery": "1"}, Address: 47247, Unit: "kW", Gain: 1000, Quantity: 2, Type: RegisterTypeUint32, Writeable: true},
"forcible_discharge_power_battery_1": Register{Namespace: "luna2000", Name: "forcible_discharge_power", Fields: map[string]string{"battery": "1"}, Address: 47249, Unit: "kW", Gain: 1000, Quantity: 2, Type: RegisterTypeUint32, Writeable: true},
"maximum_charge_power_battery": Register{Namespace: "luna2000", Name: "maximum_charge_power", Fields: map[string]string{"battery": "1"}, Address: 47075, Unit: "W", Gain: 1, Quantity: 2, Type: RegisterTypeUint32, Writeable: true},
"maximum_discharge_power_battery": Register{Namespace: "luna2000", Name: "maximum_discharge_power", Fields: map[string]string{"battery": "1"}, Address: 47077, Unit: "W", Gain: 1, Quantity: 2, Type: RegisterTypeUint32, Writeable: true},
}

powerMeterRegisters = map[string]Register{
Expand Down
14 changes: 12 additions & 2 deletions modbus/modbus.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,22 @@ func (m *Modbus) ChangeBatteryForceCharge(inverter string, battery string, state

switch state {
case MODBUS_STATE_BATTERY_FORCIBLE_CHARGE_DISCHARGE_CHARGE:
err = connection.client.WriteUint32(luna2000Registers["forcible_charge_power_battery_1"].Address, uint32(watts))
err = connection.client.WriteUint32(luna2000Registers["maximum_charge_power_battery"].Address, uint32(watts))
if err != nil {
return err
}
case MODBUS_STATE_BATTERY_FORCIBLE_CHARGE_DISCHARGE_DISCHARGE:
err = connection.client.WriteUint32(luna2000Registers["forcible_discharge_power_battery_1"].Address, uint32(watts))
err = connection.client.WriteUint32(luna2000Registers["maximum_discharge_power_battery"].Address, uint32(watts))
if err != nil {
return err
}
case MODBUS_STATE_BATTERY_FORCIBLE_CHARGE_DISCHARGE_STOP:
err = connection.client.WriteUint32(luna2000Registers["maximum_charge_power_battery"].Address, 0)
if err != nil {
return err
}

err = connection.client.WriteUint32(luna2000Registers["maximum_discharge_power_battery"].Address, 0)
if err != nil {
return err
}
Expand Down

0 comments on commit 9a5a09f

Please sign in to comment.