Hello,
I am trying to “miss use” the openhab-spot-price-optimizer. During winter I am using to optimize when using energy, but now in summer I am using it to optimize when selling energy at the most expencive moment.
Currently I do this via “inversed” logic → 0 for OK to sell energy, 1 for NOK. Problem is this doesn’t represent nicely in a graph.
In order to solve this I was looking into inverting the control points from the time series before persisting it. I am writing the rules in a ECMAScript/Javascript. Is this possible, or is there an obvious way I am missing to do this?
// Load module and create service.
var { GenericOptimizer } = require('openhab-spot-price-optimizer/generic-optimizer.js');
var optimizer = new GenericOptimizer();
// Define price item and control item here.
var priceItem = items.getItem('SpotPrice');
var controlItem = items.getItem('MEB_Discharge_Control');
// Read how many hours are needed from the BoilerHours item.
var period =24.0;
var item = items.getItem("MEB_DischargingHours");
var hours = period - parseFloat(item.numericState);
//var hours = parseFloat(item.numericState);
// Define the optimization window here, this example optimizes tomorrow.
var start = time.toZDT('12:00').plusDays(0);
var end = start.plusHours(period);
// Define the delay (seconds) to ensure prices have been saved first.
var delay = 60;
// Read prices from the database, optimize and save the control points.
var delayedFunction = function() {
var prices = priceItem.persistence.getAllStatesBetween(start, end);
optimizer.setPrices(prices);
optimizer.allowIndividualHours(hours);
optimizer.blockAllRemaining();
var timeseries = optimizer.getControlPoints();
//here I am looking how to inverse the control points from the timeseries...
controlItem.persistence.persist(timeseries);
};
// Create a timer that calls delayedFucntion after the delay.
actions.ScriptExecution.createTimer(time.toZDT().plusSeconds(delay), delayedFunction);