RM 5.1 DateTime variable comparison

Hubitat version 2.3.0.124. Comparing two DateTime variables in RM 5.1 appears to only compare the Time component, not the Date. This results in comparisons that should pass (e.g 5 pm yesterday < than 2 pm today) failing - a dateTime from yesterday compares as greater than a dateTime from today.

Here is a sample rule:

In this case the trigger hasn't fired in a while, so variable NextPoll is from yesterday, 9:40PM on 12-27 is comparing as greater than 9:37 PM on 12-28:

the condition is still false.

Logging shows the problem:

Aside: The mental model here being used is the traditional one of "datetime" type being a point on the timeline from past to future. These can be compared as less or greater than, subtracted to create a duration, etc.

I agree that you've probably spotted a bug. As a workaround, I believe that you could use the approach that I use to tell if the litter drawer has been open for 30 seconds or more, modifying appropriately (convert your 5 minutes to 300 seconds, etc.) the math.

This is simply to show that the math does work if a different approach is used:

1 Like

This is odd, because it works for me as expected:

Notice what is displayed in black parens in the rule above, and in your rule. Yours shows that it is comparing times, and the one above shows that it is comparing both date and time.

My suggestion is to edit the condition of NextPoll <= Now. Is this an older rule? Comparing full DateTimes only started pretty recently (as in recent build), so it may just be stale. @fair.rob

1 Like

@bravenel Thanks for the reply. Editing the existing rule, or creating new DateTIme variables in the same rule didn't address the problem. I then tried an entirely new rule, and it works correctly as you show above.

1 Like

I created a brand new rule and it is failing. So, how do we get this registered as a bug.

More reflection of issue


Tried 24 hour time too.... Looks ever more odd:

I do set it with a 120 minute offset, so I am not sure if that is related to the issue.

And.... Here is the workaround.... I was comparing a Local Variable to a Global Variable. I created a local variable and set it to the global variable at rule instantiation and now it is working.

Download the Hubitat app