How to store and calculate number of hours or days?

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).

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.

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.

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.

:cross_mark: onboard delays don’t; I"d use them for small delays (seconds) only
:white_check_mark: 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:

See it counting down:

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

When you really want to calculate with timestamps, I’d recommend to read the Better logic library app topic.

2 Likes

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.

2 Likes