100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps
Java asset-managementbuildingdashboarddataplatformdevice-managementedge-computingenergyenergy-managementenergy-monitorfleet-managementfleet-telematicsiotiot-applicationiot-platformmodbusmqttmqtt-brokerota-updaterules-enginesmartcity
Updated forecast solar service (#1412)
Igor Rutka623e6a767247
diff --git a/manager/src/main/java/org/openremote/manager/energy/ForecastSolarService.java b/manager/src/main/java/org/openremote/manager/energy/ForecastSolarService.javaindex f2dcdfe6f..aaf7dc936 100644--- a/manager/src/main/java/org/openremote/manager/energy/ForecastSolarService.java+++ b/manager/src/main/java/org/openremote/manager/energy/ForecastSolarService.java@@ -17,8 +17,13 @@ import org.openremote.model.Container;import org.openremote.model.ContainerService;import org.openremote.model.PersistenceEvent;import org.openremote.model.asset.Asset;+import org.openremote.model.asset.AssetFilter;import org.openremote.model.asset.impl.ElectricityProducerSolarAsset;+import org.openremote.model.attribute.Attribute;import org.openremote.model.attribute.AttributeEvent;+import org.openremote.model.attribute.AttributeRef;+import org.openremote.model.datapoint.ValueDatapoint;+import org.openremote.model.datapoint.query.AssetDatapointAllQuery;import org.openremote.model.geo.GeoJSONPoint;import org.openremote.model.query.AssetQuery;import org.openremote.model.syslog.SyslogCategory;@@ -31,7 +36,6 @@ import java.time.format.DateTimeFormatter;import java.time.format.DateTimeFormatterBuilder;import java.util.*;import java.util.concurrent.ScheduledExecutorService;-import java.util.concurrent.ScheduledFuture;import java.util.concurrent.TimeUnit;import java.util.concurrent.atomic.AtomicReference;import java.util.logging.Level;@@ -87,7 +91,7 @@ public class ForecastSolarService extends RouteBuilder implements ContainerServiprotected static final AtomicReference<ResteasyClient> resteasyClient = new AtomicReference<>();protected ResteasyWebTarget forecastSolarTarget;private String forecastSolarApiKey;- private final Map<String, ScheduledFuture<?>> calculationFutures = new HashMap<>();+ private final Map<String, ElectricityProducerSolarAsset> electricityProducerSolarAssetMap = new HashMap<>();@SuppressWarnings("unchecked")@Override@@ -128,7 +132,7 @@ public class ForecastSolarService extends RouteBuilder implements ContainerServicontainer.getService(MessageBrokerService.class).getContext().addRoutes(this);// Load all enabled producer solar assets- LOG.fine("Loading producer solar assets...");+ LOG.fine("Loading electricity producer solar assets...");List<ElectricityProducerSolarAsset> electricityProducerSolarAssets = assetStorageService.findAll(new AssetQuery()@@ -139,19 +143,26 @@ public class ForecastSolarService extends RouteBuilder implements ContainerServi.filter(electricityProducerSolarAsset -> electricityProducerSolarAsset.isIncludeForecastSolarService().orElse(false)).toList();- LOG.fine("Found includes producer solar asset count = " + electricityProducerSolarAssets.size());+ LOG.fine("Number of electricity producer solar assets with forecast enabled = " + electricityProducerSolarAssets.size());- electricityProducerSolarAssets.forEach(this::startProcessing);+ for (ElectricityProducerSolarAsset electricityProducerSolarAsset : electricityProducerSolarAssets) {+ electricityProducerSolarAssetMap.put(electricityProducerSolarAsset.getId(), electricityProducerSolarAsset);+ getSolarForecast(electricityProducerSolarAsset);+ updateSolarForecastAttribute(electricityProducerSolarAsset);+ }++ // Start forecast solar thread+ executorService.scheduleAtFixedRate(this::processSolarData, 1, 1, TimeUnit.MINUTES);clientEventService.addInternalSubscription(AttributeEvent.class,- null,- this::processAttributeEvent);+ new AssetFilter<AttributeEvent>().setAssetClasses(Collections.singletonList(ElectricityProducerSolarAsset.class)),+ this::processElectricityProducerSolarAssetAttributeEvent);}@Overridepublic void stop(Container container) throws Exception {- new ArrayList<>(calculationFutures.keySet()).forEach(this::stopProcessing);+ executorService.shutdown();}protected static void initClient() {@@ -162,144 +173,258 @@ public class ForecastSolarService extends RouteBuilder implements ContainerServi}}- protected void processAttributeEvent(AttributeEvent attributeEvent) {- processElectricityProducerSolarAssetAttributeEvent(attributeEvent);- }-protected synchronized void processElectricityProducerSolarAssetAttributeEvent(AttributeEvent attributeEvent) {+ String attributeName = attributeEvent.getName();- if (ElectricityProducerSolarAsset.POWER.getName().equals(attributeEvent.getName())- || ElectricityProducerSolarAsset.POWER_FORECAST.getName().equals(attributeEvent.getName())) {- // These are updated by this service+ // These are updated by this service+ if (ElectricityProducerSolarAsset.POWER.getName().equals(attributeName)+ || ElectricityProducerSolarAsset.POWER_FORECAST.getName().equals(attributeName)) {return;}- if (attributeEvent.getName().equals(ElectricityProducerSolarAsset.INCLUDE_FORECAST_SOLAR_SERVICE.getName())) {- boolean enabled = (Boolean)attributeEvent.getValue().orElse(false);- if (enabled && calculationFutures.containsKey(attributeEvent.getId())) {- // Nothing to do here- return;- } else if (!enabled && !calculationFutures.containsKey(attributeEvent.getId())) {- // Nothing to do here- return;- }-- LOG.fine("Processing producer solar asset attribute event: " + attributeEvent);- stopProcessing(attributeEvent.getId());+ // Set power attribute value with power forecast attribute value+ if (attributeName.equals(ElectricityProducerSolarAsset.SET_ACTUAL_SOLAR_VALUE_WITH_FORECAST.getName())) {+ boolean enabled = (Boolean) attributeEvent.getValue().orElse(false);// Get latest asset from storageElectricityProducerSolarAsset asset = (ElectricityProducerSolarAsset) assetStorageService.find(attributeEvent.getId());- if (asset != null && asset.isIncludeForecastSolarService().orElse(false)) {- startProcessing(asset);+ if (asset != null && enabled) {+ assetProcessingService.sendAttributeEvent(new AttributeEvent(asset.getId(), ElectricityProducerSolarAsset.POWER, asset.getPowerForecast().orElse(null)), getClass().getSimpleName());+ } else if (asset != null) {+ assetProcessingService.sendAttributeEvent(new AttributeEvent(asset.getId(), ElectricityProducerSolarAsset.POWER, null), getClass().getSimpleName());}+ return;}- if (attributeEvent.getName().equals(ElectricityProducerSolarAsset.SET_ACTUAL_SOLAR_VALUE_WITH_FORECAST.getName())) {+ // Enable solar forecast+ if (attributeName.equals(ElectricityProducerSolarAsset.INCLUDE_FORECAST_SOLAR_SERVICE.getName())) {+ boolean enabled = (Boolean) attributeEvent.getValue().orElse(false);++ if (enabled && !electricityProducerSolarAssetMap.containsKey(attributeEvent.getId())) {+ LOG.info(String.format("Enabled solar forecast for ElectricityProducerSolarAsset: name='%s', ID='%s';", attributeEvent.getAssetName(), attributeEvent.getId()));++ // Get latest asset from storage+ ElectricityProducerSolarAsset asset = (ElectricityProducerSolarAsset) assetStorageService.find(attributeEvent.getId());++ if (asset != null) {+ electricityProducerSolarAssetMap.put(asset.getId(), asset);+ getSolarForecast(asset);+ updateSolarForecastAttribute(asset);+ }+ } else if (!enabled && electricityProducerSolarAssetMap.containsKey(attributeEvent.getId())) {+ LOG.info(String.format("Disabled solar forecast for ElectricityProducerSolarAsset: name='%s', ID='%s';", attributeEvent.getAssetName(), attributeEvent.getId()));+ electricityProducerSolarAssetMap.remove(attributeEvent.getId());+ }+ }++ // Update solar forecast+ if (attributeName.equals(ElectricityProducerSolarAsset.PANEL_AZIMUTH.getName()) ||+ attributeName.equals(ElectricityProducerSolarAsset.PANEL_PITCH.getName()) ||+ attributeName.equals(ElectricityProducerSolarAsset.POWER_EXPORT_MAX.getName()) ||+ attributeName.equals(ElectricityProducerSolarAsset.LOCATION.getName())) {// Get latest asset from storageElectricityProducerSolarAsset asset = (ElectricityProducerSolarAsset) assetStorageService.find(attributeEvent.getId());- // Check if power is currently zero and set it if power forecast has an value- if (asset.getPower().orElse(0d) == 0d && asset.getPowerForecast().orElse(0d) != 0d) {- assetProcessingService.sendAttributeEvent(new AttributeEvent(asset.getId(), ElectricityProducerSolarAsset.POWER, asset.getPowerForecast().orElse(0d)), getClass().getSimpleName());+ if (asset != null && asset.isIncludeForecastSolarService().orElse(false)) {+ ElectricityProducerSolarAsset assetPrevious = electricityProducerSolarAssetMap.get(asset.getId());++ String valueStr = attributeEvent.getValue().toString();+ String valuePreviousStr = assetPrevious.getAttributes().get(attributeEvent.getName()).flatMap(Attribute::getValue).toString();++ // Only update solar forecast on attribute value change+ if (!valueStr.equals(valuePreviousStr)) {+ Object value = attributeEvent.getValue().orElse(null);++ if (attributeName.equals(ElectricityProducerSolarAsset.PANEL_AZIMUTH.getName())) {+ asset.setPanelAzimuth((Integer) value);+ } else if (attributeName.equals(ElectricityProducerSolarAsset.PANEL_PITCH.getName())) {+ asset.setPanelPitch((Integer) value);+ } else if (attributeName.equals(ElectricityProducerSolarAsset.POWER_EXPORT_MAX.getName())) {+ asset.setPowerExportMax((Double) value);+ } else if (attributeName.equals(ElectricityProducerSolarAsset.LOCATION.getName())) {+ asset.setLocation((GeoJSONPoint) value);+ }++ getSolarForecast(asset);+ updateSolarForecastAttribute(asset);+ }+ electricityProducerSolarAssetMap.put(asset.getId(), asset);}}}protected void processAssetChange(PersistenceEvent<ElectricityProducerSolarAsset> persistenceEvent) {LOG.fine("Processing producer solar asset change: " + persistenceEvent);- stopProcessing(persistenceEvent.getEntity().getId());-- if (persistenceEvent.getCause() != PersistenceEvent.Cause.DELETE) {- if (persistenceEvent.getEntity().isIncludeForecastSolarService().orElse(false)- && persistenceEvent.getEntity().getLocation().isPresent()) {- startProcessing(persistenceEvent.getEntity());- }+ // Remove asset from solar forecast map on asset deletion+ if (persistenceEvent.getCause() == PersistenceEvent.Cause.DELETE) {+ electricityProducerSolarAssetMap.remove(persistenceEvent.getEntity().getId());}}- protected void startProcessing(ElectricityProducerSolarAsset electricityProducerSolarAsset) {- LOG.fine("Starting calculation for producer solar asset: " + electricityProducerSolarAsset);- calculationFutures.put(electricityProducerSolarAsset.getId(), executorService.scheduleAtFixedRate(() -> {- processSolarData(electricityProducerSolarAsset);- }, 0, 1, TimeUnit.HOURS));- }- protected void stopProcessing(String electricityProducerSolarAssetId) {- ScheduledFuture<?> scheduledFuture = calculationFutures.remove(electricityProducerSolarAssetId);- if (scheduledFuture != null) {- LOG.fine("Stopping calculation for producer solar asset: " + electricityProducerSolarAssetId);- scheduledFuture.cancel(false);+ protected void processSolarData() {+ // Check if there are any electricity producer solar assets to process+ if (electricityProducerSolarAssetMap.isEmpty()) {+ return;+ }++ int currentMinute = LocalDateTime.now().getMinute();++ // Update solar forecast every hour+ if (currentMinute == 0) {+ electricityProducerSolarAssetMap.forEach((assetId, electricityProducerSolarAsset) -> getSolarForecast(electricityProducerSolarAsset));+ }++ // Update solar power forecast attribute every 15 minutes+ if ((currentMinute % 15) == 0) {+ electricityProducerSolarAssetMap.forEach((assetId, electricityProducerSolarAsset) -> updateSolarForecastAttribute(electricityProducerSolarAsset));}}- protected void processSolarData(ElectricityProducerSolarAsset electricityProducerSolarAsset) {+ protected void getSolarForecast(ElectricityProducerSolarAsset electricityProducerSolarAsset) {Optional<Double> lat = electricityProducerSolarAsset.getAttribute(Asset.LOCATION).flatMap(attr -> attr.getValue().map(GeoJSONPoint::getY));Optional<Double> lon = electricityProducerSolarAsset.getAttribute(Asset.LOCATION).flatMap(attr -> attr.getValue().map(GeoJSONPoint::getX));Optional<Integer> pitch = electricityProducerSolarAsset.getPanelPitch();Optional<Integer> azimuth = electricityProducerSolarAsset.getPanelAzimuth();Optional<Double> kwp = electricityProducerSolarAsset.getPowerExportMax();- if (lat.isPresent() && lon.isPresent() && pitch.isPresent() && azimuth.isPresent() && kwp.isPresent()) {- try (Response response = forecastSolarTarget- .path(String.format("%f/%f/%d/%d/%f", lat.get(), lon.get(), pitch.get(), azimuth.get(), kwp.get()))- .request()- .build("GET")- .invoke()) {- if (response != null && response.getStatus() == 200) {- EstimateResponse responseModel = response.readEntity(EstimateResponse.class);- if (responseModel != null) {- // Forecast date time is ISO8601 without 'T' so needs special formatter- LocalDateTime now = LocalDateTime.ofInstant(Instant.ofEpochMilli(timerService.getCurrentTimeMillis()), ZoneId.systemDefault());- LocalDateTime previousTimestamp = null;- boolean setActualValuePower = electricityProducerSolarAsset.isSetActualSolarValueWithForecast().orElse(false);- boolean setActualValueForecastPower = true;-- for (Map.Entry<String, Double> wattItem : responseModel.result.watts.entrySet()) {- LocalDateTime timestamp = LocalDateTime.parse(wattItem.getKey(), ISO_LOCAL_DATE_TIME_WITHOUT_T);-- assetPredictedDatapointService.updateValue(electricityProducerSolarAsset.getId(), ElectricityProducerSolarAsset.POWER_FORECAST.getName(), -wattItem.getValue() / 1000, timestamp);- assetPredictedDatapointService.updateValue(electricityProducerSolarAsset.getId(), ElectricityProducerSolarAsset.POWER.getName(), -wattItem.getValue() / 1000, timestamp);-- if (setActualValueForecastPower && timestamp.isAfter(now)) {- assetProcessingService.sendAttributeEvent(new AttributeEvent(electricityProducerSolarAsset.getId(), ElectricityProducerSolarAsset.POWER_FORECAST, -wattItem.getValue() / 1000), getClass().getSimpleName());- setActualValueForecastPower = false;-- if (setActualValuePower) {- assetProcessingService.sendAttributeEvent(new AttributeEvent(electricityProducerSolarAsset.getId(), ElectricityProducerSolarAsset.POWER, -wattItem.getValue() / 1000), getClass().getSimpleName());- setActualValuePower = false;- }- }- if (previousTimestamp != null && !previousTimestamp.toLocalDate().equals(timestamp.toLocalDate())) {- while (previousTimestamp.isBefore(timestamp)) {- previousTimestamp = previousTimestamp.plusMinutes(15);- assetPredictedDatapointService.updateValue(electricityProducerSolarAsset.getId(), ElectricityProducerSolarAsset.POWER_FORECAST.getName(), -wattItem.getValue() / 1000, previousTimestamp);- assetPredictedDatapointService.updateValue(electricityProducerSolarAsset.getId(), ElectricityProducerSolarAsset.POWER.getName(), -wattItem.getValue() / 1000, previousTimestamp);- }- }- previousTimestamp = timestamp;- }- rulesService.fireDeploymentsWithPredictedDataForAsset(electricityProducerSolarAsset.getId());++ if (lat.isEmpty() || lon.isEmpty() || pitch.isEmpty() || azimuth.isEmpty() || kwp.isEmpty()) {+ LOG.warning(String.format("ElectricityProducerSolarAsset: name='%s', ID='%s' doesn't have all needed attributes filled in;" ++ " latitude='%s', longitude='%s', panelAzimuth='%s', panelPitch='%s', powerExportMax='%s'",+ electricityProducerSolarAsset.getName(), electricityProducerSolarAsset.getId(), lat, lon, azimuth, pitch, kwp));+ return;+ }++ try (Response response = forecastSolarTarget+ .path(String.format("%f/%f/%d/%d/%f", lat.get(), lon.get(), pitch.get(), azimuth.get(), kwp.get()))+ .request()+ .build("GET")+ .invoke()) {+ if (response != null && response.getStatus() == 200) {+ EstimateResponse responseModel = response.readEntity(EstimateResponse.class);++ if (responseModel != null) {+ HashMap<LocalDateTime, Double> solarForecast = new HashMap<>();+ HashMap<LocalDateTime, Double> solarForecastPrevious = new HashMap<>();++ // Get previous solar forecast from database+ List<ValueDatapoint> solarForecastListPrevious = assetPredictedDatapointService.getDatapoints(new AttributeRef(electricityProducerSolarAsset.getId(), ElectricityProducerSolarAsset.POWER_FORECAST.getName()));++ for (ValueDatapoint datapoint : solarForecastListPrevious) {+ LocalDateTime dateTime = LocalDateTime.ofInstant(Instant.ofEpochMilli(datapoint.getTimestamp()), ZoneId.systemDefault());+ Double powerKiloWatt = (Double) datapoint.getValue();+ solarForecastPrevious.put(dateTime, powerKiloWatt);}- } else {- StringBuilder message = new StringBuilder("Unknown");- if (response != null) {- message.setLength(0);- message.append("Status ");- message.append(response.getStatus());- message.append(" - ");- message.append(response.readEntity(String.class));++ // Get start and end dateTime of solar forecast+ String minKey = responseModel.result.watts.keySet().stream().min(String::compareTo).orElse("");+ String maxKey = responseModel.result.watts.keySet().stream().max(String::compareTo).orElse("");+ LocalDateTime startDateTime = LocalDateTime.parse(minKey, ISO_LOCAL_DATE_TIME_WITHOUT_T).toLocalDate().atStartOfDay();+ LocalDateTime endDateTime = LocalDateTime.parse(maxKey, ISO_LOCAL_DATE_TIME_WITHOUT_T).toLocalDate().plusDays(1).atStartOfDay();++ // Prepopulate solar forecast map with 15-minute intervals+ for (LocalDateTime dateTime = startDateTime; !dateTime.isAfter(endDateTime); dateTime = dateTime.plusMinutes(15)) {+ solarForecast.put(dateTime, 0.0);}- LOG.warning("Request failed: " + message);++ // Add solar forecast to solar forecast map+ for (Map.Entry<String, Double> wattItem : responseModel.result.watts.entrySet()) {+ LocalDateTime dateTime = LocalDateTime.parse(wattItem.getKey(), ISO_LOCAL_DATE_TIME_WITHOUT_T);+ Double powerKiloWatt = -wattItem.getValue() / 1000;+ solarForecast.put(dateTime, powerKiloWatt);+ }++ LocalDateTime currentDateTime = LocalDateTime.ofInstant(Instant.ofEpochMilli(timerService.getCurrentTimeMillis()), ZoneId.systemDefault());++ // Update solar forecast in database+ solarForecast.forEach((dateTime, powerKiloWatt) -> {+ if (dateTime.isAfter(currentDateTime) || solarForecastPrevious.get(dateTime) == null) {+ assetPredictedDatapointService.updateValue(electricityProducerSolarAsset.getId(), ElectricityProducerSolarAsset.POWER_FORECAST.getName(), powerKiloWatt, dateTime);+ assetPredictedDatapointService.updateValue(electricityProducerSolarAsset.getId(), ElectricityProducerSolarAsset.POWER.getName(), powerKiloWatt, dateTime);+ }+ });}- } catch (Throwable e) {- if (e.getCause() != null && e.getCause() instanceof IOException) {- LOG.log(Level.SEVERE, "Exception when requesting forecast solar data", e.getCause());- } else {- LOG.log(Level.SEVERE, "Exception when requesting forecast solar data", e);+ rulesService.fireDeploymentsWithPredictedDataForAsset(electricityProducerSolarAsset.getId());+ } else {+ StringBuilder message = new StringBuilder("Unknown");+ if (response != null) {+ message.setLength(0);+ message.append("Status ");+ message.append(response.getStatus());+ message.append(" - ");+ message.append(response.readEntity(String.class));}+ LOG.warning("Request failed: " + message);}+ } catch (Throwable e) {+ if (e.getCause() != null && e.getCause() instanceof IOException) {+ LOG.log(Level.SEVERE, "Exception when requesting forecast solar data", e.getCause());+ } else {+ LOG.log(Level.SEVERE, "Exception when requesting forecast solar data", e);+ }+ }+ }++ protected void updateSolarForecastAttribute(ElectricityProducerSolarAsset electricityProducerSolarAsset) {+ Optional<Double> lat = electricityProducerSolarAsset.getAttribute(Asset.LOCATION).flatMap(attr -> attr.getValue().map(GeoJSONPoint::getY));+ Optional<Double> lon = electricityProducerSolarAsset.getAttribute(Asset.LOCATION).flatMap(attr -> attr.getValue().map(GeoJSONPoint::getX));+ Optional<Integer> pitch = electricityProducerSolarAsset.getPanelPitch();+ Optional<Integer> azimuth = electricityProducerSolarAsset.getPanelAzimuth();+ Optional<Double> kwp = electricityProducerSolarAsset.getPowerExportMax();++ if (lat.isEmpty() || lon.isEmpty() || pitch.isEmpty() || azimuth.isEmpty() || kwp.isEmpty()) {+ return;+ }++ // Get solar forecast data-points for current 15 minute interval+ long currentTimeMillis = timerService.getCurrentTimeMillis();+ long startTimeMillis = currentTimeMillis - currentTimeMillis % (15 * 60000);+ long endTimeMillis = startTimeMillis + 15 * 60000;+ AssetDatapointAllQuery assetDatapointQuery = new AssetDatapointAllQuery(startTimeMillis, endTimeMillis);+ List<ValueDatapoint<?>> solarForecastDatapoints = assetPredictedDatapointService.queryDatapoints(electricityProducerSolarAsset.getId(), ElectricityProducerSolarAsset.POWER_FORECAST.getName(), assetDatapointQuery);++ if (solarForecastDatapoints == null || solarForecastDatapoints.size() < 2) {+ LOG.warning(String.format("ElectricityProducerSolarAsset: name='%s', ID='%s' doesn't have a solar forecast", electricityProducerSolarAsset.getName(), electricityProducerSolarAsset.getId()));+ return;+ }++ ValueDatapoint<?> solarForecastDatapointMax = solarForecastDatapoints.get(0);+ ValueDatapoint<?> solarForecastDatapointMin = solarForecastDatapoints.get(solarForecastDatapoints.size() - 1);++ // Get current timestamp of power forecast attribute+ ElectricityProducerSolarAsset asset = (ElectricityProducerSolarAsset) assetStorageService.find(electricityProducerSolarAsset.getId());+ long powerForecastAttributeTimeMillis = asset.getAttributes().get(ElectricityProducerSolarAsset.POWER_FORECAST).flatMap(Attribute::getTimestamp).orElse(0L);++ // Update power forecast attribute value+ Double powerKiloWatt;+ long timeMillis;++ if (solarForecastDatapointMin.getTimestamp() > powerForecastAttributeTimeMillis) {+ powerKiloWatt = (Double) solarForecastDatapointMin.getValue();+ timeMillis = solarForecastDatapointMin.getTimestamp();} else {- LOG.warning(String.format("Asset %s doesn't have all needed attributes filled in", electricityProducerSolarAsset.getId()));+ long upperTimestamp = solarForecastDatapointMax.getTimestamp();+ long lowerTimestamp = solarForecastDatapointMin.getTimestamp();+ Double upperValue = (Double) solarForecastDatapointMax.getValue();+ Double lowerValue = (Double) solarForecastDatapointMin.getValue();++ if (upperValue == null || lowerValue == null) {+ return;+ }++ // Interpolate value+ double factor = (double) (currentTimeMillis - lowerTimestamp) / (upperTimestamp - lowerTimestamp);+ double interpolatedValue = lowerValue + factor * (upperValue - lowerValue);+ powerKiloWatt = Math.round(interpolatedValue * 1000.0) / 1000.0;+ timeMillis = currentTimeMillis;+ }++ // Update attributes+ assetProcessingService.sendAttributeEvent(new AttributeEvent(electricityProducerSolarAsset.getId(), ElectricityProducerSolarAsset.POWER_FORECAST.getName(), powerKiloWatt, timeMillis));++ if (electricityProducerSolarAsset.isSetActualSolarValueWithForecast().orElse(false)) {+ assetProcessingService.sendAttributeEvent(new AttributeEvent(electricityProducerSolarAsset.getId(), ElectricityProducerSolarAsset.POWER.getName(), powerKiloWatt, timeMillis));}}}diff --git a/model/src/main/java/org/openremote/model/asset/impl/ElectricityProducerAsset.java b/model/src/main/java/org/openremote/model/asset/impl/ElectricityProducerAsset.javaindex 5080c6aec..f4844fc60 100644--- a/model/src/main/java/org/openremote/model/asset/impl/ElectricityProducerAsset.java+++ b/model/src/main/java/org/openremote/model/asset/impl/ElectricityProducerAsset.java@@ -20,7 +20,9 @@package org.openremote.model.asset.impl;import org.openremote.model.asset.AssetDescriptor;+import org.openremote.model.attribute.MetaItem;import org.openremote.model.value.AttributeDescriptor;+import org.openremote.model.value.MetaItemType;import org.openremote.model.value.ValueType;import jakarta.persistence.Entity;@@ -43,7 +45,8 @@ public class ElectricityProducerAsset extends ElectricityAsset<ElectricityProducpublic static final AttributeDescriptor<Double> TARIFF_EXPORT = ElectricitySupplierAsset.TARIFF_EXPORT.withOptional(true);public static final AttributeDescriptor<Double> CARBON_IMPORT = ElectricitySupplierAsset.CARBON_IMPORT.withOptional(true);- public static final AttributeDescriptor<Double> POWER_FORECAST = new AttributeDescriptor<>("powerForecast", ValueType.NUMBER+ public static final AttributeDescriptor<Double> POWER_FORECAST = new AttributeDescriptor<>("powerForecast", ValueType.NUMBER,+ new MetaItem<>(MetaItemType.READ_ONLY)).withUnits(UNITS_KILO, UNITS_WATT);public static final AssetDescriptor<ElectricityProducerAsset> DESCRIPTOR = new AssetDescriptor<>("flash", "EABB4D", ElectricityProducerAsset.class);diff --git a/model/src/main/java/org/openremote/model/asset/impl/ElectricityProducerSolarAsset.java b/model/src/main/java/org/openremote/model/asset/impl/ElectricityProducerSolarAsset.javaindex 52f61ece1..fccd65cf3 100644--- a/model/src/main/java/org/openremote/model/asset/impl/ElectricityProducerSolarAsset.java+++ b/model/src/main/java/org/openremote/model/asset/impl/ElectricityProducerSolarAsset.java@@ -23,11 +23,9 @@ import org.openremote.model.asset.Asset;import org.openremote.model.asset.AssetDescriptor;import org.openremote.model.attribute.Attribute;import org.openremote.model.attribute.AttributeMap;+import org.openremote.model.attribute.MetaItem;import org.openremote.model.geo.GeoJSONPoint;-import org.openremote.model.value.AbstractNameValueHolder;-import org.openremote.model.value.AttributeDescriptor;-import org.openremote.model.value.ValueDescriptor;-import org.openremote.model.value.ValueType;+import org.openremote.model.value.*;import jakarta.persistence.Entity;import java.util.Collection;@@ -54,7 +52,7 @@ public class ElectricityProducerSolarAsset extends ElectricityProducerAsset {public static final AttributeDescriptor<Boolean> INCLUDE_FORECAST_SOLAR_SERVICE = new AttributeDescriptor<>("includeForecastSolarService", BOOLEAN);- public static final AttributeDescriptor<Boolean> SET_ACTUAL_SOLAR_VALUE_WITH_FORECAST = new AttributeDescriptor<>("setActualSolarValueWithForecast", BOOLEAN);+ public static final AttributeDescriptor<Boolean> SET_ACTUAL_SOLAR_VALUE_WITH_FORECAST = new AttributeDescriptor<>("setActualSolarPowerValueWithForecast", BOOLEAN);public static final AssetDescriptor<ElectricityProducerSolarAsset> DESCRIPTOR = new AssetDescriptor<>("white-balance-sunny", "EABB4D", ElectricityProducerSolarAsset.class);