I have now moved the data into the InMemory persistence and “converted” the Grafana dashboard to a Openhab Chart:
I first tried to display the total of the month with
time “last day of month”. This displayed the February data above “Mar” and April data above “May” … which was a bit irritating. That’s the reason why I changed the
time to display the total for every month on the “10th” of the month “yyyy-mm-10” which looks better.
I used the following rules to get the data into InMemory
JavaScript rule to get the 12 month totals for every year into a TimeSeries
//
// Year 2023
// Create a new TimeSeries with policy ADD
var timeSeries2023 = new items.TimeSeries('ADD');
timeSeries2023.add(time.toZDT('2024-01-10T23:59'),
Quantity('484.704 kWh')).add(time.toZDT('2024-02-10T23:59'), Quantity('437.797 kWh')).add(time.toZDT('2024-03-10T23:59'),
Quantity('494.810 kWh')).add(time.toZDT('2024-04-10T23:59'), Quantity('492.663 kWh')).add(time.toZDT('2024-05-10T23:59'),
Quantity('442.657 kWh')).add(time.toZDT('2024-06-10T23:59'), Quantity('442.288 kWh')).add(time.toZDT('2024-07-10T23:59'),
Quantity('446.869 kWh')).add(time.toZDT('2024-08-10T23:59'), Quantity('477.908 kWh')).add(time.toZDT('2024-09-10T23:59'),
Quantity('415.493 kWh')).add(time.toZDT('2024-10-10T23:59'), Quantity('476.385 kWh')).add(time.toZDT('2024-11-10T23:59'),
Quantity('497.806 kWh')).add(time.toZDT('2024-12-10T23:59'), Quantity('555.073 kWh')) ;
// Let's have a look at the TimeSeries
console.log(timeSeries2023);
// Persist the TimeSeries for the Item 'kWh2024' using the InMemory persistence service
items.getItem('kWh2023').persistence.persist(timeSeries2023, 'inmemory');
//
// Year 2024
// Create a new TimeSeries with policy ADD
var timeSeries2024 = new items.TimeSeries('ADD');
timeSeries2024.add(time.toZDT('2024-01-10T23:59'),
Quantity('558.205 kWh')).add(time.toZDT('2024-02-10T23:59'), Quantity('455.587 kWh')).add(time.toZDT('2024-03-10T23:59'),
Quantity('481.220 kWh')).add(time.toZDT('2024-04-10T23:59'), Quantity('483.733 kWh')).add(time.toZDT('2024-05-10T23:59'),
Quantity('451.596 kWh')).add(time.toZDT('2024-06-10T23:59'), Quantity('486.790 kWh')).add(time.toZDT('2024-07-10T23:59'),
Quantity('452.671 kWh')).add(time.toZDT('2024-08-10T23:59'), Quantity('446.660 kWh')).add(time.toZDT('2024-09-10T23:59'),
Quantity('445.123 kWh')).add(time.toZDT('2024-10-10T23:59'), Quantity('467.268 kWh')).add(time.toZDT('2024-11-10T23:59'),
Quantity('417.602 kWh')).add(time.toZDT('2024-12-10T23:59'), Quantity('80.970 kWh')) ;
// Let's have a look at the TimeSeries
console.log(timeSeries2024);
// Persist the TimeSeries for the Item 'kWh2024' using the InMemory persistence service
items.getItem('kWh2024').persistence.persist(timeSeries2024, 'inmemory');
at the begin of the year all 12 values can be 0.0 and you can step by step update every month with the next script which updates only the current month
JavaScript rule which does not update all 12 value but only the value of current month
//
// Year 2024
// Replace one month of the TimeSeries with policy REPLACE
var timeSeries2024 = new items.TimeSeries('REPLACE');
timeSeries2024.add(time.toZDT('2024-12-10T23:59'), Quantity('95.448 kWh')) ;
// Let's have a look at the TimeSeries
console.log(timeSeries2024);
// Persist the TimeSeries for the Item 'kWh2024' using the InMemory persistence service
items.getItem('kWh2024').persistence.persist(timeSeries2024, 'inmemory');
you can run this rule every day so that you can see how the month increase
The rules still need to be improved (update the values in the rule) so that they run without my help (fully automated)
Chart Code - see where to define the persistence - service: inmemory
config:
chartType: year
label: kWh2024
period: Y
slots:
grid:
- component: oh-chart-grid
config:
includeLabels: true
containLabel: true
show: true
legend:
- component: oh-chart-legend
config:
bottom: 3
type: scroll
series:
- component: oh-time-series
config:
gridIndex: 0
item: kWh2023
name: kWh 2023
service: inmemory
type: scatter
xAxisIndex: 0
yAxisIndex: 0
- component: oh-time-series
config:
gridIndex: 0
item: kWh2024
name: kWh 2024
service: inmemory
type: bar
xAxisIndex: 0
yAxisIndex: 0
tooltip:
Beside the work to improve the rules I’m still interested to know how to display Grafana dashboards within the Openhab screen (Grafana has much more possibilities to adjust a chart). Many thanks again to Rich who helps to overcome some gaps in my knowledge with some hints to get that done!