# Catching a variable before a reset

**URL:** <https://community.homey.app/t/catching-a-variable-before-a-reset/102329>\
**Category:** Questions & Help\
**Created:** [January 26, 2024, 8:42am UTC](https://community.homey.app/t/catching-a-variable-before-a-reset/102329 "2024-01-26T08:42:46Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gerrit\_Fikse](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/gerrit_fikse/32/16406_2.png) [@Gerrit\_Fikse](https://community.homey.app/u/Gerrit_Fikse)\
**Post date:** [January 26, 2024, 8:42am UTC](https://community.homey.app/t/catching-a-variable-before-a-reset/102329/1 "2024-01-26T08:42:46Z")

</div>

Hello,  
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  
Gerrit

---

<div class="post-metadata">

**Author:** ![robertklep](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/robertklep/32/160628_2.png) [@robertklep](https://community.homey.app/u/robertklep)\
**Post date:** [January 26, 2024, 8:52am UTC](https://community.homey.app/t/catching-a-variable-before-a-reset/102329/2 "2024-01-26T08:52:38Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Wim\_Post](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/wim_post/32/56793_2.png) [@Wim\_Post](https://community.homey.app/u/Wim_Post)\
**Post date:** [January 27, 2024, 10:02am UTC](https://community.homey.app/t/catching-a-variable-before-a-reset/102329/3 "2024-01-27T10:02:54Z")

</div>

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.

 ![IMG_1695](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/b/2/b216b15ae81e711e98bef365b92385e18204f932.jpeg)

---

<div class="post-metadata">

**Author:** ![robertklep](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/robertklep/32/160628_2.png) [@robertklep](https://community.homey.app/u/robertklep)\
**Post date:** [January 27, 2024, 10:19am UTC](https://community.homey.app/t/catching-a-variable-before-a-reset/102329/4 "2024-01-27T10:19:25Z")

</div>

I still don’t understand what “it is reset external” means 🤷🏼‍♂️

---

<div class="post-metadata">

**Author:** ![Gerrit\_Fikse](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/gerrit_fikse/32/16406_2.png) [@Gerrit\_Fikse](https://community.homey.app/u/Gerrit_Fikse)\
**Post date:** [January 27, 2024, 11:45am UTC](https://community.homey.app/t/catching-a-variable-before-a-reset/102329/5 "2024-01-27T11:45:32Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![robertklep](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/robertklep/32/160628_2.png) [@robertklep](https://community.homey.app/u/robertklep)\
**Post date:** [January 27, 2024, 12:05pm UTC](https://community.homey.app/t/catching-a-variable-before-a-reset/102329/6 "2024-01-27T12:05:26Z")

</div>

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:

```auto
when (car charger counter is updated) {
  if (new value < previous value) {
    daily usage = previous value
  }
  previous value = new value
}

```

---

<div class="post-metadata">

**Author:** ![Rmb](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/rmb/32/79135_2.png) [@Rmb](https://community.homey.app/u/Rmb)\
**Post date:** [January 27, 2024, 4:51pm UTC](https://community.homey.app/t/catching-a-variable-before-a-reset/102329/7 "2024-01-27T16:51:49Z")

</div>

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