RM:Need help with a Lighting scenario

I'm in the process of converting my webCoRE pistons over to RM.
In webCoRE I can do the following:-
Time is between A and B
Lux is below X
Time is between B and A
Lux is below X
Motion is active
Turn on light.
Wait 8 mins
Turn off light.

What I have done is split the 2 equations above into 2 rules.
The problem I am encountering is that when the first rule becomes false when we are out of the A and B time window, it waits 8 mins and turn off the light even if we are up and moving about.
The light then turns back on when motion is re-detected and all is fine.
What I am trying to achieve, which i can do relatively easy with a piston as above, is if motion is detected during the 8 minute window before the first rule matures then the light doesn't turn off because the second rule will be true.
I hope this all makes sense!!!!!!!!!

Why two rules? Why not just do the rule the way you wrote it in your post?

Conditions: Time between A and B, Lux below X, Time between B and A, Motion active
Rule: (Time between A and B AND Lux below X) OR (Time between B and A AND Lux below X AND Motion active)
Action for true: Turn on light
Action for false: Turn off light after 8 minutes pending cancel on truth change

What you were missing is that special delayed off that resets the timer if motion starts again.

When I tried to do that in the past I could only put in one time condition. (I think). Thats why I split it into 2 rules. Will have another look.

EDIT: I already have between A and B as a condition. When I put in another condition of between B and A, the first conditions time changes to the second one that I have just defined.

Ah, you are correct. An old artifact that should be cleaned up.

About the issue of the first rule turning it off at time B, you could address that by using a restriction instead of a condition in the first rule. Restrict the first rule to only run between A and B. Having the restriction kick in at time B will not cause the rule to become false, so it won't turn off the light then. At time B the second rule is going to be evaluated, and if motion is active, that's going to keep the light on until it becomes inactive for 8 minutes.

The problem with this is that if I'm away the light will never turn off as the second rule will never become true.
Are you going to 'fix' the issue that I have come across. If so, I can wait. Not a big issue as we have usually turned in before time between A and B has matured. Just happens occasionally and its a pain but a quick wave and we are good again.

I'm just trying to get everything off webCoRE as I find RM rules quicker to activate than my (sometimes) complex pistons.

The second rule won't become true because of a mode restriction? As in, mode is Away, so it doesn't even run?

All rules work fine.
I haven't put in all the restrictions etc. as that is not the issue.
The issue is that I have 2 rules that both work independently of each other.
So, as said earlier, if we are still up when time B is passed then the delay kicks in to turn the light off. Which it duly does. It then turns back on after a small delay as motion is detected as part of the second rule.
As you indicated earlier, if I could put in 2 'Time Is Between' conditions, this would solve the issue. I could then incorporate my 2 rules into one.

OK, so Rule 2 isn't going to become true at time B unless there is motion, so it won't turn off the light left on by Rule 1. Rules ordinarily only do their actions when there is a change in rule truth. For rule 2, it is false at time B. If there is no motion it is still false so it won't do anything, namely, turn off the light.

We could force rule 2 to be evaluated at time B, by putting that in the false part of Rule 1 -- i.e., evaluate Rule 2. That overrules the change-in-rule-truth test. So at time B, rule 2 is going to evaluate to false and run it's false action. That will turn off the light after 8 minutes. However, if there is motion, it's going to become true, and will postpone turning off the light until motion stops. This last bit assumes you've changed it from delayed off to delayed off pending truth change.

Oh, but this still won't work. As the light is still going to be turned off by rule 1. Argh!!

Ah, one more thought: So we can force Rule 2 to be run at time B. If it is true, we want to prevent Rule 1 from turning off the light. So if in Rule 1 under Restrictions we put in Disable with Private Boolean, and then in the true part of Rule 2 we set Rule 1's private Boolean to false, that will prevent rule 1 from turning off the light. Then in the false part of Rule 2, we set the private Boolean of Rule 1 to true.

You could just fix the multiple 'Time Is Between' problem and hey presto, Bob is a happy bunny. :smile:

Seriously though, it isn't a major issue, just annoying. I will find a way round it.

The last paragraph in my post just above will fix it. Fix to Rule Machine will take much longer...

Thanks for the reply.
I have already done a work round by using 2 virtual switches that turn on and off depending on the time.
I then put these into the rule. Haven't tested it yet but it should work fine.

@bravenel I need some clarification on this please.
In a post above you suggested that I could use-
A and B or D in an expression for a rule.
I have interpreted this to mean
A and B to be true
C to be true for a rule to become true,
In the rule below this is not happening.
When the Fan is on (true) and A and B are false, the rule does not become true
I may have misinterpreted you answer and thats why I'm after clarification.

If the top 2 statements are true and the bottom one false, the lights turn on.
If the top 2 are false and the bottom one true, they do not turn on.
The rule in post 11 is working as you suggest it should use AND AND AND OR AND AND (both groups of ANDs work independently of each other) which has solved my original problem. Still cannot work out why the rule in this post does not work OK.

The clarification is that the rule is evaluated without any operator precedence, from left to right. So I was wrong before in suggesting to not use parens, because if the second operand is false, it will blow out of the evaluation at that point.

So it does need parens: A AND (B OR C) or (B OR C) AND A

Thanks for the reply.
I've moved my individual statement to the top and it now works OK.
A or B and C and D works OK.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.