Compare present time to hub variable time in a conditional expression?

Like so many in this RM forum I think I am must be going brain dead. I have 50+ rules, some quite complex, but I can't figure this out for the life of me. I am feeling I may have finally killed too many brain cells with my last drink! :crazy_face:

I am trying to write rule that triggers only when a lightning strike is detected within a certain distance of my home. I also have required expressions of certain modes and certain presence sensors being present. That part seems easy.

Then, when the rule triggers, I want it to run some actions which include saving the date and time of that occurrence in a hub variable.

Then, the next time a lighting strike occurs within the specified distance, I want the same actions to run only if that next occurrence is at least 15 minutes since the last time there was strike within that specified distance (stored in the hub variable). If it is, run the actions including storing the hub variable again.

The part I can't figure out is how to determine if the current time when the rule triggers is at least 15 minutes since the stored time.

I may be making this way more complicated than it needs to be, but any suggestion are welcome.

Thanks in advance,


Can you do that with a conditional trigger instead of variables?

I don't think the Time Since Event comparison will work because there may be many lightning strikes between the first one that triggers the rule and the next one that might trigger the rule that don't meet the lightning distance trigger requirement. The event that is used in the trigger is strikeDistance. The rule is only triggered if the strikeDistance is <= 8. I want the actions to run only if there is a strike within 8 miles. Then, there may be more lightning strikeDistance events that may or may not be <= to 8. Regardless, even if there is a strike that is <= 8 miles, I don't want to repeat the actions unless that strike happens after 15 minutes.

The actions being run are an announcement on a speaker and turning on a strobe by the pool. If there are many strikes within the 8-mile limit, I don't want the announcement to keep happening.


You could try the old trick:

Required expression: Private Boolean true

Trigger event: (whatever)

Actions to run:
Set Private Boolean False
Set Private Boolean True --> delay 0:15:00
(whatever other actions)

1 Like

One way I can think of solving this is by using two rules instead of one. The first rule would be something like:

Lighting strike (only when Hub Variable 1 is 0)

Set Hub Variable 1 to 1 (i.e. first rule has run)
Set Hub Variable 2 to current time
Run rest of your actions
Wait for Event - 15 minutes elapsed time
Set Hub Variable 1 to 0 (i.e. no lighting strikes within 15 minutes)

Rule 2 Trigger
Lighting Strike (if Hub Variable 1 equals 1)

Rule 2 Actions
Cancel Rule Actions of Rule 1
Set Hub Variable 3 to current time
Set Hub Variable 4 to time difference if Hub Variable 2 and 3
If Hub Variable 4 is equal to or greater than 15, run actions
Wait for event - Elapsed time of 15 minutes
Set Hub Variable 1 to zero

I'm short on time, but I think the above can get you pretty close.

1 Like

Thanks for the replies guys. You both got me thinking

@bertabcd1234 I had forgotten about private Boolean. I haven't used it in a while. I think this might work. Nice and clean without the need for another rule as I had setup already. One question: The way you laid out the Actions, You set Private Boolean to false, then immediately to True after a delay of 15 minutes. Then you execute the rules. Won't that cause the announcement and the strobe to not be executed until after the 15 minute delay expires? Shouldn't I put the announcement and strobe in between the two Private Boolean commands?

@JB10 While I think Bert's might be more clean, this suggestion did answer a question for me about how I would accomplish a pure compare in times between now() and some past saved time. It requires more Variables but it would work. It has gotten me thinking about some other rules I might want to do that might benefit from this.

I tried the Private Boolean first, but then it just so happens that in the current Beta (General Release Candidate there is new switch which essentially performs the same way as this use of private Boolean, so I went that way. Here is my rule:

I also added a hub variable that gets set to the strike distance in order to avoid a rare but possible looping situation if the last strike was within the 8 mile limit. This is unlikely since storms typically keep moving away before they die, but it is possible. Since I can't set the attribute of the sensor, which holds the last distance, I had to do this, and reset from the rule.

Thanks again for you suggestions! I you have additional suggestions let me know.


No, not as long as you did it like I did. The delay on the action (done by enabling the "delay" option when creating this particular action) schedules that action for the specified time in the future, then immediately moves on to the next. This is different from having "Delay" as its own action, where the rule will effectively pause at that point until the time is up before resuming the next action.

1 Like

I was just checking my log after the thunderstorm that just went through and noticed that very thing. Thanks for that confirmation. I guess I knew that from long ago, but clearly I forgot that.

Thanks Again,