Write and read timeseries (forecast values) in a script (ECMAScript 11)

Hello,
I really like the new functionality in 4.1 with forecast values. I wanted to take advantage of it and display a graph of energy prices in the future. I use the Energi Data Service binding which supports future values, and wanted to combine/sum the channel values into a new item.

I found several ways to read the forecasted values in a script but I lack a way of writing a value with a timestamp to an item.

How do I write a future value to an item?

Example code for getting timeseries data:

var logger = log("timeseries");
var fromdate = new Date();
fromdate.setHours(fromdate.getHours()-3);
var toDate = new Date();
toDate.setHours(toDate.getHours()+6);

var itemWithForecast = items.getItem('Energi_Data_Service_Spot_Price');

var entries = itemWithForecast.history.getAllStatesBetween(fromdate, toDate, "influxdb");
//var entries = itemWithForecast.history.getAllStatesSince(fromdate, "influxdb");
var entry = itemWithForecast.history.historicState(toDate, "influxdb");

for(var i = 0; i < entries.length; i++)
{
  logger.info(entries[i].state);
}
1 Like

I believe the PR to add those Persistence Actions is not yet merged. So until that happens the only way is I know of is through the REST API.

Thanks

I have looked into the api documentation/Api Explorer in OpenHab.
The only methods I could find that I might be able to use is:
PUT /items/{itemname}/state
POST /items/{itemname}

but none of them have a property for time, the request body seems to be value that the item will receive.

Do you know how/where to add timestamp?

You missed the whole persistence category.

PUT /persistence/items/{itemname}

Oh, I must be blind…

Thanks :slight_smile: