Energy consumption calculation - problem with reset

I have a item where is value of the energy consumption normaly still increasing.
But when there is power shut down or unit restart, this counter start again from zero :

To calculate consumption from this value for actual day, I’m using function

val ZonedDateTime zdt = ZonedDateTime.now()
val actual_day = zdt.withHour(0).withMinute(0).withSecond(0)
val today = Cons_Value_as_Number.deltaSince(actual_day) as Number

It’s working when there isn’t a restart, because then I have a negative value for this one day when reset to zero happened

Do you have any idea how to treat this special case, when counter goes to zero?

Thanks

Alex

if (Cons_Value_as_Number.minimumSince(actual_day).state == 0) ???

As example. from 0:00 till 8:00 value increased from 200 to 250
Then there is a reset to zero and till 10:00 when calculation is done increased to 20

My function will show -180 (20-200)
but
Real consumption is 70 ((250-200) + (20-0))

Not sure how your if (Cons_Value_as_Number.minimumSince(actual_day).state == 0) ???
will solve my problem

minimumSince() returns a historic item. Historic item has a timestamp. Convert this timestamp to a ZonedDateTime, substract one second.
Use deltaBetween(startOfDay, timestamp) to get the sum until reset
Use deltaSince(timestamp) to get the rest of day
Add both values and you are done.

1 Like

oh so, thanks
Will try