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:
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.
The only ways to achieve what you are after right now on those default charts are:
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.
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: