Rule Machine - restrictions for Sat & Sun

Is there is away to make this rule just effective on Saturday & Sunday (all day)

I have a Prescence Sensor that works great M - F with time restrictions. On Sat & Sun I would like it to work all day with no restrictions.

If we can not do it here and you are good with another app like Room Lighting could please give me an example using that app?

Thank you so much.

Add the “days of week” condition as a restriction to this rule, and select Mon-Fri.

Then create another rule with the same trigger and actions, but use only the “days of week” restriction with Sat and Sun selected.

2 Likes

Not sure what I did wrong.



Food for thought...

When I create a rule, my goal is to always keep that rule as tight & narrow as possible, especially with respect to when and how often it will trigger.

Triggers that can happen either in high volume or rapid/sustained back-to-back "bursts" (like motion active) can result in a rule getting re-fired over & over, so like many folks here, I'm keen to rein that sort of thing in.

In theory, a rule re-firing on itself numerous shouldn't really be a problem per se, but in reality (for a variety of reasons), it can be.

A Required Expression (RE) is the most obvious tool to help -- an RE acts as a "live or inactive" switch for the rule...

When RE is True, the rule is live & in play -- any trigger event will fire the rule. When RE = False, it's as if the rule doesn't even exist, and the trigger event won't ever fire it.

But there are some edge cases where the timing of things can potentially gum that up just enough to be meddlesome. So Hubitat's architect of Rule Machine (Bruce R) gave us a new option - a condition for the trigger (a.k.a Trigger Conditional). That condition is evaluated immediately at the trigger event.

So, for rules with a "bursty" or high-volume trigger, that's why many of us here like using a Private Boolean, hub variable, or a virtual switch as a Trigger Conditional to act as another gatekeeper for the rule. You can still use a RE if you want to, but it shouldn't be the same/similar as your Conditional Trigger.

I myself prefer using a virtual switch (VS) instead of a Private Boolean (PB), but the end result is exactly the same -- the VS or PB is set as the Trigger Conditional, and then the first and last Actions in the rule are setting/re-setting the state of that PB or VS.

Here's one of my motion rules that use a VS in that way (note that I have a RE here too - it acts as the first / wider gatekeeper for the rule):

Summary

This kind of setup ensures that the rule doesn't get put in the position of re-firing on itself / stepping on itself.

I’m not sure what exactly you did.

But from your last screenshot, I believe I can see what you didn’t do.

It appears as though you created a condition but you’re not using it in the required expression.

Rule machine is trying to tell you this, in two different places.

IMG_3078

2 Likes

Okay I think I might have it figured out. Please see screenshots.
OR
should I leave the Motion active?

Is there a better app to use to display my screen and apps?


I would strongly suggest reading the docs, as, despite many previous attempts to correct this, your rule continues to show a fundamental misunderstabding of Rule Machine basics, including what trigger events actually do. You don't have to read the whole thing; this is explained pretty early on. I'm not saying this for no reason; I think it would be extremely helpful if you are going to use Rule Machine.

In your case, your trigger is sunrise on weekends. Triggers (as you'll see in the docs) will make you actions run. Surely that is not what you want. Further, your actions have a condition that would only be true if your trigger fired (day in Saturday or Sunday). This is the exact same as a mistake that has been pointed out to you in another rule previously. This should at least make you question the way it's written, and you'd be right to do so. At a minimum, you do want motion as the trigger, as you asked; but unless you want them to turn on without motion at all, it's likely the only trigger you need, too.

You may also need to rewrite your actions, as right now only your first action is restricted by your condition. It sounds like you maybe want everything to be restricted that way? If so, you'll need an IF THEN...END IF (not a "simple conditional" IF), a conditional trigger, a required expression, or some other approach to this problem. You may have actually closer before. :slight_smile: (But it depends on what you actually want to restrict.)

You may also want to consider creating this in Basic Rule and "importing" it into Rule Machine to get a better starting point if you do want to use RM. It looks doable in Basic Rule, so I'd really suggest just keeping it there, but if you don't want to, at least that would give you a good place to start.

4 Likes

Give this a try...

image

1 Like

How do you get the "IF" requirement OR

I am using Monday & Tuesday as my "Sunday & Saturday" for testing.

days of week

Click “edit required expression”.

1000015223
That looks like it would work, but it would depend on the order of precedence for "AND" and "OR" statements.

For example, I was going to offer the following suggestion, but I felt the result would be uncertain.

Can anyone shed any light on how each of these suggestions would be interpreted?

They are evaluated left to right with equal precedence. You can add parentheses in your expression to change this (creating sub-expressions that are evaluated as one unit outside the sub-expression), which you'd need to do for either of these expressions to evaluate how you probably want them to.

3 Likes

Thanks for your reply.

When adding "Actions" I was able to build reliable expressions using AND & OR (within If-Then groups), but I cannot figure out any way of adding parentheses when creating Required Expressions.

Any suggestions?

Click that first "+" then select "(" to add, and then click the 4th "+" to select and add a ")"

1 Like

Thank you very much. ChatGPT told me to add parentheses as well. and I have been trying to accomplish that since yesterday.

After seeing how easy it was, I feel kinda stupid.:disappointed:

1 Like

So like this then?

image

Still learning. That nugget helps with some other things I work on. Thanks.

That looks good!

1 Like

Thank you all so much. I think I have it now. FYI I am learning so much from you guys! BIG THANKS!

Just to make sure I explained myself correct, on Sat & Sun the Prescence sensor will trigger the lights ALL day. Monday - Friday the Pres sensor will only fire from 11:00 am to 1:00 pm? By the way how do you put military time in a rule? Like 1:00 pm 13:00? Every time I try it will not take the 13 or higher.

That looks good! Note that this rule itself will not actually do anything (you need to add actions, which I am assuming you know and are just taking this one step at a time; it affects the ability of your trigger device to trigger this rule but does not affect its behavior anywhere else, including other rules or any apps).

This is a hub setting, not specific to Rule Machine. It will affect time inputs in all apps. Go to Settings > Hub Details and select 24-hour time as your time format.

1 Like

In logic, the AND operator (&& ) has higher precedence than the OR operator (|| ). This means that in an expression with both operators, the AND operations are evaluated first, before the OR operations.

So this is not the way rule machine works, correct?

UPDATE
I just confirmed @bertabcd1234 description of RULE 5.1 operator precedence is as he stated in the documentation and is different than every (I think) other language I have used since the mid 1960s.

Now I have to go review all of my rules to ensure I am following this illogical logic.