Skip to content

armgit / core

Public Imported from GitHub
0

100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps

Energy optimisation bug fix for storage import/export tariffs

Rich Turner955c43d2f61e
diff --git a/manager/src/main/java/org/openremote/manager/energy/EnergyOptimiser.java b/manager/src/main/java/org/openremote/manager/energy/EnergyOptimiser.java
index d5d2e0f99..b4ee35a7e 100644
--- a/manager/src/main/java/org/openremote/manager/energy/EnergyOptimiser.java
+++ b/manager/src/main/java/org/openremote/manager/energy/EnergyOptimiser.java
@@ -671,7 +671,7 @@ public class EnergyOptimiser {
if (powerNet + powerMax > 0d) {
// Can't make tariff flip (we're reducing import hence the -1d)
- return new double[]{-1d * (tariffImport + assetExportCost), powerMax, 0d};
+ return new double[]{(-1d * tariffImport) + assetExportCost, powerMax, 0d};
}
// We can flip tariffs if we export enough power
@@ -679,7 +679,7 @@ public class EnergyOptimiser {
double powerEnd = 0d - powerNet; // Inflection point where switch to export instead of import
// If import was paying then reducing import is a loss in earnings
- double cost = powerEnd * (tariffImport + assetExportCost);
+ double cost = powerEnd * (tariffImport - assetExportCost);
// Is it beneficial to include remaining (-ve export power)
if (tariffExport + assetExportCost < 0d || tariffExport <= (-1d * tariffImport)) {
@@ -729,7 +729,7 @@ public class EnergyOptimiser {
if (powerNet + powerMax < 0d) {
// Can't make tariff flip (we're reducing import hence the -1d)
- return new double[]{-1d * (tariffExport + assetImportCost), powerMin, powerMax};
+ return new double[]{(-1d * tariffExport) + assetImportCost, powerMin, powerMax};
}
// We can flip tariffs if we take enough power
@@ -737,7 +737,7 @@ public class EnergyOptimiser {
double powerEnd = 0d - powerNet; // Inflection point where switch to import instead of export
// If export was paying then reducing export is a loss in earnings i.e. a cost and vice versa hence the -1d
- double cost = -1d * powerEnd * (tariffExport + assetImportCost);
+ double cost = -1d * powerEnd * (tariffExport - assetImportCost);
if (powerMin > powerEnd) {
// We have to flip to meet power req
diff --git a/test/src/test/groovy/org/openremote/test/energy/EnergyOptimisationAssetTest.groovy b/test/src/test/groovy/org/openremote/test/energy/EnergyOptimisationAssetTest.groovy
index c5098d841..053379f8e 100644
--- a/test/src/test/groovy/org/openremote/test/energy/EnergyOptimisationAssetTest.groovy
+++ b/test/src/test/groovy/org/openremote/test/energy/EnergyOptimisationAssetTest.groovy
@@ -119,7 +119,7 @@ class EnergyOptimisationAssetTest extends Specification implements ManagerContai
when: "the optimisation runs"
optimisationService.runOptimisation(managerTestSetup.electricityOptimisationAssetId, optimisationTime)
- then: "the setpoints of the storage asset for the next 24hrs should be correctly optimised [-20.0, 7.0, -20.0, 7.0, 0.0, 7.0, -14.0, 0.0]"
+ then: "the setpoints of the storage asset for the next 24hrs should be correctly optimised"
conditions.eventually {
assert ((ElectricityStorageAsset)assetStorageService.find(managerTestSetup.electricityBatteryAssetId)).getPowerSetpoint().orElse(0d) == 0d
def setpoints = assetPredictedDatapointService.getValueDatapoints(
@@ -139,5 +139,61 @@ class EnergyOptimisationAssetTest extends Specification implements ManagerContai
assert setpoints[5].value == -14d
assert setpoints[6].value == 0d
}
+
+ when: "storage asset import and export tariffs are added to make storage un-viable and optimisation is run"
+ def batteryAsset = ((ElectricityStorageAsset)assetStorageService.find(managerTestSetup.electricityBatteryAssetId))
+ batteryAsset.setTariffExport(10)
+ batteryAsset.setTariffImport(10)
+ batteryAsset = assetStorageService.merge(batteryAsset)
+ optimisationService.runOptimisation(managerTestSetup.electricityOptimisationAssetId, optimisationTime)
+
+ then: "the battery should not be used in any interval"
+ conditions.eventually {
+ assert ((ElectricityStorageAsset)assetStorageService.find(managerTestSetup.electricityBatteryAssetId)).getPowerSetpoint().orElse(0d) == 0d
+ def setpoints = assetPredictedDatapointService.getValueDatapoints(
+ new AttributeRef(managerTestSetup.electricityBatteryAssetId, ElectricityAsset.POWER_SETPOINT.name),
+ "minute",
+ (long)(optimiser.intervalSize * 60) + " minute",
+ LocalDateTime.ofInstant(optimisationTime, ZoneId.systemDefault()).plus((long)(optimiser.intervalSize * 60), ChronoUnit.MINUTES),
+ LocalDateTime.ofInstant(optimisationTime, ZoneId.systemDefault()).plus(1, ChronoUnit.DAYS).minus((long)(optimiser.intervalSize * 60), ChronoUnit.MINUTES)
+ )
+
+ assert setpoints.size() == 7
+ assert setpoints[0].value == 0d
+ assert setpoints[1].value == 0d
+ assert setpoints[2].value == 0d
+ assert setpoints[3].value == 0d
+ assert setpoints[4].value == 0d
+ assert setpoints[5].value == 0d
+ assert setpoints[6].value == 0d
+ }
+
+ when: "storage asset import and export tariffs are modified to make storage viable in limited intervals and optimisation is run"
+ batteryAsset = ((ElectricityStorageAsset)assetStorageService.find(managerTestSetup.electricityBatteryAssetId))
+ batteryAsset.setTariffExport(5)
+ batteryAsset.setTariffImport(5)
+ batteryAsset = assetStorageService.merge(batteryAsset)
+ optimisationService.runOptimisation(managerTestSetup.electricityOptimisationAssetId, optimisationTime)
+
+ then: "the battery should only be used in the correct intervals"
+ conditions.eventually {
+ assert ((ElectricityStorageAsset)assetStorageService.find(managerTestSetup.electricityBatteryAssetId)).getPowerSetpoint().orElse(0d) == 0d
+ def setpoints = assetPredictedDatapointService.getValueDatapoints(
+ new AttributeRef(managerTestSetup.electricityBatteryAssetId, ElectricityAsset.POWER_SETPOINT.name),
+ "minute",
+ (long)(optimiser.intervalSize * 60) + " minute",
+ LocalDateTime.ofInstant(optimisationTime, ZoneId.systemDefault()).plus((long)(optimiser.intervalSize * 60), ChronoUnit.MINUTES),
+ LocalDateTime.ofInstant(optimisationTime, ZoneId.systemDefault()).plus(1, ChronoUnit.DAYS).minus((long)(optimiser.intervalSize * 60), ChronoUnit.MINUTES)
+ )
+
+ assert setpoints.size() == 7
+ assert setpoints[0].value == 0d
+ assert setpoints[1].value == -20d
+ assert setpoints[2].value == 0d
+ assert setpoints[3].value == 0d
+ assert setpoints[4].value == 0d
+ assert setpoints[5].value == 0d
+ assert setpoints[6].value == 0d
+ }
}
}