How to get previous value from persistance

Hi There,

i have a mind problem with persitance. I persist an enery counter on every update. now i like to calculate the energy consumption over the day by adding to a base counter all the small deltas over the day.

My idea was: Get the current value when item is updated and then use the previousState() function to get the value before the last update and the caclulate the delta. Straight forwad as i think. BUT previousSate() give me alway the same value than the current stae. I checked that with some variables in my rules. if the current value i N how do i get from the persitence N-1 value.

Thomas

Because you are persisting every update, any update that gets sent to the Item, even if the update doesn’t result in a change, gets persisted.

It sounds like what you really want is the previous different value. You can do this one of two ways:

  • change persistence to everyChange rather than everyUpdate
  • use previousState(true) which returns the previous different value

Unfortunately this dow not wirk right

Persistance : Every Change
previousState(true) with or without true

This combination gives the actual state and not the one before the actual state.

If i use historicState(now.minusSeconds(0)) i got the right value

Maybe this is a bug in OH2

Thomas