Rule Machine - Time Since Event not working as expected

I am attempting to make a rule that speaks the bedroom temperature when I walk in the bedroom, however I do not want it speaking every single time motion is seen in the bedroom, so that as I walk around I don't get told the temperature over and over. To solve this I am attempting to use the conditional action "Time Since Event" on the motion sensor. I then state to not speak the temperature if the time since event is less than 5 minutes.

The rule appears to have all its conditions true, but when I trigger the motion sensor the logs show it skips the command due to it being false. I think what is happening is that the "time since event" timer is getting reset to 0 for the motion sensor before the speak command can be run. This seems like unintended behavior since it would practically make the time since event variable condition useless. I thought about making it a required expression before the trigger so that it would be evaluated before it got reset, however "time since event" isn't something I can choose as a "required expression" condition. Not sure why it isn't there.

Can't say for sure without seeing a screenshot or description of your actual rule, but this sounds like the most likely cause. A "motion: active" event as a trigger event will have a nearly-zero value for "time since event" for "motion" on the same device if that condition is evaluated early on in your actions. After all, that event is what triggered the rule. (This conditional still has uses--consider cases where you'd check a device that didn't trigger the rule, or a different attribute on a device that did.)

I'm not sure why this type of condition isn't available for required expressions, but my guess is that it has something to do with the difficulty of computing the true/false value in response to both the sensor itself and any change in time, so it could be an expensive computation (or really just a frequent series of small ones) or high-effort to program.

I would suggest taking another approach. Here is one, where I use the rule's built-in "private boolean" variable to restrict triggering for a certain time after the first trigger:

Required expression: Private boolean true

Trigger events: Motion Sensor active

Actions to run:

Set Private Boolean False (this rule)
Set Private Boolean True (this rule) --> delay 0:05:00
Speak: "Temperature is %blah%"

or for something that might be closer to what you actually want (just guessing!):

Actions to run:

Speak: "Temperature is %blah%"
Set Private Boolean False (this rule)
Wait for condition: Motion Sensor inactive --> duration 0:05:00
Set Private Boolean True (this rule)
1 Like

I tried to attach a screenshot but it keeps telling me that I cannot have media in a post ¯_(ツ)_/¯

I think your suggestion of using booleans will work. I could have it wait for a specified period of time before setting it back to true. Thanks for the suggestion, I’ll give it a try!

1 Like

This is a spam protection feature and will expire.

1 Like

So I gave this a try and ran into an issue. At first it seemed to work properly, but later I realized the rule had stopped working. Looking at the logs, it looks like it worked fine as long as the motion sensor was not triggered again during the wait period, however, once the motion sensor was triggered before the 20 minute wait time had elapsed it seems to have "forgotten" about waiting and then the private boolean was forever set to false causing the actions never to occur for the rest of the day.



You are missing the required expression I suggested, "Private Boolean True." (Without it, the rule will indeed keep retriggering with additional motion, and triggers cancel waits.)

Ah! Thank you. I was thinking that each rule triggering would be its own instance not affecting the other. That makes sense now.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.