`previousState(true)` returns `null` (JavaScript)

I’ve got an item icloudbinding_cln_afstand_tot_thuis. The value has been 1.229 for a couple of hours, but as you can see, it has some previous values:

If I run:

var vorigestatus = items["icloudbinding_cln_afstand_tot_thuis"].persistence.previousState();
console.log(vorigestatus);

… this is the output:

08:48:43.077 [INFO ] [enhab.automation.script.ui.scratchpad] - PersistedItem (Timestamp=2025-10-07T08:48+02:00[Europe/Brussels], State=1.229 m)

But if I want the previous different state, and run:

var vorigestatus = items["icloudbinding_cln_afstand_tot_thuis"].persistence.previousState(true);
console.log(vorigestatus);

… this is the output:

08:49:05.660 [INFO ] [enhab.automation.script.ui.scratchpad] - null

In the documentation I read:

But I don’t understand what that means. I also don’t understand what that serviceId is… (And I actually think this doesn’t apply, since .previousState() does return output.)

Thanks in advance for anyone’s guidance!

have a look here:

tl:>dr;
openHAB comes with loads of persitences, usually “rrd4j” is the default one (could depend on your install). rrd4j needs a regular interval to work (everyMinute), so the “previousState” usually is exactly the same as the current state (it gets “muddier” as rrd does some compacting of values over time).
the “persistence id” is the id a persistence has (e.g. “rrd4j” or “jdbc” or whatever your preferred persistence would be).

so, either use a different persistence (you can have more than one active at any time) like MySQL and use the persistence strategy everyChange, which will then result in your .persistence.previousState to give out the “real” previous state.
or use the newly introduced previousState on the item itself. Since OH5 the previous state is also known at item level without the need for persistence:
var vorigestatus = items["icloudbinding_cln_afstand_tot_thuis"].previousState;

1 Like

And that’s how simple it was…

Thanks!

2 Likes