Triggering based on time variables with offsets

I am putting a timestamp into a global variable and want to trigger a rule only if this timestamp is more than X seconds away. I found out that when I compare time variables there is no way to compare against the current time with/without an offset. I tried doing it the other way by creating a trigger between two times and using the variable, but then again there was no way to put an offset on the variable.

It seems like I'm missing something or this little bit was missing in the implementation. If this doesn't exist yet, can we please add it?

I will have to do some ugly juggling with extra rules and variables to work around what could have been just a quick check

"More than X seconds away" is a condition, and not an event ("at X seconds away" would be an event). So, you won't be able to use that for a trigger. If this was not a mis-speak, I'd suggest explaining what you want to accomplish with the Rule. Actually, I'd recommend that either way--there might be another solution regardless. :smiley:

But if you want this exact implementation, the only way to think of is the one you hinted at: create a local variable (hub variable would also work but is not necessary for a condition in the same Rule), set it to the time of the other variable plus/minus the offset, and use this variable instead. Whether it would be easy/possible to add the offset as a built-in feature, I can't say.

But, it's more than X seconds away for a range of time (now, until X seconds away, assuming now is before X seconds away). When do you actually want to trigger the rule?

If the answer is you want to trigger it exactly X seconds before that variable time, then you will need to create a second Hub Variable, and set it to the first one minus that offset, like this:

This assumes the timestamp you want to trigger before is 'dateTime' and the new one is 'timeV'. This rule could be triggered by 'dateTime' changing, so that 'timeV' would always represent a time before that.

We will add the option to specify an offset to a variable time trigger in the next release.

4 Likes

Yes, I meant as a condition on the trigger or predicate.

That is sort of what I was referring to as workaround, but it's hard to maintain because I'll need to do this for each offset.
Happy to hear you're adding it natively in the next release. Thank you :slight_smile:

Download the Hubitat app