Any suggestions regarding Persistence on change?

Hi All,

Today, I am using MariaDB JDBC persistence service with an every change strategy.

Recently, I realised some of my z-wave devices were sending energy reports every 5 seconds.

This was clogging up my z-wave network, adding latency etc, so, in the z-wave device config I changed to only send an update if the change in power usage is >10%.

Great, my z-wave network is much healthier now.

However, my persistence services, and especially my charts start to look very spikey.

This is my Fridge with reporting every 5 seconds, you can see the usage rests at 0 for long periods, then spikes up to ~500 watts briefly as the pump starts:

This is the same device after changing to 10%

I know I could modify my persistence strategy to log every 5 seconds, but this would add loads of un-necessary data points to the DB.

Ideally, what I want is a persistence strategy that logs the start and end of each plateau:

Something like this:

Time Watts
10:00:00 500
10:00:02 *500
10:00:02.1 1
10:00:30 *1
10:00:30.1 500

The * values are missing today, are there any techniques that can help me achieve this?

Thanks in advance for any suggestions!

Will

You don’t need to mess with what’s persisted. You just need to adjust how it’s charted.

MainUI Charts are built using Apache ECharts and while MainUI only presents a few of the more common options to you in the forms, you can add any property supported by ECharts to the YAML config.

So in this case, you want to change how the line transitions from one value to the next. The default is to not step. It directly connects one point to the next which gives that saw-tooth appearance to the charts. However, if you change this by setting the “step” property for the time series to “end” to “start” or “end”.

To do this, in your custom chart click on the time series config and choose “edit yaml” and add step: start as a property.

component: oh-time-series
config:
  name: Outside Temp
  gridIndex: 0
  xAxisIndex: 0
  yAxisIndex: 0
  type: line
  item: vWeather_Temp
  service: rrd4j
  step: start

See Step Line - Line - Common Charts - How To Guides - Handbook - Apache ECharts for more details about the step property and see the menu on the left on that page for more properties you can apply to a line chart. Some of them are supported by OH already (e.g. area) but others are not (e.g. smooth).

Unfortunately this won’t help with the automatically generated charts (i.e. the ones generated by the “Anaslyze” action of the widget. To control how the line is drawn on those charts I opened [MainUI] Add ECharts properties to Item · Issue #3957 · openhab/openhab-webui · GitHub.

The only ways to achieve what you are after right now on those default charts are:

  1. Save the Item’s state more regularly. You could add an everyMinute strategy or what ever is appropriate. Note that rrd4j already has a requirement for the everyMinute strategy and it remains a fixed size. So it could make sense to use rrd4j for charting.

  2. Take the job of when to persist the values away from the persistence config and control when and what gets persisted from a rule. You’ll exclude this Item from being persisted by any strategy (except maybe restoreOnStartup). Then create a rule that triggers when ever the Item changes state. The body of the rule will save the current state to persistence and then save the new state.
    In JS (OH 5.1) it would look something like:

items[event.itemName].persistence.persist(time.toZDT(), event.oldState, 'jdbc');
items[event.itemName].persistence.persist('jdbc');

This should be close enough for charting purposes.

Note this will not work for rrd4j nor mapdb.

1 Like

Fantastic - thanks Rich !

In my case I had to use step: end to achieve my desired result.

When I looked at my DB, I realise I have >1m records in the table for this fridge energy consumption.

Most of these values are pointless now I have the step setting in my charts.

Next step from my side is to clean the redundant entries using some SQL magic.