MQTT Request and Response#

GbbOptimizer supports request/response queries over MQTT. An external program sends a request and GbbOptimizer replies with data.

Connection#

The external program should connect to MQTT with the following parameters:

ParameterValue
AddressSee MQTT servers
Port8883
Username{PlantId}
Password{PlantToken}
UseTLStrue
ClientIDmust end with _{PlantId}

Topics#

DirectionTopic
Request →{PlantId}/ha_gbb/dataserver/serverrequest
← Response{PlantId}/ha_gbb/dataserver/serverresponse

For backward compatibility the program also handles {PlantId}/dataserver/serverrequest and {PlantId}/dataserver/serverresponse (not recommended).

Error Response#

Any request may return an error:

1
2
3
4
5
{
  "Operation": "xxx",
  "Status": "ERROR",
  "ErrDesc": "error description"
}
FieldTypeDescription
OperationstringOperation from the request
Statusstring"ERROR"
ErrDescstringHuman-readable error description

Available Operations#

REQ RESBatteryForecast_GetChartData Get battery forecast chart data
REQ {PlantId}/ha_gbb/dataserver/serverrequest
RES {PlantId}/ha_gbb/dataserver/serverresponse

Request:

1
{"Operation": "BatteryForecast_GetChartData"}

Response — array of objects in the BatteryForecast_GetChartData field:

FieldTypeDescription
DaydateDay
Hourint (0-23)Hour
StartBattery_PercdecimalSOC at the start of the hour
StartBattery_kWhdecimalkWh at the start (DC)
StartBattery_kWhACdecimalkWh at the start (AC)
PVForecast_Percdecimal?PV forecast (%)
PVForecast_kWhdecimal?PV forecast (kWh DC)
PVForecast_kWhACdecimal?PV forecast (kWh AC)
Loads_Percdecimal?Consumption (%)
Loads_kWhdecimal?Consumption incl. ExtraLoad (kWh DC)
Loads_kWhACdecimal?Consumption (kWh AC)
GridCharge_Percdecimal?Grid charging (%)
GridCharge_kWhdecimal?Grid charging (kWh DC)
GridCharge_kWhACdecimal?Grid charging (kWh AC)
Discharge_Percdecimal?Discharge (%)
Discharge_kWhdecimal?Discharge (kWh DC)
Discharge_kWhACdecimal?Discharge (kWh AC)
EndBattery_PercdecimalSOC at the end of the hour
EndBattery_kWhdecimalkWh at the end (DC)
EndBattery_kWhACdecimalkWh at the end (AC)
EndBattery_Pricedecimal?Value of energy in the battery
Profit_Amountdecimal?Profit amount
FromGrid_kWhdecimal?Grid import
Purchase_Pricedecimal?Purchase price
Purchase_Amountdecimal?Purchase amount
ToGrid_kWhdecimal?Grid export
Sale_Pricedecimal?Sale price
Sale_Amountdecimal?Sale amount
Consumption_kWhdecimal?Consumption (= Loads_kWh)
Consumption_Pricedecimal?Consumption price
Consumption_Amountdecimal?Consumption amount
ExtraLoadsKWdecimal?Extra consumption (total)
ExtraLoadsKW_ElectricVehicledecimal?EV
ExtraLoadsKW_HeatingPumpdecimal?Heat pump
ExtraLoadsKW_Generic1Generic6decimal?Other 1–6
REQ RESHistory_GetHours Get hourly history from the Profits module
REQ {PlantId}/ha_gbb/dataserver/serverrequest
RES {PlantId}/ha_gbb/dataserver/serverresponse

Request — form 1 (date range):

1
{"Operation": "History_GetHours", "FromDate": "2024-01-01", "ToDate": "2024-01-01"}
FieldTypeDescription
Operationstring"History_GetHours"
FromDatedate?Default: today
ToDatedate?Default: today

Request — form 2 (period):

FieldTypeDescription
Operationstring"History_GetHours"
Periodstring"curr_day", "prev_day" or "today_yesterday"
AddPeriodToPropertyint?If 1 → response key with suffix, e.g. "History_Hours_curr_day"

Response — array in History_Hours:

FieldTypeDescription
HourdecimalHour
DaydateDay
FromGrid_kWhdecimal?Grid import
FromGrid2_kWhdecimal?Net-metered import
PurchaseAmountdecimal?Purchase amount
ToGrid_kWhdecimal?Grid export
ToGrid2_kWhdecimal?Net-metered export
SaleAmountdecimal?Sale amount
Consumption_kWhdecimal?Consumption
ConsumptionAmountdecimal?Consumption amount
ProfitAmountdecimal?Profit amount
Solar_kWhdecimal?PV production
ToBattery_kWhdecimal?To battery
SOC_Min / SOC_Maxdecimal?Min/Max SOC
SOC_Start / SOC_Enddecimal?Start / end SOC
BattChange_kWhdecimal?Battery change
LostPower_kWhdecimal?Losses
ChargeFromGrid_kWhdecimal?Charging from grid
ChargeFromPV_kWhdecimal?Charging from PV
DischargeToGrid_kWhdecimal?Discharge to grid
DischargeToLoads_kWhdecimal?Discharge to loads
Start_kWh / End_kWhdecimal?Start / end kWh in battery
ValueStartAmount / ValueEndAmountdecimal?Start / end value
ValueChangeAmountdecimal?Value change
REQ RESHistory_GetDays Get daily history from the Profits module
REQ {PlantId}/ha_gbb/dataserver/serverrequest
RES {PlantId}/ha_gbb/dataserver/serverresponse

Request — form 1:

1
{"Operation": "History_GetDays", "FromDate": "2024-01-01", "ToDate": "2024-01-03"}

Request — form 2:

FieldTypeDescription
Periodstring"curr_month", "prev_month", "curr_year" or "prev_year"
AddPeriodToPropertyint?If 1 → suffix in the response key

Response — identical structure to History_GetHours, but in the History_Days array.

REQ RESHistory_GetMonths Get monthly history from the Profits module
REQ {PlantId}/ha_gbb/dataserver/serverrequest
RES {PlantId}/ha_gbb/dataserver/serverresponse

Request — form 1:

1
{"Operation": "History_GetMonths", "FromYear": 2024, "FromMonth": 1, "ToYear": 2024, "ToMonth": 2}
FieldTypeDescription
FromYear / FromMonthint?Default: current year/month
ToYear / ToMonthint?Default: current year/month

Request — form 2:

FieldTypeDescription
Periodstring"curr_month", "prev_month", "curr_year" or "prev_year"

Response — identical structure plus Year and Month fields, in the History_Months array.