mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-10 07:02:02 +01:00
[energidataservice] Improve rule example for calculating totals (#18024)
* Improve rule example for calculating totals Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk> Co-authored-by: Jimmy Tanagra <jcode@tanagra.id.au>
This commit is contained in:
parent
705feffd54
commit
563caa0762
@ -87,6 +87,8 @@ In this example file-based using Rule Builder:
|
||||
rules.when()
|
||||
.channel('energidataservice:service:energidataservice:electricity#event').triggered('DAY_AHEAD_AVAILABLE')
|
||||
.then(event => {
|
||||
// Short delay because persistence is asynchronous.
|
||||
setTimeout(() => {
|
||||
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));
|
||||
@ -100,6 +102,7 @@ rules.when()
|
||||
timeSeries.add(spotPrice.timestamp, totalPrice);
|
||||
}
|
||||
items.TotalPrice.persistence.persist(timeSeries);
|
||||
}, 5000);
|
||||
})
|
||||
.build("Calculate total price");
|
||||
```
|
||||
@ -112,6 +115,7 @@ rules.when()
|
||||
rule "Calculate total price" do
|
||||
channel "energidataservice:service:energidataservice:electricity#event", triggered: "DAY_AHEAD_AVAILABLE"
|
||||
run do
|
||||
after 5.seconds do # Short delay because persistence is asynchronous.
|
||||
# Persistence methods will call LocalDate#to_zoned_date_time which converts it
|
||||
# to a ZonedDateTime in the default system zone, with 00:00 as its time portion
|
||||
start = LocalDate.now
|
||||
@ -131,6 +135,7 @@ rule "Calculate total price" do
|
||||
TotalPrice.persist(time_series)
|
||||
end
|
||||
end
|
||||
end
|
||||
```
|
||||
|
||||
:::
|
||||
|
Loading…
Reference in New Issue
Block a user