C# IoT Procedures#

GbbOptimizer allows you to create custom procedures in C# that control IoT devices based on forecasts, energy prices, and consumption history.

A procedure must run in no more than 100 ms and must not interfere with the program’s operation. Otherwise it will be suspended.

The App Object#

Each IoT procedure receives an App object as a parameter. The available properties are listed below.

Main Properties#

PropertyTypeDescription
App.CurrDateDateTime?Date for which the device should be turned on/off
App.CurrHourdecimal?Hour (12:30 = 12.5; 12:45 = 12.75)
App.CurrForecastIndexint?Index in App.Forecast for the current date and hour
App.StringVariablesDictionary<string, string?>User string variables (persistent between calls)
App.DecimalVariablesDictionary<string, decimal?>User numeric variables (persistent between calls)

Forecast#

PropertyTypeDescription
App.ForecastIForecast[]Battery forecast array. [0] = current hour, [1] = next hour, etc.
.DateDateTimeForecast date
.DateNoint0 = today, 1 = tomorrow, etc.
.HourdecimalForecast hour
.HourNodecimalHour counted from the start of the forecast ([0].HourNo == 0 always)
.StartBattery_kWhACdecimalkWh in battery (AC) at the start of the hour
.StartBattery_kWhdecimalkWh in battery (DC) at the start of the hour
.Prod_KWhACdecimal?Production (PV + wind) in the given hour
.Loads_kWhACdecimal?Consumption in the given hour
.GridCharge_kWhACdecimal?kWh from grid to battery (grid side)
.GridCharge_kWhdecimal?kWh from grid to battery (battery side)
.Discharge_kWhACdecimal?kWh from battery to grid (grid side)
.Discharge_kWhdecimal?kWh from battery to grid (battery side)
.EndBattery_kWhACdecimal?kWh in battery (AC) at the end of the hour
.EndBattery_kWhdecimal?kWh in battery (DC) at the end of the hour
.Meteo_SOCdecimal?null = no weather warnings; value = target SOC for the warning
.Temperature_Cdecimal?Temperature (°C) in the given hour
.ExtraLoads_kWhdecimal?Total extra loads
.FromGrid_kWhdecimal?kWh from grid
.PurchasePricedecimal?Purchase price
.PurchaseAmountdecimal?Purchase amount
.ToGrid_kWhdecimal?kWh to grid
.SalePricedecimal?Sale price
.SaleAmountdecimal?Sale amount

Prices#

PropertyTypeDescription
App.PricesDictionary<(DateTime, decimal), IPrice>Prices for yesterday, today, and tomorrow
.DayDateTimePrice date
.HourdecimalPrice hour
.PurchasePricedecimal?Purchase price
.SalesPricedecimal?Sale price
.Imported_PurchasePricedecimal?Purchase price imported from price source
.Imported_SalesPricedecimal?Sale price imported from price source

History#

PropertyTypeDescription
App.HistoryIHistory[]Historical data. [0] = hour before current, [1] = two hours before, etc.
.DateDateTimeDate
.HourdecimalHour
.FromGrid_kWhdecimal?kWh from grid
.PurchasePricedecimal?Purchase price
.PurchaseAmountdecimal?Purchase amount
.ToGrid_kWhdecimal?kWh to grid
.SalePricedecimal?Sale price
.SaleAmountdecimal?Sale amount
.Loads_kWhdecimal?Consumption (kWh)
.LoadsPricedecimal?Consumption energy price
.LoadsAmountdecimal?Consumption energy amount
.PV_kWhdecimal?PV production (kWh)
.SOC_Startdecimal?SOC at the start of the hour
.SOC_Enddecimal?SOC at the end of the hour
.ExtraLoads_Pricedecimal?Extra loads price
.ExtraLoads_kWhdecimal?Total extra loads (kWh)

IoT Devices#

PropertyTypeDescription
App.IoTDevicesDictionary<string, IIoTDevice>List of IoT devices
.NamestringDevice name
.IsOnboolCurrent switch state

Special Functions#

FunctionDescription
void App.ToLog(string message)Display a message in the Log menu
bool App.IsInLowerPrices(DateTime CurrDate, decimal CurrHour, int LowerHours, bool Purchase)Is the given hour among the lowest-price hours of the day?
bool App.IsInHigherPrices(DateTime CurrDate, decimal CurrHour, int HigherHours, bool Purchase)Is the given hour among the highest-price hours of the day?

Available Libraries#

  • mscorlib.dll
  • system.runtime.dll
  • System.Text.RegularExpressions.dll
  • system.linq.dll
  • System.Collections.dll

Example#

1
2
3
4
5
public bool IoTDevice_0036_IsOn(IApp App)
{
    return App.IsInLowerPrices(App.CurrDate, App.CurrHour, 3, false)
        || App.Forecast[App.CurrForecastIndex].FromGrid_kWh > 3;
}

This example turns the device on when:

  • The current hour is among the 3 cheapest hours of the day (sale price), or
  • The forecast grid import in the current hour exceeds 3 kWh