Package org.openremote.manager.energy
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 ClassesModifier and TypeClassDescriptionprotected static class -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final Map<String, EnergyOptimisationService.OptimisationInstance> protected AssetPredictedDatapointServiceprotected AssetProcessingServiceprotected AssetStorageServiceprotected ClientEventServiceprotected ExecutorServiceprotected DateTimeFormatterprotected GatewayServiceprotected static final Loggerprotected org.openremote.container.message.MessageBrokerServiceprotected static final intprotected ScheduledExecutorServiceprotected org.openremote.container.timer.TimerServiceFields inherited from class org.apache.camel.builder.RouteBuilder
logFields inherited from interface org.openremote.model.ContainerService
DEFAULT_PRIORITY, HIGH_PRIORITY, LOW_PRIORITY, MED_PRIORITYFields inherited from interface org.apache.camel.Ordered
HIGHEST, LOWEST -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidcheckTimeoutAndThrow(String optimisationAssetId, long startTimeMillis) voidprotected double[]get24HAttributeValues(String assetId, org.openremote.model.attribute.Attribute<Double> attribute, double intervalSize, int intervalCount, Instant optimisationTime) protected doublegetElectricityStorageAssetEnergyLevelMax(org.openremote.model.asset.impl.ElectricityStorageAsset asset) protected StringgetLogPrefix(String optimisationAssetId) protected static InstantgetOptimisationStartTime(long currentMillis, long periodSeconds) Gets the start time of the interval that the currentMillis value is withinprotected 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 doublegetStorageUnoptimisedImportPower(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 assetvoidinit(org.openremote.model.Container container) protected booleanisElectricityGroupAsset(org.openremote.model.asset.Asset<?> asset) protected voidprocessAssetChange(org.openremote.model.PersistenceEvent<org.openremote.model.asset.impl.EnergyOptimisationAsset> persistenceEvent) protected voidprocessAttributeEvent(org.openremote.model.attribute.AttributeEvent attributeEvent) protected voidprocessOptimisationAssetAttributeEvent(EnergyOptimisationService.OptimisationInstance optimisationInstance, org.openremote.model.attribute.AttributeEvent attributeEvent) protected voidrunOptimisation(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.voidstart(org.openremote.model.Container container) protected voidstartOptimisation(org.openremote.model.asset.impl.EnergyOptimisationAsset optimisationAsset) voidstop(org.openremote.model.Container container) protected voidstopOptimisation(String optimisationAssetId) protected booleanstorageAssetConnected(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, validatorMethods 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, xpathMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.openremote.model.ContainerService
getPriority
-
Field Details
-
LOG
-
OPTIMISATION_TIMEOUT_MILLIS
protected static final int OPTIMISATION_TIMEOUT_MILLIS- See Also:
-
formatter
-
timerService
protected org.openremote.container.timer.TimerService timerService -
assetProcessingService
-
assetStorageService
-
assetPredictedDatapointService
-
messageBrokerService
protected org.openremote.container.message.MessageBrokerService messageBrokerService -
clientEventService
-
gatewayService
-
executorService
-
scheduledExecutorService
-
assetOptimisationInstanceMap
protected final Map<String,EnergyOptimisationService.OptimisationInstance> assetOptimisationInstanceMap -
forceChargeAssetIds
-
-
Constructor Details
-
EnergyOptimisationService
public EnergyOptimisationService()
-
-
Method Details
-
init
- Specified by:
initin interfaceorg.openremote.model.ContainerService- Throws:
Exception
-
start
- Specified by:
startin interfaceorg.openremote.model.ContainerService- Throws:
Exception
-
configure
- Specified by:
configurein classorg.apache.camel.builder.RouteBuilder- Throws:
Exception
-
stop
- Specified by:
stopin interfaceorg.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
-
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
Gets the start time of the interval that the currentMillis value is within -
getLogPrefix
-
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
-
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
-