How often do rules run?

So I’ve created a rule that if the temperature in the bedroom gets over 19.9c, and HSM is Armed Night turn on the fan. Works great.

My problem is how to control how often it runs? For example, when i came to bed tonight HSM was armed as expected by another rule, all fine.

However my fan rule doesn’t run right away, and I can’t find a way to control how often it runs?

I thought I’d change my nighttime routine rule and have it poll my bedroom thermo 30 seconds after arming, to see if forcing that information change would fire the rule but it didn’t work, right now in RM the conditions are showing as both true but the fan isn’t turning on and in the logs the rule hasn’t run for 20 minutes. I’m not sure how to set the frequency for it to run?

The terminology for this trigger is misleading. Although it says "becomes" it actually means "is". That's because it will trigger everytime it receives a temperature reading in that condition, not just the first time it "becomes" true to that condition. So it will trigger for every reading from the sensor where the current temperature satisfies your condition. And that will depend upon how that specific sensor works (eg. when it decides to report the value to the hub).

The normal way to deal with this is to use a Private Boolean. This is a binary variable, local to each rule, that you can set true or false and use to only trigger the rule once in such a condition. You will find examples if you search for it. So the first time this condition fires you would set it, say, to false, and then use a conditional to first check for false and not again run the action if so. Then you would have a further conditional statement or use a different rule to set the PB back to true again when sensible to do so, ready for the next time you want to check the temp is crossing that boundary again.

2 Likes

To add to the above, as-written, your rule won't do anything unless a temperature reading comes in (and it's greater than your threshold--any reading, not just the first such reading, as explained above). The IF in your actions that checks the HSM and fan status does not cause anything to be evaluated just by being there except when a trigger matches (or your rule actions are otherwise run, e.g., by invoking them from another rule).

1 Like

Hi again. In case it helps, here is one of my rules (actually I don't use it any more, but maybe it will help you) which uses a PB and triggers on a temperature reading similar to yours....

This rule is designed to automatically control the AC unit when the temperature falls below a threshold. Hope it helps!

3 Likes

Thanks! I’ll look into the boolean switch.

However i’m still confused as to why, even when both conditions are showing as true in RM as my original screenshot the rule didn’t take any action until 20 minutes later? Looking in the logs the rule runs sporadically and when it eventually ran it found the conditions met and activated the fan. I’m confused as to why it didn’t run as soon as the trigger conditions were met and then action conditions were met?

So in the end the fan came on 20 minutes later.

However in the mean time the temperature poll had run three times and confirmed a temptation over 19.9c and was showing that the temperature was 20 in hubitat but the trigger still didn’t fire until 20 minutes after? I’m trying to work out in my head what the logic is behind when a rule runs and why it didn’t run.

Are you saying that my trigger only fires specifically if the temperature moves from 19.9c to 20c and won’t fire if the temperature is already over 20c?

Ok, so after some reading on private boolean and local variables as I didn’t understand them at all I’ve rewritten the rule, and I think this will cover fan on and off rather than having two separate rules as I did?

Should this work? Have I missed anything?

1 Like

One thing though should I take out the fan on/off condition as if someone turns the fan on without the rule it’ll throw it all into chaos?

You should probably add a trigger for HSM Status is Armed Night. That way the rule will run and check for the correct temperature directly on arming and not just next time the temperature is updated.

That’s a great idea, thanks, i’ll change it now


Made the edit.

1 Like

Do you think that the “if fan off” Or “if fan on” part may cause problems? I.e if the wife turned the fan on via alexa then the rule won’t trigger because the fan status is already on?

If I remove that requirement the rule should still run fine shouldn’t it?

So more like this:

This should then still trigger if the fan status is changed by alexa or anything else?

Yes, this should work, since I don't use RM I don't know if this is a rule that is to complex and it should be broken down into more rules for the sake of performance, but yes, this should work.

can you please explain in words what PB is trying to accomplish? I don't understand the point of these... :confused:

Thanks!

@bertabcd1234 posted an excellent explanation of what a Private Boolean is and how to use Boolean status in a rule a couple months ago. Here is his post:

3 Likes

I'd suggest an END IF at the end of your rule as well.

I think switching to 'changed' for your temperature is going to work better than 'becomes' as well.

I suspect part of the reason your first rule logic failed was due to no change in the temp. So the current temp == existing temp, either at your trigger or at the device measuring temp. Can't become if it already is. But I could be wrong!

S.

1 Like

I didn’t understand the need for PB either but basically it’s a virtual switch to signify if the action is already active. So for my rule it shows if the Conditions are already met then the “switch” will be active and therefore doesn’t need to be turned on again.

So this almost worked but for some readon it wasn’t changing the boolean when triggered but I think i’d maybe not set that up right?

So i used something @BorrisTheCat taught me on another post and mapped the boolean variable into a virtual switch and have that flipped on and off with the actions.