Class EnergyOptimisationService

java.lang.Object
org.apache.camel.builder.BuilderSupport
org.apache.camel.builder.RouteBuilder
org.openremote.manager.energy.EnergyOptimisationService
All Implemented Interfaces:
org.apache.camel.builder.ModelRoutesBuilder, org.apache.camel.CamelContextAware, org.apache.camel.Ordered, org.apache.camel.RoutesBuilder, org.apache.camel.spi.HasCamelContext, org.apache.camel.spi.ResourceAware, org.openremote.model.ContainerService

public class EnergyOptimisationService extends org.apache.camel.builder.RouteBuilder implements org.openremote.model.ContainerService
Handles optimisation instances for EnergyOptimisationAsset.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    protected static class 
     
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
     
     
     
     
     
    protected ExecutorService
     
    protected List<String>
     
     
    protected GatewayService
     
    protected static final Logger
     
    protected org.openremote.container.message.MessageBrokerService
     
    protected static final int
     
     
    protected org.openremote.container.timer.TimerService
     

    Fields inherited from class org.apache.camel.builder.RouteBuilder

    log

    Fields inherited from interface org.openremote.model.ContainerService

    DEFAULT_PRIORITY, HIGH_PRIORITY, LOW_PRIORITY, MED_PRIORITY

    Fields inherited from interface org.apache.camel.Ordered

    HIGHEST, LOWEST
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    checkTimeoutAndThrow(String optimisationAssetId, long startTimeMillis)
     
    void
     
    protected double[]
    get24HAttributeValues(String assetId, org.openremote.model.attribute.Attribute<Double> attribute, double intervalSize, int intervalCount, Instant optimisationTime)
     
    protected double
    getElectricityStorageAssetEnergyLevelMax(org.openremote.model.asset.impl.ElectricityStorageAsset asset)
     
    protected String
    getLogPrefix(String optimisationAssetId)
     
    protected static Instant
    getOptimisationStartTime(long currentMillis, long periodSeconds)
    Gets the start time of the interval that the currentMillis value is within
    protected double[]
    getStoragePowerSetpoints(EnergyOptimisationService.OptimisationInstance optimisationInstance, org.openremote.model.asset.impl.ElectricityStorageAsset storageAsset, double[] normalisedEnergyLevelMins, double[] energyLevelMaxs, double[] powerNets, double[] importPowerLimits, double[] exportPowerLimits, double[] costImports, double[] costExports)
    Returns the power setpoint calculator for the specified asset (for producers power demand will only ever be negative, for consumers it will only ever be positive and for storage assets that support export (i.e.
    protected double
    getStorageUnoptimisedImportPower(EnergyOptimisationService.OptimisationInstance optimisationInstance, String optimisationAssetId, org.openremote.model.asset.impl.ElectricityStorageAsset storageAsset, double energyLevelTarget, double remainingPowerCapacity)
    Gets the un-optimised import power for the first (current) interval for the supplied storage asset
    void
    init(org.openremote.model.Container container)
     
    protected boolean
    isElectricityGroupAsset(org.openremote.model.asset.Asset<?> asset)
     
    protected void
    processAssetChange(org.openremote.model.PersistenceEvent<org.openremote.model.asset.impl.EnergyOptimisationAsset> persistenceEvent)
     
    protected void
    processAttributeEvent(org.openremote.model.attribute.AttributeEvent attributeEvent)
     
    protected void
    processOptimisationAssetAttributeEvent(EnergyOptimisationService.OptimisationInstance optimisationInstance, org.openremote.model.attribute.AttributeEvent attributeEvent)
     
    protected void
    runOptimisation(String optimisationAssetId, Instant optimisationTime)
    Runs the optimisation routine for the specified time; it is important that this method does not throw an exception as it will cancel the scheduled task thus stopping future optimisations.
    protected ScheduledFuture<?>
    scheduleOptimisation(String optimisationAssetId, EnergyOptimiser optimiser, Duration startDuration, long periodSeconds)
    Schedules execution of the optimiser at the start of the interval window with up to 30s of offset randomness added so that multiple optimisers don't all run at exactly the same instance; the interval execution times are calculated relative to the hour.
    void
    start(org.openremote.model.Container container)
     
    protected void
    startOptimisation(org.openremote.model.asset.impl.EnergyOptimisationAsset optimisationAsset)
     
    void
    stop(org.openremote.model.Container container)
     
    protected void
    stopOptimisation(String optimisationAssetId)
     
    protected boolean
    storageAssetConnected(org.openremote.model.asset.impl.ElectricityStorageAsset storageAsset)
     

    Methods inherited from class org.apache.camel.builder.RouteBuilder

    addLifecycleInterceptor, addRoutes, addRoutesToCamelContext, addTemplatedRoutesToCamelContext, bindToRegistry, bindToRegistry, checkInitialized, configuration, configureRest, configureRests, configureRoute, configureRouteConfiguration, configureRoutes, configureRouteTemplate, configureTemplatedRoute, customize, customize, dataFormat, errorHandler, errorHandler, expression, from, from, from, fromF, fromV, fromV, getBeans, getOrder, getResource, getRestCollection, getRestConfiguration, getRests, getRouteCollection, getRoutes, getRouteTemplateCollection, getTemplatedRouteCollection, initializeCamelContext, intercept, interceptFrom, interceptFrom, interceptSendToEndpoint, loadRoutesBuilder, loadRoutesBuilder, onCompletion, onException, onException, populateBeans, populateOrUpdateRoutes, populateRests, populateRoutes, populateRouteTemplates, populateTemplatedRoutes, populateTransformers, populateValidators, prepareModel, property, propertyInject, removeLifecycleInterceptor, rest, rest, restConfiguration, routeTemplate, setErrorHandlerFactory, setResource, setRestCollection, setRouteTemplateCollection, setTemplatedRouteCollection, templatedRoute, tokenizer, toString, transformer, updateRoutesToCamelContext, validator

    Methods inherited from class org.apache.camel.builder.BuilderSupport

    body, bodyAs, constant, constant, constant, createErrorHandlerBuilder, csimple, csimple, datasonnet, datasonnet, datasonnet, deadLetterChannel, deadLetterChannel, defaultErrorHandler, endpoint, endpoint, exceptionMessage, exchangeProperty, expression, getCamelContext, getContext, getErrorHandlerFactory, hasErrorHandlerFactory, header, java, java, joor, joor, jq, jq, jsonpath, jsonpath, jtaTransactionErrorHandler, jtaTransactionErrorHandler, jtaTransactionErrorHandler, method, method, method, method, noErrorHandler, regexReplaceAll, regexReplaceAll, setCamelContext, simple, simple, simpleF, simpleF, springTransactionErrorHandler, springTransactionErrorHandler, springTransactionErrorHandler, systemProperty, systemProperty, variable, xpath, xpath, xpath, xpath

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

    Methods inherited from interface org.openremote.model.ContainerService

    getPriority
  • Field Details

  • Constructor Details

    • EnergyOptimisationService

      public EnergyOptimisationService()
  • Method Details

    • init

      public void init(org.openremote.model.Container container) throws Exception
      Specified by:
      init in interface org.openremote.model.ContainerService
      Throws:
      Exception
    • start

      public void start(org.openremote.model.Container container) throws Exception
      Specified by:
      start in interface org.openremote.model.ContainerService
      Throws:
      Exception
    • configure

      public void configure() throws Exception
      Specified by:
      configure in class org.apache.camel.builder.RouteBuilder
      Throws:
      Exception
    • stop

      public void stop(org.openremote.model.Container container) throws Exception
      Specified by:
      stop in interface org.openremote.model.ContainerService
      Throws:
      Exception
    • processAssetChange

      protected void processAssetChange(org.openremote.model.PersistenceEvent<org.openremote.model.asset.impl.EnergyOptimisationAsset> persistenceEvent)
    • processAttributeEvent

      protected void processAttributeEvent(org.openremote.model.attribute.AttributeEvent attributeEvent)
    • getElectricityStorageAssetEnergyLevelMax

      protected double getElectricityStorageAssetEnergyLevelMax(org.openremote.model.asset.impl.ElectricityStorageAsset asset)
    • processOptimisationAssetAttributeEvent

      protected void processOptimisationAssetAttributeEvent(EnergyOptimisationService.OptimisationInstance optimisationInstance, org.openremote.model.attribute.AttributeEvent attributeEvent)
    • startOptimisation

      protected void startOptimisation(org.openremote.model.asset.impl.EnergyOptimisationAsset optimisationAsset)
    • stopOptimisation

      protected void stopOptimisation(String optimisationAssetId)
    • scheduleOptimisation

      protected ScheduledFuture<?> scheduleOptimisation(String optimisationAssetId, EnergyOptimiser optimiser, Duration startDuration, long periodSeconds) throws IllegalStateException
      Schedules execution of the optimiser at the start of the interval window with up to 30s of offset randomness added so that multiple optimisers don't all run at exactly the same instance; the interval execution times are calculated relative to the hour. e.g. a 0.25h intervalSize (15min) would execute at NN:00+offset, NN:15+offset, NN:30+offset, NN:45+offset...It is important that intervals coincide with any change in supplier tariff so that the optimisation works effectively.
      Throws:
      IllegalStateException
    • getOptimisationStartTime

      protected static Instant getOptimisationStartTime(long currentMillis, long periodSeconds)
      Gets the start time of the interval that the currentMillis value is within
    • getLogPrefix

      protected String getLogPrefix(String optimisationAssetId)
    • checkTimeoutAndThrow

      protected void checkTimeoutAndThrow(String optimisationAssetId, long startTimeMillis) throws TimeoutException
      Throws:
      TimeoutException
    • runOptimisation

      protected void runOptimisation(String optimisationAssetId, Instant optimisationTime) throws Exception
      Runs the optimisation routine for the specified time; it is important that this method does not throw an exception as it will cancel the scheduled task thus stopping future optimisations.
      Throws:
      Exception
    • isElectricityGroupAsset

      protected boolean isElectricityGroupAsset(org.openremote.model.asset.Asset<?> asset)
    • get24HAttributeValues

      protected double[] get24HAttributeValues(String assetId, org.openremote.model.attribute.Attribute<Double> attribute, double intervalSize, int intervalCount, Instant optimisationTime)
    • getStoragePowerSetpoints

      protected double[] getStoragePowerSetpoints(EnergyOptimisationService.OptimisationInstance optimisationInstance, org.openremote.model.asset.impl.ElectricityStorageAsset storageAsset, double[] normalisedEnergyLevelMins, double[] energyLevelMaxs, double[] powerNets, double[] importPowerLimits, double[] exportPowerLimits, double[] costImports, double[] costExports)
      Returns the power setpoint calculator for the specified asset (for producers power demand will only ever be negative, for consumers it will only ever be positive and for storage assets that support export (i.e. supports producer and consumer) it can be positive or negative at a given interval. For this to work the supplied parameters should be updated when the system changes and not replaced so that references maintained by the calculator are valid and up to date.
    • storageAssetConnected

      protected boolean storageAssetConnected(org.openremote.model.asset.impl.ElectricityStorageAsset storageAsset)
    • getStorageUnoptimisedImportPower

      protected double getStorageUnoptimisedImportPower(EnergyOptimisationService.OptimisationInstance optimisationInstance, String optimisationAssetId, org.openremote.model.asset.impl.ElectricityStorageAsset storageAsset, double energyLevelTarget, double remainingPowerCapacity)
      Gets the un-optimised import power for the first (current) interval for the supplied storage asset