Persist strategy "everyChange" incl. the last known value before change

Okay, still don’t know what you have tried to put in previousState(), so had an experiment for myself.

The docs are misleading; these are good syntax
....previousState(true, "influxdb")...
....previousState(false, "influxdb")...
....previousState()...
and this is bad syntax
....previousState("influxdb")...
which I suppose is not entirely surprising.

Here is what I am trying to achieve, the chart on the top is almost what I need.
The chart should show steps only, as the parameter is usually changing only in steps of 0 or 11.
It seems like the rule is “half” working, the second persist statement in the rule is not performed.
image

When you’re ready, show us the rule you are currently using to get those results and describe what results you would like to see instead.
I could guess that you think the first chart has missed some reading altogether?
The crystal ball is not very effective, and I’m fed up with guessing.

Bear in mind Rich’s original rule was aimed at pure binary switch.
You’re trying to do something else altogether with variable data, so you are most likely going to have to define what you want the rule to do very closely.
“Previous value” is not the same as “previous different value” is not the same as “previous zero value” is not the same as “previous very small value”

It may be helpful to use the REST API to retrieve and review the actual data in your database (its timestamped in unix epoch form).

I still have concerns around database granularity and multiple persists within a few milliseconds.

The really, really simple way to approximate your wanted pictures is to use both everyMinute and everyChange strategies on your Item, it’d pretty much do itself then.

Abandoned the rule.
Made persistence every 5 minutes.

I was thinking about the rule you would need …
I reckon you’d fetch previousState, then if and only if was zero (or close to zero) you’d add an “extra” persist of zero. Then fire a 1-second timer to persist the “real” new value, slightly delayed to make sure we don’t run into db timestamping granularity limitations.

Exactly the way I was thinking I need to do but my programming skill is very limited and I have no idea how to do that. This is the reason I went to the simplest way.

I don’t want to revive this thread, but as I had the same issue and didn’t find a good solution here, but in the echarts docs (that works on OH 3 and probably later) I wanted to paste it for others that reach this point with the search function.
Adding
step: start
in the YAML of the oh-time-series component does the trick. A full time series example could look like:

    - component: oh-time-series
      config:
        name: Switch state
        gridIndex: 0
        xAxisIndex: 0
        yAxisIndex: 1
        step: start
        type: line
        item: WhateverDiscrete

For some other (theoretical) problems you could also try value end or middle in step. See the echart docs.