Persisting and charting pulse (energy) counter


can somebody point me to an example on how to implement a pulse counter, persist it in mysql and show charts based on it? I am sure I am not the first one to do it but I could not find the fitting topic.

My setup is 1.8.1, the pulses are coming in through MQTT. Unfortunately one pulse comes in as a True/False sequence, so I would to have to filter only True’s or False’s, too.
Alternatively I could persist the pulses in MySQL directly as timestamps, maybe this is easier to implement.
Finally I would like to have charts for one day, 5 min intervals. for one month, daily interval, one year dayly intervals for 14 counters.

Any help welcome.

The charting capability built into OH is pretty basic. It does not provide really strict control over most of the things you may want to be able to adjust. It supports chart periods of


The intervals are automatically calculated based on how often the data is stored in persistence.

Also, the charting engine will not give you a nice flat graph for this sort of binary data. For example, if you have an ON and then an hour later an OFF the chart will draw a diagonal line between the ON and the OFF giving you a saw toothed chart rather than one that is square.

So in short, if you are very particular about your data periods or how you want the chart to look you are better off looking for an external third party tool. Influx appears to have a lot of good charting and data analysis tools.

As for saving the data you can set up persistence and have persistence automatically save all the Trues and Falses which I believe gets saved in the DB as 1s and 0s. The persistence engine stores both the data and the time so, for example, to get the number of True’s in the past hour you could do:


Persistence Documentation
Charting Documentation

Thank you,

that helped a lot in that I will not longer try to solve it within openhab.I understand the way is to render it using a web server maybe as jpg or svg. I guess openhab can insert a jpg in the sitemap.
I will definitely try Influx, I have some experience with D3.js, too.