Required Expression Not Evaluating Correctly?

Iā€™m aware that the state of the required expression on the rule page header wonā€™t update asynchronously without a page load. It stays at false even after reload, despite both parts of the expression evaluating to true - Iā€™ll try to send a video later today or tomorrow when Iā€™m back home. Iā€™m also aware that the required expression and trigger are somewhat independent but the triggers will never be evaluated with the required expression evaluating to false.

I am not sure that required expression was ever meant to be used that way, wow that is pretty crazy! Of all the rules people have posted over the years, this must have the most things in required conditions I have ever seen.

I am not sure how I would rewrite the rule, but to me, you have overcomplicated this. While I am not an expert with Rule Machine, I think most of this should be in the actions part of the rule. My impression for required expression is that it might be used to limit something by date, OR mode, OR temperature, and so on,

Maybe post screenshots of your existing rule, and write out in plain language (without using rule terms) what you want to happen so people can make suggestions for how to simplify this somehow.

If you don't have permissions to post images directly into the forums, you can join the owner group here: Hubitat which will give you those permissions.

1 Like

Let me try again to explain. The result of the Required Expression that you see on the page itself is evaluated in real time. Those conditions result in a true as you are looking at them.

The value of Required Expression shown in the header is actually what's important as to whether your rule will run. Under the covers, that Required Expression is maintained as a result of events (not talking about the triggers in your rule). If those events are missed for some reason, the Required Expression will remain false even though if evaluated in real time would be true.

For example, if you have a required expression of 6 AM to 8 AM daily, and your hub was down from 5 AM to 7 AM, then that required expression will remain false until 1) the next day, 2) you go into the rule and hit Done, or 3) you had selected the option to "Evaluate Required Expression at System Startup" in the Required Expression definition.

1 Like

Iā€™m certainly open to other ways of doing this.

Hereā€™s a plain text explanation of what Iā€™m trying to do. I have 3 zoned Nest thermostats - one on each level of my home. Iā€™d like to turn the heat or cooling off when theyā€™re not in use - when Iā€™m away, and on levels where no one is sleeping at night (level 1 has our guest room so sometimes is used at night, sometimes is not). Also, sometimes the call to update the thermostat fails (e.g. a Nest server is down) so Iā€™d like this rule to have resiliency where it automatically retries when there are failures - itā€™s no fun waking up to a cold house in the morning.

Iā€™m curious why you think some of this belongs in the rule actions rather than the required expression. From my, admittedly amateur, perspective I would think that logic in the required expression would be best for determining if action should be taken while logic in the actions would determine what action should be taken. All of this logic is really just to determine if an action should be taken (i.e. if the current state is the desired one). I wouldnā€™t think that should go in the actions but am interested in other perspectives.

Will post a full screenshot of the rule when Iā€™m home tonight or tomorrow.

Got it. Iā€™m familiar with Hubitatā€™s use of events but Iā€™ll admit Iā€™m not an expert on them. I have hit Done (2nd condition youā€™ve identified) on this rule multiple times and it still continues to evaluate as true.

As an aside, if Iā€™m on the device screen for one of the relevant devices and I see the state change on the device state on the right side of the screen, that would indicate the event was properly processed, right?

Thank you and everyone else for your help so far. Iā€™m hoping you can help me figure this out!

The concept of Required Expression (formerly Predicate Condition) is relatively new. See the topic below for more background. As such, many of us don't distinguish between the if or what. We use conditionals for any refinement not inherent in the trigger for the rule.

I did use Required Expression in a few cases after that functionality was introduced, but have gone back to using conditionals exclusively.

1 Like

I use required expressions, but much simpler ones than this one. I tend to think of it like this:

Require expression = simple constraints on scheduling (note: not constraints on logic)
Trigger = When the rule should run
Action = What should happen, including logic that determines if a particular action should be taken or which action should be done.

My experience with RM has led me to make rules simpler and have more of them rather than more complex with fewer rules.

3 Likes

Yes!

5 Likes

I appreciate all the help on this so far. Based on all of your suggestions, I made a simple rule to test out the "between two dates" portion of the required expression but I'm still confused about the behavior.

I made a simple rule whose only action is to write a log entry that would trigger at a certain time of day. I added a regular expression that checks that the date is NOT between January 1, 2022 (as a local variable) and December 22, 2022 (as a hub variable) - since today is December 27, 2022 that should be true (and the hub does indicate that). However, whenever I open up this rule it has a "Not Installed" message in the header, even after clicking "Install Rule" and "Done." It also doesn't trigger when the trigger condition is met. I've attached a screenshot of the rule (thanks neonturbo for helping me get permissions for that). I would have expected this rule to trigger at 10:49, but it did not. I also can't even click "Run Actions" as I can in other rules because I can't figure out how to install this rule.

Any ideas on how to move forward? Thanks again for all the help so far!

Also, I just realized that when I try to install the app I get this error message (see screenshot). The message seems to indicate that the app would never fire based on the schedule (not sure if it's referring to the required expression or the trigger) but it seems to me that the app should fire any day after December 22nd at 10:49am (i.e. every day after today, December 27th at 10:49am). Hope this helps.

Hello again,

It has been a couple days so just wanted to see if there were any ideas on this. I'm still stuck. :frowning:

Thanks!

Is there a better place to ask these kinds of support questions? Or is this the place but it's going slow because people are on vacation for the holidays? I'm trying to figure out what the best path forward is but I'm feeling kind of lost.

You're in the right spot, it's just this is the holidays and folks are busy with vacations, family, etc. :slight_smile:

I'm not familiar w/the error you're seeing, but I'd suggest removing that rule and re-creating it. May just be some bytes that got crossed up.

3 Likes

I've tried recreating the rule (see image). Still getting the same error:
org.quartz.SchedulerException: Based on configured schedule, the given trigger 'app798Recur.stHandler' will never fire. on line 7920 (method appButtonHandler)

Is it possibly an issue with just my hub? Is anyone else getting the same error if they reproduce this scenario?

I was able to re-create any time at least one of these variables was in the past, even if the current range is within the present time. I'd guess this has something to do with how RM is trying to (otherwise) intelligently schedule things based on your DateTime variables to re-evaluate the required expression when those dates occur, but something about one of them being in the past must be tripping them up. Probably something for @bravenel to look into.

PS - I tested with hub variables so this isn't your problem, but it's generally recommended to avoid using local variables in required expressions. They don't generate events, so even if their values change, the required expression won't "see" that so may not get updated until something else happens. Perhaps this is something you just did for testing; just thought I'd mention it otherwise.

The required expression would only be evaluated when the rule is opened in the UI, never otherwise, so this would fail.

Will look into the error thrown...

1 Like

Thanks for the tip - I'll stop using global variables in required expressions.
In case it helps, I did try the same thing with global variables in the regular expression but I get the same error.

Hub Variables are fine, just not local variables.

Sorry, meant to write local - just typed the exact opposite of what I intended. :smiley:

Any updates on this?