Rule for Total energy consumed in kWh for day

Hi everyone, I’m new here and I’m a newbie.
My powermeter (owl inyuition) have a counter for the total consumption and i want to calculate the consumption for each day (in kW). I have modified a rule that i found in this forum:

rule "Imposta il consumo min e max giornaliero"
	Item Pow_2 changed or
		Time cron "0 0 0 * * ?" or
	System started
   val max = (Pow_2.maximumSince(now.withTimeAtStartOfDay, "rrd4j").state as DecimalType).doubleValue
   val min = (Pow_2.minimumSince(now.withTimeAtStartOfDay, "rrd4j").state as DecimalType).doubleValue

if( max != null && min != null) {
	Consumo_giornaliero.postUpdate((max - min) /1000)

Everythings seems to work fine, but the problem is that sometimes the value become “zero” so the calculation become wrong.

Can anyone give me a suggestion?
Should I look for another kind of approach?

You can try adding a condition to your if statement that will exclude the times there is a zero.

if( max != null && min != null && min != 0) {

Thank you very much. Now i will try and i will tell you if it work! :+1:

I’ll keep my finger’s crosses.:sunglasses::grinning:

The rule seem quite ok. Min ist the value at day start uand max at the day end. So max-min ist the consumption over the day.

The question ist why drops the system to zero and the goes back to the right value?

This is the result…

The minimum value it’s still wrong. I restarted OH for see the result.

Changing the Rule isn’t going to change past data already stored in the database. It will only prevent new 0s from being stored in the database. You need to manually remove the 0s from the data already in the database.