[Scènes] Comparing a timestamp to the current date/time or to “today”

Hello,

I am currently working on a Roborock integration that can expose the date of the last cleaning as a timestamp.

The goal is then to be able to build a scene of the type:

When the house becomes empty
→ retrieve the last cleaning of the robot
→ continue only if no cleaning has been done today
→ start cleaning

The integration can easily expose:

Last clean start = 1786958400

The problem is that at the scene engine level, it does not seem possible to simply compare this value with a relative date such as:

beginning of today
today
now
yesterday
X hours ago

A condition like this would be particularly useful:

Last clean < beginning of today

or, more ergonomically:

Last clean
→ is not today

The idea would therefore be to add generic support for dates/timestamps in scene conditions.

timestamp < now
timestamp > startOfDay
timestamp > now - 24h
timestamp isToday
timestamp isYesterday

This could eventually go through scene variables/formulas, for example by exposing values or functions like:

now()
today()
startOfDay()
endOfDay()

The need is not specific to Roborock. This would also allow working with:

  • date of the last movement;
  • last opening of a door;
  • last startup of a device;
  • last recharge;
  • last event from an integration;
  • any device exposing a timestamp.

In my specific case, this would avoid adding a feature cleaned_today in the Roborock integration, while the generic information last_clean_start is normally sufficient.

Would this be something that could fit in the scene engine?

Will the following request, accepted by Pierre-Gilles, allow you to meet your needs?

Hey @StephaneB

Yes, this request seems to cover a large part of my needs :+1:

In my case, the Roborock integration directly exposes the timestamp of the start of the last cleaning (last_clean_start). Therefore, I don’t need to store the current time at the time of an event, but I need to be able to compare this timestamp with the current date in a scene.

For example: last_clean_start < start of today, to know that no cleaning has been started yet today.

If the feature proposed in this topic allows both to retrieve now/today’s date and to make comparisons or calculations with a timestamp from a feature, then yes, it would meet my needs.

The two requests could probably be grouped around generic support for dates/timestamps in scenes. :slight_smile: