From cba09ffdf6258e858f4bf410e53729ba1d1b2c02 Mon Sep 17 00:00:00 2001 From: Igor Rutka Date: Fri, 5 Jun 2026 11:43:16 +0200 Subject: [PATCH] Disable power limit profile forecasts when optimisation is disabled --- .../ems/manager/EmsOptimisationService.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/ems/src/main/java/org/openremote/extension/ems/manager/EmsOptimisationService.java b/ems/src/main/java/org/openremote/extension/ems/manager/EmsOptimisationService.java index eb2d42d..17a6a9f 100644 --- a/ems/src/main/java/org/openremote/extension/ems/manager/EmsOptimisationService.java +++ b/ems/src/main/java/org/openremote/extension/ems/manager/EmsOptimisationService.java @@ -250,6 +250,11 @@ private void stopOptimisation(String assetId) { if (scheduledFuture != null) { scheduledFuture.cancel(false); } + + services.getAssetPredictedDatapointService().purgeValues(assetId, EmsEnergyOptimisationAsset.POWER_LIMIT_MAXIMUM_PROFILE_MANUAL.getName()); + services.getAssetPredictedDatapointService().purgeValues(assetId, EmsEnergyOptimisationAsset.POWER_LIMIT_MINIMUM_PROFILE_MANUAL.getName()); + services.getAssetPredictedDatapointService().purgeValues(assetId, EmsEnergyOptimisationAsset.POWER_LIMIT_MAXIMUM_PROFILE_TOTAL.getName()); + services.getAssetPredictedDatapointService().purgeValues(assetId, EmsEnergyOptimisationAsset.POWER_LIMIT_MINIMUM_PROFILE_TOTAL.getName()); } private void startGopacsHandler(String contractedEan, String realm, String assetId) { @@ -426,6 +431,11 @@ private void processAttributeEventEmsEnergyOptimisationAsset(AttributeEvent attr // Update power limit maximum profile manual if (attributeName.equals(EmsEnergyOptimisationAsset.POWER_LIMIT_MAXIMUM_PROFILE_MANUAL_INPUT.getName())) { + if (!energyOptimisationAssetsMap.containsKey(assetId)) { + LOG.warning(String.format("%s; Optimisation is disabled. The manual power limit profile has been updated but has not been loaded into the forecast database.", logPrefix)); + return; + } + String powerLimitMaximumProfileManualInput = (String) attributeEvent.getValue().orElse(""); if (powerLimitMaximumProfileManualInput.isBlank()) { @@ -463,6 +473,11 @@ private void processAttributeEventEmsEnergyOptimisationAsset(AttributeEvent attr // Update power limit minimum profile manual if (attributeName.equals(EmsEnergyOptimisationAsset.POWER_LIMIT_MINIMUM_PROFILE_MANUAL_INPUT.getName())) { + if (!energyOptimisationAssetsMap.containsKey(assetId)) { + LOG.warning(String.format("%s; Optimisation is disabled. The manual power limit profile has been updated but has not been loaded into the forecast database.", logPrefix)); + return; + } + String powerLimitMinimumProfileManualInput = (String) attributeEvent.getValue().orElse(""); if (powerLimitMinimumProfileManualInput.isBlank()) {