Persistence: On-Off-Transitions with Influx

I store my ON/OFF sensor with the influx-db persistence.

What I currently have is what is depicted in the following example:

In this case the value was OFF at ~10:40 and became ON at 14:00

What I would like to have though is also the a point in the time serious where the value was OFF the last time like so

I could achieve that kind of by storing a value every other minute or second but that would generate unnecessary information.

I am currently using Grafana to show the values.

change the line graph to a bar graph in Grafana?

In the properties of the Grafana series, there is an option to show the previous value between data points rather than connect them linearly.

meanwhile i use influxdb_v2 and flux in grafana. but the the following settings are very similar in influxdb_v1 when i remember correct (only the query is different).

for visualization of the actors from my underfloor-heating i use the visualization-type “state timeline” and override the value-mappings like
grafik
to have a visualization like

for visualization where to put warmwater solar (automatic / manual mode) i use the visualization-type “time series” (for contact and number items) and override the graph-style (as suggested in the two answers bevore) like
grafik
the value-mappings i override like
grafik
to receive a visualization like

First of thanks to all of you for the quick response :pray:t2:

Where I wasn’t clear when I posted my question was that it is not so much about the visualization but rather that I like to have that value in the time series for computation:

The reason is that I have a rule that computes the time since the last change (“how much time has passed since the window/door was opened”. This rule didn’t really work with the persistence method “previous state value time” because the actually transition starting point is missing (see the blue arrow above). The green dot at let’s say 14:05 would compute 14:05 - 10:40 but not 14:05 - 14:00 which is totally wrong.

Note: I am aware that there would be other ways to achieve the same result but I was surprised that it doesn’t work with persistence “previous state value time” due to this missing transition starting point (I took me quite some time to understand why - only when I drew the above picture I started to understand).

I think the lastUpdate method from the persistence extensions should provided that time. The previousState would indeed come with the start time of the previous state.

You could argue that a lastChange method could also be useful to distinguish between update and change. But that does not exist in the persistence extensions.

1 Like

Created a PR for that: Persistence extensions, add lastChange and nextChange by mherwege · Pull Request #4259 · openhab/openhab-core · GitHub

2 Likes

Always missed that badly (and certainly had to do workarounds with .previousState(true).timestamp)

And that would not give the expected result. Let’s say the current state is 100 and the history is something like 25, 25, 50, 50, 100, 100. The previous state (skipEquals) is then 50 and the timestamp would be when it first changed to 50. However, the timestamp of the last change should be when it changed to 100!

It does work for nextState though.

EDIT: It is even worse, in the example above `.previousState(true).timestamp would return the timestamp of the second 50, and not the timestamp of the first change to 50.

There are several issues with .previousState(true) :slight_smile: so I’m waiting desperately for the merge…

Did you check whether it does work with rrd4j? (.previousState doesn’t at all)

I didn’t test, but I doubt it will give a good result. rrd4j does not store time of events accurately.

1 Like