# How to store and calculate number of hours or days?

**URL:** <https://community.homey.app/t/how-to-store-and-calculate-number-of-hours-or-days/139872>\
**Category:** Questions & Help\
**Tags:** advancedflow\
**Created:** [July 16, 2025, 11:51am UTC](https://community.homey.app/t/how-to-store-and-calculate-number-of-hours-or-days/139872 "2025-07-16T11:51:36Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Walle](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/walle/32/48755_2.png) [@Walle](https://community.homey.app/u/Walle)\
**Post date:** [July 16, 2025, 11:51am UTC](https://community.homey.app/t/how-to-store-and-calculate-number-of-hours-or-days/139872/1 "2025-07-16T11:51:36Z")

</div>

In an advanced flow, how do I use a variable to calculate number of hours or days compared to current time?

I want to create some smart(ish) flows for my robot vacuum cleaner.

Some example scenarios:

Scenario 1: Instead of a automatically start cleaning on a fixed schedule, I want only let it run based following criteria:

1. Nobody is currently at home.
2. It has been at least 3 days sense last completed run.
3. The mop is dry (at least 3 hours after last time completed mopping run).

Scenario 2: Don’t vacuum the bathroom if someone have showered X hours ago. I don’t want to let the vacuum potentially wet floors, so I want it wait until the water have evaporated.

As I see it, the ideal way to solve this, if possible, is to calculate timestamps of dates in a (advanced) flow.

I’m open for suggestions, but I would prefer to solve this either with standard Homey features or with well maintained and versatile community app (I try to avoid to install apps in general).

---

<div class="post-metadata">

**Author:** ![DirkH](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/dirkh/32/78952_2.png) [@DirkH](https://community.homey.app/u/DirkH)\
**Post date:** [July 16, 2025, 2:39pm UTC](https://community.homey.app/t/how-to-store-and-calculate-number-of-hours-or-days/139872/2 "2025-07-16T14:39:54Z")

</div>

> [@Walle](#):
>
> - Nobody is currently at home.

There are cards (_ **WHEN** Last person left home_) , but that is not really reliable, at least not at my home. There Are some threads about this issue, just search.

> [@Walle](#):
>
> - It has been at least 3 days sense last completed run.
> - The mop is dry (at least 3 hours after last time completed mopping run).

You do not need to calculate, just use a timer.  
_ **When** mopping stops_  
\ ***Then**  
_Set mop\_is\_dry to **NO** _  
_Start Timer MoppingDone with 3 hours_

_ **WHEN** Timer MoppingDone finishes_  
_Set mop\_is\_dry to **YES** _  
etc.

---

<div class="post-metadata">

**Author:** ![Walle](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/walle/32/48755_2.png) [@Walle](https://community.homey.app/u/Walle)\
**Post date:** [July 16, 2025, 4:39pm UTC](https://community.homey.app/t/how-to-store-and-calculate-number-of-hours-or-days/139872/3 "2025-07-16T16:39:50Z")

</div>

Thank you for the timer/delay tip.

However, I’m a bit concerned about what happens if there’s an unexpected hub shutdown (e.g., due to a temporary power cut). Do timers survive restarts?

Also, this doesn’t fully address the core issue:

**“It has been at least 3 days since the last completed run.”**

As far as I can tell, delays are limited to 999 minutes (~16 hours), which isn’t sufficient for multi-day checks.

Additionally, I may want to trigger **different actions depending on how long it’s been** :

- After 5 days: send a reminder message.
- After 7 days: start vacuuming anyway.
- After 10 days: call my parents and force me to clean my home (just kidding… kind of).

So having access to timestamps or being able to compare the current time to a stored value would make the logic much more flexible.

---

<div class="post-metadata">

**Author:** ![Peter\_Kawa](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/peter_kawa/32/173848_2.png) [@Peter\_Kawa](https://community.homey.app/u/Peter_Kawa)\
**Post date:** [July 16, 2025, 4:54pm UTC](https://community.homey.app/t/how-to-store-and-calculate-number-of-hours-or-days/139872/4 "2025-07-16T16:54:58Z")

</div>

> [@Walle](#):
>
> concerned about what happens if there’s an unexpected hub shutdown (e.g., due to a temporary power cut). Do timers survive restarts?

❌ onboard delays don’t; I"d use them for small delays (seconds) only  
✅ timers from the Chronograph app do, while they count up towards a timestamp, set by the “duration” value.

The other things you mention can also be done with Chronograph timers. It has a “day” unit for instance, so no calculations with seconds or minutes needed.  
These timers can delay for 999 days, maybe even longer:

 ![Screenshot_20250716_190722_Firefox](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/b/f/bf9e3185625d29a0190078293a6916082ac35d53.jpeg)

See it counting down:

 ![Screenshot_20250716_191023_Firefox](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/2/8/28343cc159676c07f94277af78ed79da87d03886.jpeg)

1. 

You can count hours, or days etc. with variables as well:

When..  
every day  
Then..  
calculate numeric var “vac” as {{ [var] +1 }}

This increases the variable’s value by 1 each day.  
(at some point, reset it to 0 again)

Now you can trigger flows based on that number

When..  
variable “vac” has changed  
And..  
logic card value “vac” is exactly 3 (or 5 or 9 or 400)  
Then..  
Do things

or:

When…  
the last person left  
And..  
logic card value “vac” is exactly 3 (or 5 or 9 or 400)  
Then…  
-go vacuum  
-logic card set variable “vac” to 0

1. 

When you really want to calculate with timestamps, I’d recommend to read the [Better logic library app topic](https://community.homey.app/t/app-pro-better-logic-library-for-users/71876).

---

<div class="post-metadata">

**Author:** ![Walle](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/walle/32/48755_2.png) [@Walle](https://community.homey.app/u/Walle)\
**Post date:** [July 17, 2025, 10:16pm UTC](https://community.homey.app/t/how-to-store-and-calculate-number-of-hours-or-days/139872/5 "2025-07-17T22:16:16Z")

</div>

Thank you for your reply, really helpful.

I decided to go with the Chronograph app for this setup.

**Current setup:**

1. A Chronograph stopwatch tracks the time since the last completed vacuum run.
2. When the flow is triggered (e.g. nobody is home), it checks the stopwatch duration:

- If it’s more than 3 days, a vacuum job is started, and a "cleaning in progress” Chronograph timer is started (set to 1 hour).

1. When the robot reports “Finished cleaning”, the flow checks if the “cleaning in progress” timer is still running:

- If it is: it stops/resets both the timer and the stopwatch.

The purpose of the “cleaning in progress” timer is to distinguish automated runs (triggered via Homey) from manual or spot cleaning.

Since I can’t directly determine the type of cleaning job completed, this acts as a temporary self-clearing flag indicating that a Homey flow initiated the vacuuming.

This setup is less than a day old, so I haven’t tested it in real-world use yet, but initial manual testing of the flows looks promising.
