How to extract time from persisted item?

I do have persisted ON/OFF state on Item am working with.
How can I work with time of the value?

I’m using influx, date/time is there indeed, when I draw a graph Time is there so I guess OH knows about it .
Can I use that time to display it on UI somehow? or calculate duration etc.?
is it something like

myitem.state
myItem.time 

?

Thanks

See

Persistence Extensions in Scripts and Rules

1 Like

seen that, but there is nothing about timestamp of the persisted state, or is it?

<item>.lastUpdate Queries for the last update timestamp of a given Item

But maybe you meant some more random query?

.lastUpdate is last timestamp, but how OH draw chart which contains all times at all states?

cos, yes I can extract last update, but what about the last-1, last-2 ?

I don’t think you’ll be able to do that with the persistence service.
I have to ask though, why?

Because charting is based on time intervals, not “last but one”. etc.

Random times can be queried with

<item>.historicState(AbstractInstant) Retrieves the State of an Item at a certain point in time

so it’s pretty easy to get a series at n-minute intervals.

as I said, I’m persisting ON/OFF state and I would like to count ON period during the day.
I probably can use a dummy item, but as this already have all needed informations I’m curious how to use them properly.

I probably don’t understand correctly… since Chart is able to draw exact point at exact time with data which is being persisted I thought that this can be extracted to a textual information as well.

basically, OH knows 1(on) from 8ish to 10ish then 0 (off) etc.
if OH knows that, I should able to access this information from something, am I?

this

Sure. Query every minute, one at a time, using historicState method. This will return the state at that historic moment.

If the last previous state recorded before that moment was ON, historicState will return ON because it hadn’t changed since, even if that was hours before.

If you are literally counting changes, it’s probably easier to implement that in a rule.

If you are integrating i.e. looking to find out ON-time compared to OFF-time, you could store on/off as 0 and 1 and run an average query.

In order to get all that data in a “textual” way, why don’t you use the REST API?
The return will be a JSON String.