]> git.basschouten.com Git - openhab-addons.git/commitdiff
Add UoM support for energy prices (#16070)
authorJacob Laursen <jacob-github@vindvejr.dk>
Sat, 16 Dec 2023 16:29:06 +0000 (17:29 +0100)
committerGitHub <noreply@github.com>
Sat, 16 Dec 2023 16:29:06 +0000 (17:29 +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/handler/EnergiDataServiceHandler.java
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 c28eb0524a008d78379ab32ada3a2abd531fab48..a203dbabd1f1975baa701c4bcf83077d29db04db 100644 (file)
@@ -47,15 +47,15 @@ It will not impact channels, see [Electricity Tax](#electricity-tax) for further
 
 ### Channel Group `electricity`
 
-| Channel                  | Type   | Description                                                                            | Advanced |
-|--------------------------|--------|----------------------------------------------------------------------------------------|----------|
-| spot-price               | Number | Current spot price in DKK or EUR per kWh                                               | no       |
-| grid-tariff              | Number | Current grid tariff in DKK per kWh. Only available when `gridCompanyGLN` is configured | no       |
-| system-tariff            | Number | Current system tariff in DKK per kWh                                                   | no       |
-| transmission-grid-tariff | Number | Current transmission grid tariff in DKK per kWh                                        | no       |
-| electricity-tax          | Number | Current electricity tax in DKK per kWh                                                 | no       |
-| reduced-electricity-tax  | Number | Current 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      |
+| Channel                  | Type               | Description                                                                    | Advanced |
+|--------------------------|--------------------|--------------------------------------------------------------------------------|----------|
+| spot-price               | Number:EnergyPrice | Spot price in DKK or EUR per kWh                                               | no       |
+| grid-tariff              | Number:EnergyPrice | Grid tariff in DKK per kWh. Only available when `gridCompanyGLN` is configured | no       |
+| system-tariff            | Number:EnergyPrice | System tariff in DKK per kWh                                                   | no       |
+| 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.
index ca686821fb6b0c55bd6e042f280841fcab5b3b0f..5f6ed20d78dbec7be5f3e681ecf8250e3aab8296 100644 (file)
@@ -56,7 +56,8 @@ import org.openhab.binding.energidataservice.internal.exception.DataServiceExcep
 import org.openhab.binding.energidataservice.internal.retry.RetryPolicyFactory;
 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.dimension.EnergyPrice;
+import org.openhab.core.library.types.QuantityType;
 import org.openhab.core.library.types.StringType;
 import org.openhab.core.thing.Channel;
 import org.openhab.core.thing.ChannelUID;
@@ -320,14 +321,19 @@ public class EnergiDataServiceHandler extends BaseThingHandler {
             return;
         }
         BigDecimal spotPrice = cacheManager.getSpotPrice();
-        updateState(CHANNEL_SPOT_PRICE, spotPrice != null ? new DecimalType(spotPrice) : UnDefType.UNDEF);
+        updateState(CHANNEL_SPOT_PRICE,
+                spotPrice != null ? getEnergyPrice(spotPrice, config.getCurrency()) : UnDefType.UNDEF);
     }
 
     private void updateCurrentTariff(String channelId, @Nullable BigDecimal tariff) {
         if (!isLinked(channelId)) {
             return;
         }
-        updateState(channelId, tariff != null ? new DecimalType(tariff) : UnDefType.UNDEF);
+        updateState(channelId, tariff != null ? getEnergyPrice(tariff, CURRENCY_DKK) : UnDefType.UNDEF);
+    }
+
+    private QuantityType<EnergyPrice> getEnergyPrice(BigDecimal price, Currency currency) {
+        return new QuantityType<>(price + " " + currency.getSymbol() + "/kWh");
     }
 
     private void updateHourlyPrices() {
@@ -367,7 +373,7 @@ public class EnergiDataServiceHandler extends BaseThingHandler {
         for (Entry<Instant, BigDecimal> spotPrice : spotPrices) {
             Instant hourStart = spotPrice.getKey();
             if (isLinked(CHANNEL_SPOT_PRICE)) {
-                spotPriceTimeSeries.add(hourStart, new DecimalType(spotPrice.getValue()));
+                spotPriceTimeSeries.add(hourStart, getEnergyPrice(spotPrice.getValue(), config.getCurrency()));
             }
             for (Map.Entry<DatahubTariff, TimeSeries> entry : datahubTimeSeriesMap.entrySet()) {
                 DatahubTariff datahubTariff = entry.getKey();
@@ -378,7 +384,7 @@ public class EnergiDataServiceHandler extends BaseThingHandler {
                 BigDecimal tariff = cacheManager.getTariff(datahubTariff, hourStart);
                 if (tariff != null) {
                     TimeSeries timeSeries = entry.getValue();
-                    timeSeries.add(hourStart, new DecimalType(tariff));
+                    timeSeries.add(hourStart, getEnergyPrice(tariff, CURRENCY_DKK));
                 }
             }
         }
index 83587c1e46a674aeee8019e40dd2a4795d98ad91..872bc9e3de561062e00b410c5fc6fa2124de374e 100644 (file)
                <channels>
                        <channel id="spot-price" typeId="spot-price">
                                <label>Spot Price</label>
-                               <description>Current spot price in DKK or EUR per kWh.</description>
+                               <description>Spot price in DKK or EUR per kWh.</description>
                        </channel>
                        <channel id="grid-tariff" typeId="datahub-price">
                                <label>Grid Tariff</label>
-                               <description>Current grid tariff in DKK per kWh.</description>
+                               <description>Grid tariff in DKK per kWh.</description>
                        </channel>
                        <channel id="system-tariff" typeId="datahub-price">
                                <label>System Tariff</label>
-                               <description>Current system tariff in DKK per kWh.</description>
+                               <description>System tariff in DKK per kWh.</description>
                        </channel>
                        <channel id="transmission-grid-tariff" typeId="datahub-price">
                                <label>Transmission Grid Tariff</label>
-                               <description>Current transmission grid tariff in DKK per kWh.</description>
+                               <description>Transmission grid tariff in DKK per kWh.</description>
                        </channel>
                        <channel id="electricity-tax" typeId="datahub-price">
                                <label>Electricity Tax</label>
-                               <description>Current electricity tax in DKK per kWh.</description>
+                               <description>Electricity tax in DKK per kWh.</description>
                        </channel>
                        <channel id="reduced-electricity-tax" typeId="datahub-price">
                                <label>Reduced Electricity Tax</label>
-                               <description>Current reduced electricity tax in DKK per kWh. For electric heating customers only.</description>
+                               <description>Reduced electricity tax in DKK per kWh. For electric heating customers only.</description>
                        </channel>
                        <channel id="hourly-prices" typeId="hourly-prices"/>
                </channels>
index 70749213ba05dbafd771976c4cb7a438f09513d3..eed37700b221a930d1dab61109c31c353b54187f 100644 (file)
@@ -5,19 +5,19 @@
        xsi:schemaLocation="https://openhab.org/schemas/thing-description/v1.0.0 https://openhab.org/schemas/thing-description-1.0.0.xsd">
 
        <channel-type id="spot-price">
-               <item-type>Number</item-type>
+               <item-type>Number:EnergyPrice</item-type>
                <label>Spot Price</label>
                <description>Spot price.</description>
                <category>Price</category>
-               <state readOnly="true" pattern="%.9f"></state>
+               <state readOnly="true" pattern="%.9f %unit%"></state>
        </channel-type>
 
        <channel-type id="datahub-price">
-               <item-type>Number</item-type>
+               <item-type>Number:EnergyPrice</item-type>
                <label>Datahub Price</label>
                <description>Datahub price.</description>
                <category>Price</category>
-               <state readOnly="true" pattern="%.6f"></state>
+               <state readOnly="true" pattern="%.6f %unit%"></state>
                <config-description-ref uri="channel-type:energidataservice:datahub-price"/>
        </channel-type>
 
index 805510a68eab83b84a961bfd7cae3d597816f62a..6a7e97f9a8b722b82c06fa95b8853a9aa452a3c2 100644 (file)
@@ -14,7 +14,7 @@
                </channel-groups>
 
                <properties>
-                       <property name="thingTypeVersion">2</property>
+                       <property name="thingTypeVersion">3</property>
                </properties>
 
                <config-description-ref uri="thing-type:energidataservice:service"/>
index ef4dd6bd99184324e2c35bd244e2ee0970885320..ad8ed729915cd34b9e411c8f7aba90eb7a3d6b62 100644 (file)
                        <remove-channel id="transmission-net-tariff" groupIds="electricity"/>
                </instruction-set>
 
+               <instruction-set targetVersion="3">
+                       <update-channel id="spot-price" groupIds="electricity">
+                               <type>energidataservice:spot-price</type>
+                               <label>Spot Price</label>
+                               <description>Spot price in DKK or EUR per kWh.</description>
+                       </update-channel>
+                       <update-channel id="grid-tariff" groupIds="electricity">
+                               <type>energidataservice:datahub-price</type>
+                               <label>Grid Tariff</label>
+                               <description>Grid tariff in DKK per kWh.</description>
+                       </update-channel>
+                       <update-channel id="system-tariff" groupIds="electricity">
+                               <type>energidataservice:datahub-price</type>
+                               <label>System Tariff</label>
+                               <description>System tariff in DKK per kWh.</description>
+                       </update-channel>
+                       <update-channel id="transmission-grid-tariff" groupIds="electricity">
+                               <type>energidataservice:datahub-price</type>
+                               <label>Transmission Grid Tariff</label>
+                               <description>Transmission grid tariff in DKK per kWh.</description>
+                       </update-channel>
+                       <update-channel id="electricity-tax" groupIds="electricity">
+                               <type>energidataservice:datahub-price</type>
+                               <label>Electricity Tax</label>
+                               <description>Electricity tax in DKK per kWh.</description>
+                       </update-channel>
+                       <update-channel id="reduced-electricity-tax" groupIds="electricity">
+                               <type>energidataservice:datahub-price</type>
+                               <label>Reduced Electricity Tax</label>
+                               <description>Reduced electricity tax in DKK per kWh. For electric heating customers only.</description>
+                       </update-channel>
+               </instruction-set>
+
        </thing-type>
 
 </update:update-descriptions>