Obtaining a list of previousStates from persistence

The issue I am trying to solve is that i want to be able to display a number of state changes of a particurlar item, say I have a door contact sensor and the information about the status change is stored in mysql.

So I can get the current and n-1 value and update time using


or the item at a particurlar time using the


But is there a way to extract, for example, the last 10 records from mysql peristence?

I have come across the same question being raised back in 2017 here

That suggested using the extra variables for keeping the changed state of an item, but it seems like a rather useful option to have, so maybe it i already implemented and I am simply mising something obvious here.

Thanks in advance.

Take a look at how I do it in PersistenceViewer or look it up in the REST Docs UI.

1 Like

I think most of us who want to display this sort of stuff use Grafana with the Discrete plugin.

1 Like

thanks, I have the visual representation via Grafana and Discrete pluging already configured.

But for some of the windows/doors that are not opened so frequently, I find it rather inconvinient trying to find the interval during which it was last opened. The table structure showing the last no.of state change would work nicely here.
There is another possibility of using Grafana and the Table plugin and insert it via webview, but I was hoping that an inbuilt mechanism would exists allowing access to historical data.
I was playing this morning with a rule updating a set of variables, but for every item i want to keep track of, I need 20 extra variables (state+timeofupdate) if i want to keep track of last 10 statechanges. Thus it become pretty unmanageable for a large number of sensors :frowning:

So done all those sensors statuses in grafana table and thats how it looks.
Then each individual table can be inserted into the OH via Webview where needed.