Feature request: Condition that compares variable to now()


#1

Hi,

I'm trying to implement an automation that is triggered based on a comparison between the now() value and a timestamp that I've set in a global variable (e.g. motion_sensor_last_active_at).

My current approach is to have a "Tick time_now" rule that is triggered every second and updates a global time_now variable to now() in seconds.

Then I use a variable comparison condition to compare motion_sensor_last_active_at to time_now.

I suspect the "Tick time_now" rule is pretty intense and every so often, I receive a bunch of "org.h2.jdbc.JdbcSQLException:" errors where periodicHandler is unable to find a Column or hits a general "java.lang.NullPointerException".

I wonder if, in addition to the relative to variable comparison condition, we could have a relative to now() in seconds comparison, which would do away with the need for a "Tick time_now" rule that runs every second?

Thanks. I'm a big fan of your product.


#2

Just randomly poking around, what I'm trying to do here would also work for Rule machine question and avoid queuing up a bunch of delayed actions.


#3

You can't set global variables to time values. They can be strings of text, but can't be used in the way you have asked, yet at least.


#4

You CAN set global variables to time values.
Set vTime to now() in seconds.


#5

And how exactly would you put that expression into Rule Machine?


#7


#8

And how would that be used to do anything? You can force a rule to be triggered at a particular time using that. That is u less you run that rule every second, which I'm pretty sure would lock up your hub pretty fast.


#9

you definitely can set global variables to time now(). here is bruce's post explaining:

here is an example of a rule that I use to track presence:

try to remember that hubitat is an event based system. when writing rules, try think of what events you need to monitor. it doesn't have the hardware to constantly monitor everything, so you have to be careful with how you construct your rules to keep things from getting overloaded.


#10

You can put now() in either milliseconds or seconds into a global variable. Let's say you use seconds. Suppose you have a rule triggered by a motion sensor active. One of the actions could be to record the time by putting it into some gv. Suppose you have some other rule that is triggered by something else. It can put now() into another gv, and then subtract the two gv's to know the elapsed time between the events, etc. You can do comparisons on the time values placed in the gv's also.

You never really explained what it is you want to accomplish. You certainly do not need a once-a-second rule to do it.

You can get current hour, current minute, and unix time (now) in seconds whenever you want. With math you should be able to do any transformations you need, and any conditional logic as well.


#11

See Bruce’s example in the message ABOVE. That is what I’m doing in the rule I posted earlier.


#12

Okay....but that can also be accomplished using Private Boolean also. Why would you need to know the time difference between two motion events? I just don't see a practical use for this.

I believe that the original question was about trigger actions at a specific time set in a global variable. Which, I believe isn't possible, as I originally stated.


#13

Not quite what he said:

He never filled us in on what the comparison would be, but let's say the comparison is that the difference between the two is >= x seconds, and he wants to trigger his rule then. What he's missing is that he could have built x into a rule triggered by the motion sensor active, such as Run Actions Rule ZZ Delayed by x seconds. Many of these time based automations are easier than they first appear, and what needs to be adjusted is the thought process about how to accomplish the desired outcome.


#14

And I would still love to see an episode on Hubitat Live where you develop your logic and build a rule. We all need to learn to think like you. :wink: