Rule Machine - Require Expression and Wait condition not firing

I have been slowly improving some of the rules I have and make them slightly more sophisticated. I have a rule where if the time is between 10 am and sunset and the outdoor temp is above 80 degrees it turns on some ceiling fans in the house. The rule then waits for either the temp to drop below 72 degrees or for the time to be one hour past sunset and then turn off the fans. I also added a local variable to not spam the fan with commands every time the conditions are met. The first half of the rule works great - the fans turn on when they are supposed to, however the fans fail to turn off after meeting the wait for condition for the allotted time.

I suspect it has something to do with the fact that the required expression for the trigger stops at sunset and the wait condition and 2 actions are queued after that time. I assumed that leaving the "Cancel pending actions while Required Expression becomes false" turned off would allow that queued actions to fire after the wait condition is met. Maybe not? Anyways here is the rule:

As an aside, does a rule like this use too many hub resources as this time of year it is run every time the exterior temp changes between 10 am and sunset (usually each 1-3 minutes). I could make this rule simpler by using 2 rules where one just turns on a logical switch when the temp is above 80 and the other triggers on when the switch state changes, but I was trying to do this as a single rule. I cant figure out why it doesn't work.

Turn on logging and post logs for this rule.

I had logging enabled. Here are the logs from sunset to the time that the condition should have turned off the fans. The line that appears to be the issue is "Action: failed to stay for 1:00:00, still waiting: Tempest Weather Station temperature 76.4.


Are these the correct logs? The rule shows the action as Wait for expression but the logs show Wait for events.

Sorry. That was part of my troubleshooting to date. I originally had the rule setup with the wait for events as either being 1 hour past sunset OR the temp is below 72 degrees for an hour. That are the logs that are showing. When I ran into the issue I then tried changing it to a wait for expression that is the snapshot in the first post. I get the same result either way. The rule should work with either wait condition (I would expect).

I can see now that you pointed that out that the wait state is applying the condition of waiting for an hour to the specific time (which cant happen), but the rule shouldn't do that becasue I set up with wait for events as either the temp condition for an hour OR the specific time (without the hold for an hour). I will change to rule back to wait for events and remove the requirement that the temp be held for an hour and see if that makes a difference. I wonder if this is a bug.

Wait for events seems like the way to go and I agree that the 1-hour shouldn't be applied to the time. Let me try a simple example to see if I can reproduce. If so, likely a bug and we can get Bruce involved.

I was able to reproduce the bug. @bravenel this Wait for event for a certain time fails when the other event of the Wait is waiting for the duration.


I will look into it.

Found this bug. Fix will be in the next release. Thanks.

1 Like

Thanks, Bruce! Nice find @kencoon, hopefully this will get your rule working as intended.

Wow. That is great. Thank you for helping out and confirming the bug! Glad it will be fixed soon.

So which is the right way to approach a WAIT within a rule where you are waiting for the temperature to reach a certain level?

Is it WAIT FOR EXPRESSION or WAIT FOR EVENT ?

I had started with EVENT expecting that's what I'm looking for, a report from a temp device to move the rule past the WAIT. Then I realized when the rule kicks in after passing a REQUIRED EXPRESSION that the temp device might not be reporting straight away so I changed it to WAIT FOR EXPRESSION.

I'm really not clear on the difference or advantage between the two in this Use Case.

Wait for event will (always) wait for an event to come in that matches the criteria. Wait for expression will continue if the specified expression is already true, otherwise it will wait for it to become true (the result of an event, so effectively the same at that point). Sounds like you might want the latter, but it depends on what you really want.

3 Likes

image

So this is what I see when the rule passes my Required Expression criteria and then sits waiting, presumably, for a Temperature Report to Trigger. In other words, the rule doesn't initialize and then go, "hey, what's the temperature on that sensor", it waits for a report to come in?

Clarification, this query no longer has anything to do with the Wait for Expression, I believe that to be working properly.

EDIT:
Got it, thanks. Trigger vs state; and my problem may be device related:
"
Triggers represent events, which are an instant in time — for example, motion becoming active, a switch turning on, or the time becoming 8:30 PM. If you want to check a state rather than respond to a specific event, you can do so in the actions (using a conditional actions), or you can use a required expression to restrict triggering when a certain condition or combination of conditions is not true.
"

A required expression becoming true or false does not do anything on its own, if that's what you're asking (actually, in recent versions they can cancel timed or scheduled actions when they become false, matching a similar option in Basic Rule, but this is still true in general). For example, if it becomes true, you'll still need a trigger event to happen/match beforehand your actions will run.

Any idea what might cause the log to show null values?

I'm not sure. What is the actual event or action?

Between two times

What's odd is the nulls are in the log but the rule works.

Same thing comes up for satisfying the Required Expression which tests NOT away, time between two times, and Priv Bool being True

image

EDIT: Adding Rule. Let me just say this started with the simple monitoring of "Motion - Hall" Temperature and since I have added other measuring sensors JUST TRYIN to get the dang rule to trigger. The fundamental goal was to turn on a small AC unit between two specific times IF the temp was above a threshold and to turn it off by the end of that time window or before if the temp was below a threshold.

My guess is there might just be something odd in the code that generates those log entries. @bravenel would be the one to suggest what more might be helpful to figure it out if the description above isn't enough.

You should post a screenshot of the rule. Without anything to look at, my guess would be incompletion of certain inputs within the rule.