]> git.basschouten.com Git - openhab-addons.git/commitdiff
Remove obsoleted advanced channel hourly-prices (#16190)
authorJacob Laursen <jacob-github@vindvejr.dk>
Sat, 13 Jan 2024 16:26:22 +0000 (17:26 +0100)
committerGitHub <noreply@github.com>
Sat, 13 Jan 2024 16:26:22 +0000 (17:26 +0100)
Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
bundles/org.openhab.binding.energidataservice/README.md
bundles/org.openhab.binding.energidataservice/src/main/java/org/openhab/binding/energidataservice/internal/EnergiDataServiceBindingConstants.java
bundles/org.openhab.binding.energidataservice/src/main/java/org/openhab/binding/energidataservice/internal/handler/EnergiDataServiceHandler.java
bundles/org.openhab.binding.energidataservice/src/main/resources/OH-INF/i18n/energidataservice.properties
bundles/org.openhab.binding.energidataservice/src/main/resources/OH-INF/thing/channel-groups.xml
bundles/org.openhab.binding.energidataservice/src/main/resources/OH-INF/thing/channel-types.xml
bundles/org.openhab.binding.energidataservice/src/main/resources/OH-INF/thing/thing-service.xml
bundles/org.openhab.binding.energidataservice/src/main/resources/OH-INF/update/instructions.xml

index f08aafc6565c085e3baf59a10956c2bbb3fe11e1..cff534c805a9b4aeaa98181f99d5d3187213688b 100644 (file)
@@ -55,7 +55,6 @@ It will not impact channels, see [Electricity Tax](#electricity-tax) for further
 | transmission-grid-tariff | Number:EnergyPrice | Transmission grid tariff in DKK per kWh                                        | no       |
 | electricity-tax          | Number:EnergyPrice | Electricity tax in DKK per kWh                                                 | no       |
 | reduced-electricity-tax  | Number:EnergyPrice | Reduced electricity tax in DKK per kWh. For electric heating customers only    | no       |
-| hourly-prices            | String             | JSON array with hourly prices from 24 hours ago and onward                     | yes      |
 
 _Please note:_ There is no channel providing the total price.
 Instead, create a group item with `SUM` as aggregate function and add the individual price items as children.
@@ -142,48 +141,16 @@ This reduced rate is made available through channel `reduced-electricity-tax`.
 The binding cannot determine or manage rate variations as they depend on metering data.
 Usually `reduced-electricity-tax` is preferred when using electricity for heating.
 
-#### Hourly Prices
-
-The format of the `hourly-prices` JSON array is as follows:
-
-```json
-[
-       {
-               "hourStart": "2023-09-19T18:00:00Z",
-               "spotPrice": 0.0,
-               "spotPriceCurrency": "DKK",
-               "gridTariff": 0.0,
-               "systemTariff": 0.054,
-               "transmissionGridTariff": 0.058,
-               "electricityTax": 0.697,
-               "reducedElectricityTax": 0.008
-       },
-       {
-               "hourStart": "2023-09-19T19:00:00Z",
-               "spotPrice": -0.00052,
-               "spotPriceCurrency": "DKK",
-               "gridTariff": 0.0,
-               "systemTariff": 0.054,
-               "transmissionGridTariff": 0.058,
-               "electricityTax": 0.697,
-               "reducedElectricityTax": 0.008
-       }
-]
-```
-
-Future spot prices for the next day are usually available around 13:00 CET and are fetched around that time.
-Historic prices older than 24 hours are removed from the JSON array each hour.
-
 ## Thing Actions
 
-Thing actions can be used to perform calculations as well as import prices directly into rules without deserializing JSON from the [hourly-prices](#hourly-prices) channel.
-This is more convenient, much faster, and provides automatic summation of the price components of interest.
+Thing actions can be used to perform calculations as well as import prices directly into rules without relying on persistence.
+This is convenient, fast, and provides automatic summation of the price components of interest.
 
 Actions use cached data for performing operations.
 Since data is only fetched when an item is linked to a channel, there might not be any cached data available.
 In this case the data will be fetched on demand and cached afterwards.
 The first action triggered on a given day may therefore be a bit slower, and is also prone to failing if the server call fails for any reason.
-This potential problem can be prevented by linking the individual channels to items, or by linking the `hourly-prices` channel to an item.
+This potential problem can be prevented by linking the individual channels to items.
 
 ### `calculateCheapestPeriod`
 
@@ -341,8 +308,8 @@ var price = actions.calculatePrice(now.toInstant(), now.plusHours(4).toInstant,
 The parameter `priceComponents` is a case-insensitive comma-separated list of price components to include in the returned hourly prices.
 These components can be requested:
 
-| Price component        | Description             |
-|------------------------|-------------------------|
+| Price component        | Description              |
+|------------------------|--------------------------|
 | SpotPrice              | Spot price               |
 | GridTariff             | Grid tariff              |
 | SystemTariff           | System tariff            |
@@ -380,9 +347,26 @@ Number GridTariff "Current Grid Tariff" <price> (TotalPrice) { channel="energida
 Number SystemTariff "Current System Tariff" <price> (TotalPrice) { channel="energidataservice:service:energidataservice:electricity#system-tariff" [profile="transform:VAT"] }
 Number TransmissionGridTariff "Current Transmission Grid Tariff" <price> (TotalPrice) { channel="energidataservice:service:energidataservice:electricity#transmission-grid-tariff" [profile="transform:VAT"] }
 Number ElectricityTax "Current Electricity Tax" <price> (TotalPrice) { channel="energidataservice:service:energidataservice:electricity#electricity-tax" [profile="transform:VAT"] }
-String HourlyPrices "Hourly Prices" <price> { channel="energidataservice:service:energidataservice:electricity#hourly-prices" }
 ```
 
+### Persistence Configuration
+
+```java
+Strategies {
+    default = everyChange
+}
+
+Items {
+    SpotPrice,
+    GridTariff,
+    SystemTariff,
+    TransmissionGridTariff,
+    ElectricityTax: strategy = forecast
+}
+```
+
+In case persistence is only needed for charts and/or accessing prices from rules, [InMemory Persistence](https://www.openhab.org/addons/persistence/inmemory/) can be used.
+
 ### Thing Actions Example
 
 :::: tabs
@@ -517,3 +501,29 @@ var result = edsActions.calculateCheapestPeriod(time.Instant.now(), time.Instant
 :::
 
 ::::
+
+### Persistence Rule Example
+
+:::: tabs
+
+::: tab DSL
+
+```javascript
+var hourStart = now.plusHours(2).truncatedTo(ChronoUnit.HOURS)
+var price = SpotPrice.historicState(hourStart).state
+logInfo("Spot price two hours from now", price.toString)
+```
+
+:::
+
+::: tab JavaScript
+
+```javascript
+var hourStart = time.toZDT().plusHours(2).truncatedTo(time.ChronoUnit.HOURS);
+var price = items.SpotPrice.history.historicState(hourStart).quantityState;
+console.log("Spot price two hours from now: " + price);
+```
+
+:::
+
+::::
index 8ecbf60e9a878acc12bfe7869862676b1f1fedd5..4555a335b578e8d6e015b3c5d8d87ff0e10308a9 100644 (file)
@@ -52,12 +52,10 @@ public class EnergiDataServiceBindingConstants {
             + ChannelUID.CHANNEL_GROUP_SEPARATOR + "reduced-electricity-tax";
     public static final String CHANNEL_TRANSMISSION_GRID_TARIFF = CHANNEL_GROUP_ELECTRICITY
             + ChannelUID.CHANNEL_GROUP_SEPARATOR + "transmission-grid-tariff";
-    public static final String CHANNEL_HOURLY_PRICES = CHANNEL_GROUP_ELECTRICITY + ChannelUID.CHANNEL_GROUP_SEPARATOR
-            + "hourly-prices";
 
     public static final Set<String> ELECTRICITY_CHANNELS = Set.of(CHANNEL_SPOT_PRICE, CHANNEL_GRID_TARIFF,
             CHANNEL_SYSTEM_TARIFF, CHANNEL_TRANSMISSION_GRID_TARIFF, CHANNEL_ELECTRICITY_TAX,
-            CHANNEL_REDUCED_ELECTRICITY_TAX, CHANNEL_HOURLY_PRICES);
+            CHANNEL_REDUCED_ELECTRICITY_TAX);
 
     // List of all properties
     public static final String PROPERTY_REMAINING_CALLS = "remainingCalls";
index b34c8c08e364441476f758a1484ecf16d0580a79..967322ad0db8b2e31e70b108d7feefd843344885 100644 (file)
@@ -60,7 +60,6 @@ import org.openhab.binding.energidataservice.internal.retry.RetryStrategy;
 import org.openhab.core.i18n.TimeZoneProvider;
 import org.openhab.core.library.types.DecimalType;
 import org.openhab.core.library.types.QuantityType;
-import org.openhab.core.library.types.StringType;
 import org.openhab.core.library.unit.CurrencyUnits;
 import org.openhab.core.thing.Channel;
 import org.openhab.core.thing.ChannelUID;
@@ -77,8 +76,6 @@ import org.openhab.core.types.UnDefType;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import com.google.gson.Gson;
-
 /**
  * The {@link EnergiDataServiceHandler} is responsible for handling commands, which are
  * sent to one of the channels.
@@ -92,19 +89,12 @@ public class EnergiDataServiceHandler extends BaseThingHandler {
     private final TimeZoneProvider timeZoneProvider;
     private final ApiController apiController;
     private final CacheManager cacheManager;
-    private final Gson gson = new Gson();
 
     private EnergiDataServiceConfiguration config;
     private RetryStrategy retryPolicy = RetryPolicyFactory.initial();
     private @Nullable ScheduledFuture<?> refreshFuture;
     private @Nullable ScheduledFuture<?> priceUpdateFuture;
 
-    private record Price(String hourStart, BigDecimal spotPrice, String spotPriceCurrency,
-            @Nullable BigDecimal gridTariff, @Nullable BigDecimal systemTariff,
-            @Nullable BigDecimal transmissionGridTariff, @Nullable BigDecimal electricityTax,
-            @Nullable BigDecimal reducedElectricityTax) {
-    }
-
     public EnergiDataServiceHandler(Thing thing, HttpClient httpClient, TimeZoneProvider timeZoneProvider) {
         super(thing);
         this.timeZoneProvider = timeZoneProvider;
@@ -177,12 +167,12 @@ public class EnergiDataServiceHandler extends BaseThingHandler {
     private void refreshElectricityPrices() {
         RetryStrategy retryPolicy;
         try {
-            if (isLinked(CHANNEL_SPOT_PRICE) || isLinked(CHANNEL_HOURLY_PRICES)) {
+            if (isLinked(CHANNEL_SPOT_PRICE)) {
                 downloadSpotPrices();
             }
 
             for (DatahubTariff datahubTariff : DatahubTariff.values()) {
-                if (isLinked(datahubTariff.getChannelId()) || isLinked(CHANNEL_HOURLY_PRICES)) {
+                if (isLinked(datahubTariff.getChannelId())) {
                     downloadTariffs(datahubTariff);
                 }
             }
@@ -191,7 +181,7 @@ public class EnergiDataServiceHandler extends BaseThingHandler {
             updatePrices();
             updateTimeSeries();
 
-            if (isLinked(CHANNEL_SPOT_PRICE) || isLinked(CHANNEL_HOURLY_PRICES)) {
+            if (isLinked(CHANNEL_SPOT_PRICE)) {
                 if (cacheManager.getNumberOfFutureSpotPrices() < 13) {
                     retryPolicy = RetryPolicyFactory.whenExpectedSpotPriceDataMissing(DAILY_REFRESH_TIME_CET,
                             NORD_POOL_TIMEZONE);
@@ -315,7 +305,6 @@ public class EnergiDataServiceHandler extends BaseThingHandler {
         updateCurrentSpotPrice();
         Arrays.stream(DatahubTariff.values())
                 .forEach(tariff -> updateCurrentTariff(tariff.getChannelId(), cacheManager.getTariff(tariff)));
-        updateHourlyPrices();
 
         reschedulePriceUpdateJob();
     }
@@ -354,30 +343,6 @@ public class EnergiDataServiceHandler extends BaseThingHandler {
         }
     }
 
-    private void updateHourlyPrices() {
-        if (!isLinked(CHANNEL_HOURLY_PRICES)) {
-            return;
-        }
-        Map<Instant, BigDecimal> spotPriceMap = cacheManager.getSpotPrices();
-        Price[] targetPrices = new Price[spotPriceMap.size()];
-        List<Entry<Instant, BigDecimal>> sourcePrices = spotPriceMap.entrySet().stream()
-                .sorted(Map.Entry.comparingByKey()).toList();
-
-        int i = 0;
-        for (Entry<Instant, BigDecimal> sourcePrice : sourcePrices) {
-            Instant hourStart = sourcePrice.getKey();
-            BigDecimal gridTariff = cacheManager.getTariff(DatahubTariff.GRID_TARIFF, hourStart);
-            BigDecimal systemTariff = cacheManager.getTariff(DatahubTariff.SYSTEM_TARIFF, hourStart);
-            BigDecimal transmissionGridTariff = cacheManager.getTariff(DatahubTariff.TRANSMISSION_GRID_TARIFF,
-                    hourStart);
-            BigDecimal electricityTax = cacheManager.getTariff(DatahubTariff.ELECTRICITY_TAX, hourStart);
-            BigDecimal reducedElectricityTax = cacheManager.getTariff(DatahubTariff.REDUCED_ELECTRICITY_TAX, hourStart);
-            targetPrices[i++] = new Price(hourStart.toString(), sourcePrice.getValue(), config.currencyCode, gridTariff,
-                    systemTariff, electricityTax, reducedElectricityTax, transmissionGridTariff);
-        }
-        updateState(CHANNEL_HOURLY_PRICES, new StringType(gson.toJson(targetPrices)));
-    }
-
     private void updateTimeSeries() {
         TimeSeries spotPriceTimeSeries = new TimeSeries(REPLACE);
         Map<DatahubTariff, TimeSeries> datahubTimeSeriesMap = new HashMap<>();
index da13f9fda7a5443239c4605fe87c47276f2bf532..f54cbd7cc0c2ba4d827fe139696a883f0230ba52 100644 (file)
@@ -75,8 +75,6 @@ channel-group-type.energidataservice.electricity.channel.transmission-grid-tarif
 
 channel-type.energidataservice.datahub-price.label = Datahub Price
 channel-type.energidataservice.datahub-price.description = Datahub price.
-channel-type.energidataservice.hourly-prices.label = Hourly Prices
-channel-type.energidataservice.hourly-prices.description = JSON array with hourly prices from 24 hours ago and onward.
 channel-type.energidataservice.spot-price.label = Spot Price
 channel-type.energidataservice.spot-price.description = Spot price.
 
index 872bc9e3de561062e00b410c5fc6fa2124de374e..44cef47c1a0b4ab731d8555f64e21659458f9d65 100644 (file)
@@ -32,7 +32,6 @@
                                <label>Reduced Electricity Tax</label>
                                <description>Reduced electricity tax in DKK per kWh. For electric heating customers only.</description>
                        </channel>
-                       <channel id="hourly-prices" typeId="hourly-prices"/>
                </channels>
        </channel-group-type>
 
index eed37700b221a930d1dab61109c31c353b54187f..fe055d40ea7f98853b3b3afdeafef91aa95a0368 100644 (file)
                <config-description-ref uri="channel-type:energidataservice:datahub-price"/>
        </channel-type>
 
-       <channel-type id="hourly-prices" advanced="true">
-               <item-type>String</item-type>
-               <label>Hourly Prices</label>
-               <description>JSON array with hourly prices from 24 hours ago and onward.</description>
-               <category>Price</category>
-               <state readOnly="true"></state>
-       </channel-type>
-
 </thing:thing-descriptions>
index 6a7e97f9a8b722b82c06fa95b8853a9aa452a3c2..bda2a09c9a82bbf63b8e9490c5173d983ccd5ea0 100644 (file)
@@ -14,7 +14,7 @@
                </channel-groups>
 
                <properties>
-                       <property name="thingTypeVersion">3</property>
+                       <property name="thingTypeVersion">4</property>
                </properties>
 
                <config-description-ref uri="thing-type:energidataservice:service"/>
index ad8ed729915cd34b9e411c8f7aba90eb7a3d6b62..1d71298194bdf5b66c391775d9a22262f0d46d6f 100644 (file)
                        </update-channel>
                </instruction-set>
 
+               <instruction-set targetVersion="4">
+                       <remove-channel id="hourly-prices" groupIds="electricity"/>
+               </instruction-set>
+
        </thing-type>
 
 </update:update-descriptions>