Required Expression false .. but it isn't

I'm sure there's a simple explanation, but one of my automations isn't triggering (Rule-5.1 under and the rule says Required Expression false in the rule name banner. However, the required expression isn't false, as shown in the Define Required Expression dialog. This isn't a new rule .. it's been around unchanged since Sep 8, 2022.

1 Like

Please show logs screenshot.

On previous tests, there was nothing in the logs for the rule because none of the logging options within the rule were enabled. There was the log entry for the motion detected, then nothing for the rule.

I went in and enabled logging in the rule, clicked Done, and that fixed the rule. The Required Expression false went away and the automation works.

I do have a theory. We had a power outage this morning for almost two hours and the UPS that the hub is on depleted. Sunrise occurred during the time the hub was down.

Is it correct to say that the True/False shown in the Define dialog is showing real-time status (as of when the page was refreshed) but the Required Expression false in the name banner and whether or not the rule can trigger is not real time?

The time sunrise or sunset occurred while the hub was off that could definitely explain it. I believe I have had this issue in the past. Just hit done on the rule and it will probably update.

1 Like

I went whole hog on using Required Expressions out of a fear of setting up unexpectedly reoccurring rules.

Ever since I'm thinking I avoided one quagmire for another as I have seen more than one case of needing to set up the proverbial "Clean Up Routine" that handles the handful of exceptions that can cause my Required Expressions to be hung in a state of "not how I expected".

The biggest of those centering around system restarts, power outages, device battery deaths, even just going in and editing/updating a rule I've gotten my REs outta sync.

Not saying this isn't all explainable logical outcomes. Just sayin, it's not always obvious.

The uninitiated need to read a Warning Tag on the Required Expression "packaging" - "Warning - Use with the knowledge that you may need to handle/reset the condition of this by doing X,Y,Z in the event of A, B, C. which you may not expect to occur in your normal use case"

So if that was the issue i assume it would automatically fix itself the next day? or is the rule then hosed forever till you hit done?

I’ll await Bruce’s analysis. I’m curious about what circumstances can lead to the rule showing Required expressions false while at the same time showing required expressions being True ANDed with True.

As for missing the sunrise, that’s just my theory. I would hope that a clean reboot would reinitialize rule states to the same extent as hitting Done in each one would. And that the hub doesn’t need to be alive at sunrise for sunrise based automations to work later in the day.

Yes at sunrise the next day it will be set again.

I have repro'ed this with logging on the rule enabled and nothing is logged when the required expression thinks it isn't met. Consider the following test rule.

I gracefully shut down the hub at 9:05 AM and restarted it at 9:15 AM. At several times from 9:20 - 9:25 AM the trigger motion became active but the action didn't fire. The name banner at the top of the rule says that Required Expression false, even though in the Define dialog it is currently evaluating as true.

So there's something we need to understand about when required expressions are evaluated. I would have assumed that all required expressions would be evaluated upon system start, but that seems not to be the case. To get the rule working again before 9:10 AM tomorrow, it was necessary to go into the rule and hit Done.

Side note: Obviously this could be avoided by moving the required expression into actions as a conditional, so that the conditional was be evaluated each time motion occurred. I'm just wanting to learn more about what one must be aware of when using Required Expression.

1 Like

A required expression like this schedules two events. Restarting the hub has nothing to do with these scheduled events, neither removing them or changing them.

It would be most helpful if you could show two things: The Scheduled Jobs from the bottom of the rule's App Status page (gear icon), and the logs for this app between 9:00 and 9:30. Be sure the Event and Trigger logging are on in the app.

1 Like

Here is the Scheduled Jobs and it shows as expected that a job will run at the start and end of the time window. As I indicated, there is nothing in the logs (even with all logging turned on in the rule) regarding this rule at the time it failed to trigger during that time window.

Again, I'm just trying to understand the limitations of the required expression. It appears to be the case that if the hub is down when the required expression becomes true, the rule won't trigger until the required expression becomes true while the hub is up.

That leads to the scenario where the rule thinks required expression is false, yet if evaluated at that time, it is true.

Of course! A rule can't run when the hub is down. So if during that period of time the Required Expression was to have changed state, it won't. And no, before you ask, there is no way the hub is going to look for things like this at startup to find 'missed' events that you wished had run.

Consider a similar case: The hub is down, a door opens. The hub comes back up. Is a rule with a contact opens trigger supposed to run then? The answer is, of course not! Events happen when they happen. The hub is event driven, not state driven. It is never examining its state to see what it might have missed.

A Condition involves the examination of state. States change due to events occurring. Every time a rule encounters a Condition it evaluates it by examining the state of its elements. A Required Expression is evaluated only when the state of one of its elements changes. When the Required Expression becomes false, the Event Subscriptions for the triggers are removed -- the rule won't trigger from any of these events. When the Required Expression becomes true, those Event Subscriptions are created, allowing the rule to be triggered again. The Required Expression is not evaluated when the rule is triggered.

This might be helpful: Introduction to Automation

1 Like

OK, I think it is obvious that triggers are event-driven, and rules won't run if their trigger happens when the hub is down.

Required Expression on the other hand is something I think many may (erroneously) consider as a matter of state. Now that you've explained that the required expression is dependent on events to turn them on and off, yeah .. understood. And I kinda realized that in comment #3 above. I was just looking for confirmation.

I don't think I'm alone in this impression because there are quite a few threads on this. In fact in one of them, you stated

... which is exactly the astonishment that prompted me to ask. Can it be that the top of the page shows Required Express false and the rule not eligible to run even if the required expression currently is true? Yes, that can happen and there's an explanation for it. So we're good with that, although I think I'll tend towards conditionals rather than required expressions for rules whose trigger doesn't fire frequently.

I accept that. But whatever happens when one opens a rule and hits Done essentially resets the evaluation of the required expression to its state without an event, does it not? For example, If "door is open" is the required expression and the door is open when you hit Done, then the rule meets the required expression, correct?

If that is correct, then if system start triggered "Done" for each rule that had a required expression, then the scenario would no longer exist. I am not asking that this be done .. I'm just trying to understand. I had previously assumed that lots of similar stuff (like subscribing to events for all triggers) does happen upon reboot.


Ya that's why i avoid the required expression and just put extra ifs in the rule (the old way). Seems more bullet proof to me albeit with more cpu cycles.

1 Like

Very little happens on reboot. With respect to apps in general, reboot is a big yawn.

In fact, the only thing you can rely on happening is a rule that has a trigger for system start:

Up to you. But there are many circumstances in which a Required Expression is the right way to do something, and there are automations that can't be done without it. For example, try to figure out how to trigger a rule when mode becomes Day after it was Away without using Required Expression.


agreed easier with reqired espression but can be done with std rule machine and a variable.

1 Like

Show the rule. Doesn't it take two rules?

yes thats not what i meant.. i just meant it could be done without required expression.

It's just discouraging to read a suggestion that an advanced feature should be avoided rather than understood and used as intended.