Catching a variable before a reset

I have a variable that is counting the days usage and is reset (external) around midnight. Can anybody help me in a direction to catch the value just before the reset? As it is reset external I cannot use the time, the clocks might differ slightly…
Thanks for the help

You’re going to have to explain what “it is reset external” means.

My power plug does not have a daily usage variable. So I calculate it myself:

At midnight i subtract the total power usage that I stored the night before from the current total power usage. After that I store the current total power usage again.

1 Like

I still don’t understand what “it is reset external” means :man_shrugging:t3:

What I have is Openevse (car charger), which has a counter for daily usage and that is reset to 0 around midnight. As homey and Openevse have independent clocks, they are seldom fully synchronised.
When I am charging during the night, I miss part of the usage if I have the moment of reading and resetting unsynchronised.
Hope this clarifies my question.

Ah, yes, now it does.

Perhaps it’s possible to update a variable with the current value that the car charger provides, and if a new value comes in that’s lower than the previous value, you can assume the value was reset and you can use the previous value of the variable as the “daily usage” value.

In pseudo code:

when (car charger counter is updated) {
  if (new value < previous value) {
    daily usage = previous value
  previous value = new value
1 Like

How many (milli) seconds are they out of sync? :grin: