Batch state persistence

Hello folks!

I must admit that I am stomped…
Here’s the context: my solar array reports production data with a minute resolution in batches every 30 min or so.
I can retrieve that latest from the cloud. It returns a jason structure with timestamp and production data. The batch could be a few min old or several hrs.
So I can query the service and reconstruct the historical data.

I want to persist that data so that I can chart historical performance just as one would chart historical temperature.

The issue I am facing is that I cannot set the state for an item in the past. Or can I?



I see no method to set the timestamp for data that gets persisted through OH. To do this I think you will need to write something that saves the data to the database yourself and not depend on OH Persistence.

So I figured it out!

Start by setting up persistence of the item to mysql in order for openhab to create the itemX table.
Once the table is created, turn persistence back to onstartup only.
I then created a bash script that downloads the historical data & uploads it ( timestamp, value pairs) to the itemX table via mysql.
Put that script on a cron job & you are done!

Some caveats: graphing will show a horizontal line for the missing data. If you want 1 data point per day, put it at 11:59 pm instead of 0:00 as the graph will otherwise show the datapoint off center.