There are a couple of ways how you can do this:
Perhaps the easiest approach is to use [blockInPieces](https://github.com/masipila/openhab-spot-price-optimizer/wiki/GenericOptimizer-API-documentation#usage-example-with-start-and-end-constraints-3)
(or blockPeriod
or blockHours
) method, which will search the most expensive slots for you. It will return a time series so that the expensive periods are 0 and all others are 1, so this is inverted compared to what you need.
It will be your choice how you want to invert them back (either you just build your logic so that 0 means that you want to sell back to the grid or you invert the values before persisting them with a method of your choice).
Additional hint 1: You most probably want to use the optional startConstraint
and endConstratint
arguments so that you are chasing for the most expensive times during the day time.
Additional hint 2: plusDays(-1)
can be written more intuitively as minusDays(1)
.
You most probably will love @rlkoshak 's eye-poppingly excellent examples at Working with Date Times in JS Scripting (ECMAScript 11)
Cheers,
Markus