mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-25 14:55:55 +01:00
Provide JavaScript example for persisting total price (#16889)
Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
This commit is contained in:
parent
344f191857
commit
422b72eef5
@ -58,6 +58,8 @@ It will not impact channels, see [Electricity Tax](#electricity-tax) for further
|
|||||||
| co2-emission-prognosis | Number:EmissionIntensity | Estimated prognosis for CO₂ emission following the day-ahead market in g/kWh |
|
| co2-emission-prognosis | Number:EmissionIntensity | Estimated prognosis for CO₂ emission following the day-ahead market in g/kWh |
|
||||||
| co2-emission-realtime | Number:EmissionIntensity | Near up-to-date history for CO₂ emission from electricity consumed in Denmark in g/kWh |
|
| co2-emission-realtime | Number:EmissionIntensity | Near up-to-date history for CO₂ emission from electricity consumed in Denmark in g/kWh |
|
||||||
|
|
||||||
|
#### Total Price
|
||||||
|
|
||||||
_Please note:_ There is no channel providing the total price.
|
_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.
|
Instead, create a group item with `SUM` as aggregate function and add the individual price items as children.
|
||||||
This has the following advantages:
|
This has the following advantages:
|
||||||
@ -69,6 +71,41 @@ This has the following advantages:
|
|||||||
If you want electricity tax included in your total price, please add either `electricity-tax` or `reduced-electricity-tax` to the group - depending on which one applies.
|
If you want electricity tax included in your total price, please add either `electricity-tax` or `reduced-electricity-tax` to the group - depending on which one applies.
|
||||||
See [Electricity Tax](#electricity-tax) for further information.
|
See [Electricity Tax](#electricity-tax) for further information.
|
||||||
|
|
||||||
|
##### Time Series
|
||||||
|
|
||||||
|
Group items with aggregate functions are not automatically recalculated into the future when the time series for child items are updated.
|
||||||
|
Therefore, the `SUM` function mentioned above will only work for the current price.
|
||||||
|
Calculation of future total prices can be achieved with a rule (in this example file-based using Rule Builder):
|
||||||
|
|
||||||
|
:::: tabs
|
||||||
|
|
||||||
|
::: tab JavaScript
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
rules.when()
|
||||||
|
.channel('energidataservice:service:energidataservice:electricity#event').triggered('DAY_AHEAD_AVAILABLE')
|
||||||
|
.then(event => {
|
||||||
|
var timeSeries = new items.TimeSeries('REPLACE');
|
||||||
|
var start = time.LocalDate.now().atStartOfDay().atZone(time.ZoneId.systemDefault());
|
||||||
|
var spotPrices = items.SpotPrice.persistence.getAllStatesBetween(start, start.plusDays(2));
|
||||||
|
for (var spotPrice of spotPrices) {
|
||||||
|
var totalPrice = spotPrice.quantityState
|
||||||
|
.add(items.GridTariff.persistence.persistedState(spotPrice.timestamp).quantityState)
|
||||||
|
.add(items.SystemTariff.persistence.persistedState(spotPrice.timestamp).quantityState)
|
||||||
|
.add(items.TransmissionGridTariff.persistence.persistedState(spotPrice.timestamp).quantityState)
|
||||||
|
.add(items.ElectricityTax.persistence.persistedState(spotPrice.timestamp).quantityState);
|
||||||
|
|
||||||
|
timeSeries.add(spotPrice.timestamp, totalPrice);
|
||||||
|
}
|
||||||
|
items.TotalPrice.persistence.persist(timeSeries);
|
||||||
|
})
|
||||||
|
.build("Calculate total price");
|
||||||
|
```
|
||||||
|
|
||||||
|
:::
|
||||||
|
|
||||||
|
::::
|
||||||
|
|
||||||
#### Currencies
|
#### Currencies
|
||||||
|
|
||||||
There are some existing limitations related to currency support.
|
There are some existing limitations related to currency support.
|
||||||
|
Loading…
Reference in New Issue
Block a user