Help Getting Historic day to day kwh of Powermeter from Influxdb


Ive tried several days looking and searching through the community and spent alot of hours trying to figure out a way to get historic kwh data from influxdb.

I want the possibility to show the used kwh per day for the last 7 days, under is a code snippet for yesterday

rule "Praktikant KWH Test"
when Item Sikringskap_3_TotalActiveEnergy_OUT_Scaled received update



But i cant seem to get it to work properly since it takes what been accumulated from now.todatemidnight + minus 1 day, ive solved the issue temporarly by using a cron timer at 23.59 to move the value over.

Is there anyone here who might be able to assist me with this issue?

Thank you and regards

Currently, Praktikant_TodaysTotalMinus1 is being set to the delta in persisted data between now and 0:00:00 (morning) of the previous day. Do you want Praktikant_TodaysTotalMinus1 to have the value of the energy usage for just today? If so, consider…

now [2019-11-14T02:25:42.209-05:00]
now.toDateMidnight [2019-11-14T00:00:00.000-05:00]
now.toDateMidnight.minusDays(1) [2019-11-13T00:00:00.000-05:00]

So, don’t use the minusDays(1)…


This will provide just the delta in persisted data between now and 0:00:00 (morning) of today’s date. If this is not what you are looking for, please explain better what it is you are trying to achieve :slightly_smiling_face:.

I think that is the correct approach; calculate and store each days “daily total”.

I have to apologize for not explaining thoroughly enough.
i have 7 items that i want populated with the kwh usage per day for the last 7 days.

i was hoping i could use the minusDays function to archive this. but i cant figure out how.

the cron funciton work to a certain degree, but if the rule / system down for any reason or i want to see a
kwh usage for another spesific device i cant go back in time easily and need to write a rule to start logging from that day and onward.
The picture inserted also shows how a bug would look since the cron rule triggered at midnight and then for some reason it triggered again at 1am.

Thank you and regards

Most of the solutions I see for this work the other way around. At midnight or a few seconds on either side of midnight, execute a Rule to reset the count for today and rotate the values stored in the historic Items.

Then you have a Rule that keeps a count for the current day any time the sensor updates.

No persistence is required (except for restoreOnStartup so you don’t lose your historic Item states on an OH reboot).

1 Like