Skip to content

Commit

Permalink
Added charge_discharge_power register and change power calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
GJSBRT committed Apr 12, 2024
1 parent b0bce65 commit 71fad29
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
11 changes: 5 additions & 6 deletions control/calculations.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,17 @@ func calculateHomeLoad() (float64, error) {
if err != nil {
return 0, err
}
inverterInputPower = inverterInputPower * 1000

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)
if inverterInputPower > powerMeterActivePower {
homeLoad = inverterInputPower - powerMeterActivePower
} else {
homeLoad = powerMeterActivePower - inverterInputPower
}

return homeLoad, nil
Expand Down
1 change: 1 addition & 0 deletions modbus/consts.go → modbus/registers.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ var (
}

luna2000Registers = map[string]Register{
"charge_discharge_power": Register{Namespace: "luna2000", Name: "charge_discharge_power", Fields: map[string]string{}, Address: 37765, Unit: "W", Gain: 1, Quantity: 2, Type: RegisterTypeInt32, Writeable: false},
"running_status_battery_1": Register{Namespace: "luna2000", Name: "running_status", Fields: map[string]string{"battery": "1"}, Address: 37000, Unit: "", Gain: 1, Quantity: 1, Type: RegisterTypeUint16, Writeable: false},
"charging_status_battery_1": Register{Namespace: "luna2000", Name: "charging_status", Fields: map[string]string{"battery": "1"}, Address: 37001, Unit: "W", Gain: 1, Quantity: 2, Type: RegisterTypeInt32, Writeable: false},
"bus_voltage_battery_1": Register{Namespace: "luna2000", Name: "bus_voltage", Fields: map[string]string{"battery": "1"}, Address: 37003, Unit: "V", Gain: 10, Quantity: 1, Type: RegisterTypeUint16, Writeable: false},
Expand Down

0 comments on commit 71fad29

Please sign in to comment.