Add UoM support for energy prices (#16070)
Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
This commit is contained in:
parent
0228f43004
commit
413ce0898c
@ -48,13 +48,13 @@ It will not impact channels, see [Electricity Tax](#electricity-tax) for further
|
|||||||
### Channel Group `electricity`
|
### Channel Group `electricity`
|
||||||
|
|
||||||
| Channel | Type | Description | Advanced |
|
| Channel | Type | Description | Advanced |
|
||||||
|--------------------------|--------|----------------------------------------------------------------------------------------|----------|
|
|--------------------------|--------------------|--------------------------------------------------------------------------------|----------|
|
||||||
| spot-price | Number | Current spot price in DKK or EUR per kWh | no |
|
| spot-price | Number:EnergyPrice | 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 |
|
| grid-tariff | Number:EnergyPrice | Grid tariff in DKK per kWh. Only available when `gridCompanyGLN` is configured | no |
|
||||||
| system-tariff | Number | Current system tariff in DKK per kWh | no |
|
| system-tariff | Number:EnergyPrice | System tariff in DKK per kWh | no |
|
||||||
| transmission-grid-tariff | Number | Current transmission grid tariff in DKK per kWh | no |
|
| transmission-grid-tariff | Number:EnergyPrice | Transmission grid tariff in DKK per kWh | no |
|
||||||
| electricity-tax | Number | Current electricity tax in DKK per kWh | no |
|
| electricity-tax | Number:EnergyPrice | 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 |
|
| 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 |
|
| 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.
|
_Please note:_ There is no channel providing the total price.
|
||||||
|
|||||||
@ -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.RetryPolicyFactory;
|
||||||
import org.openhab.binding.energidataservice.internal.retry.RetryStrategy;
|
import org.openhab.binding.energidataservice.internal.retry.RetryStrategy;
|
||||||
import org.openhab.core.i18n.TimeZoneProvider;
|
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.library.types.StringType;
|
||||||
import org.openhab.core.thing.Channel;
|
import org.openhab.core.thing.Channel;
|
||||||
import org.openhab.core.thing.ChannelUID;
|
import org.openhab.core.thing.ChannelUID;
|
||||||
@ -320,14 +321,19 @@ public class EnergiDataServiceHandler extends BaseThingHandler {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
BigDecimal spotPrice = cacheManager.getSpotPrice();
|
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) {
|
private void updateCurrentTariff(String channelId, @Nullable BigDecimal tariff) {
|
||||||
if (!isLinked(channelId)) {
|
if (!isLinked(channelId)) {
|
||||||
return;
|
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() {
|
private void updateHourlyPrices() {
|
||||||
@ -367,7 +373,7 @@ public class EnergiDataServiceHandler extends BaseThingHandler {
|
|||||||
for (Entry<Instant, BigDecimal> spotPrice : spotPrices) {
|
for (Entry<Instant, BigDecimal> spotPrice : spotPrices) {
|
||||||
Instant hourStart = spotPrice.getKey();
|
Instant hourStart = spotPrice.getKey();
|
||||||
if (isLinked(CHANNEL_SPOT_PRICE)) {
|
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()) {
|
for (Map.Entry<DatahubTariff, TimeSeries> entry : datahubTimeSeriesMap.entrySet()) {
|
||||||
DatahubTariff datahubTariff = entry.getKey();
|
DatahubTariff datahubTariff = entry.getKey();
|
||||||
@ -378,7 +384,7 @@ public class EnergiDataServiceHandler extends BaseThingHandler {
|
|||||||
BigDecimal tariff = cacheManager.getTariff(datahubTariff, hourStart);
|
BigDecimal tariff = cacheManager.getTariff(datahubTariff, hourStart);
|
||||||
if (tariff != null) {
|
if (tariff != null) {
|
||||||
TimeSeries timeSeries = entry.getValue();
|
TimeSeries timeSeries = entry.getValue();
|
||||||
timeSeries.add(hourStart, new DecimalType(tariff));
|
timeSeries.add(hourStart, getEnergyPrice(tariff, CURRENCY_DKK));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,27 +10,27 @@
|
|||||||
<channels>
|
<channels>
|
||||||
<channel id="spot-price" typeId="spot-price">
|
<channel id="spot-price" typeId="spot-price">
|
||||||
<label>Spot Price</label>
|
<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>
|
||||||
<channel id="grid-tariff" typeId="datahub-price">
|
<channel id="grid-tariff" typeId="datahub-price">
|
||||||
<label>Grid Tariff</label>
|
<label>Grid Tariff</label>
|
||||||
<description>Current grid tariff in DKK per kWh.</description>
|
<description>Grid tariff in DKK per kWh.</description>
|
||||||
</channel>
|
</channel>
|
||||||
<channel id="system-tariff" typeId="datahub-price">
|
<channel id="system-tariff" typeId="datahub-price">
|
||||||
<label>System Tariff</label>
|
<label>System Tariff</label>
|
||||||
<description>Current system tariff in DKK per kWh.</description>
|
<description>System tariff in DKK per kWh.</description>
|
||||||
</channel>
|
</channel>
|
||||||
<channel id="transmission-grid-tariff" typeId="datahub-price">
|
<channel id="transmission-grid-tariff" typeId="datahub-price">
|
||||||
<label>Transmission Grid Tariff</label>
|
<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>
|
||||||
<channel id="electricity-tax" typeId="datahub-price">
|
<channel id="electricity-tax" typeId="datahub-price">
|
||||||
<label>Electricity Tax</label>
|
<label>Electricity Tax</label>
|
||||||
<description>Current electricity tax in DKK per kWh.</description>
|
<description>Electricity tax in DKK per kWh.</description>
|
||||||
</channel>
|
</channel>
|
||||||
<channel id="reduced-electricity-tax" typeId="datahub-price">
|
<channel id="reduced-electricity-tax" typeId="datahub-price">
|
||||||
<label>Reduced Electricity Tax</label>
|
<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>
|
||||||
<channel id="hourly-prices" typeId="hourly-prices"/>
|
<channel id="hourly-prices" typeId="hourly-prices"/>
|
||||||
</channels>
|
</channels>
|
||||||
|
|||||||
@ -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">
|
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">
|
<channel-type id="spot-price">
|
||||||
<item-type>Number</item-type>
|
<item-type>Number:EnergyPrice</item-type>
|
||||||
<label>Spot Price</label>
|
<label>Spot Price</label>
|
||||||
<description>Spot price.</description>
|
<description>Spot price.</description>
|
||||||
<category>Price</category>
|
<category>Price</category>
|
||||||
<state readOnly="true" pattern="%.9f"></state>
|
<state readOnly="true" pattern="%.9f %unit%"></state>
|
||||||
</channel-type>
|
</channel-type>
|
||||||
|
|
||||||
<channel-type id="datahub-price">
|
<channel-type id="datahub-price">
|
||||||
<item-type>Number</item-type>
|
<item-type>Number:EnergyPrice</item-type>
|
||||||
<label>Datahub Price</label>
|
<label>Datahub Price</label>
|
||||||
<description>Datahub price.</description>
|
<description>Datahub price.</description>
|
||||||
<category>Price</category>
|
<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"/>
|
<config-description-ref uri="channel-type:energidataservice:datahub-price"/>
|
||||||
</channel-type>
|
</channel-type>
|
||||||
|
|
||||||
|
|||||||
@ -14,7 +14,7 @@
|
|||||||
</channel-groups>
|
</channel-groups>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<property name="thingTypeVersion">2</property>
|
<property name="thingTypeVersion">3</property>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<config-description-ref uri="thing-type:energidataservice:service"/>
|
<config-description-ref uri="thing-type:energidataservice:service"/>
|
||||||
|
|||||||
@ -28,6 +28,39 @@
|
|||||||
<remove-channel id="transmission-net-tariff" groupIds="electricity"/>
|
<remove-channel id="transmission-net-tariff" groupIds="electricity"/>
|
||||||
</instruction-set>
|
</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>
|
</thing-type>
|
||||||
|
|
||||||
</update:update-descriptions>
|
</update:update-descriptions>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user