RM Help with parenthesized sub-rules

So I think I have the hang of using RM in general, but I donā€™t think I fully comprehend a few specifics to get some rules to work properly. (Note: I suck at coding, last time I coded was a long time ago for SANS Python course and I dumped most of it two days later lol)

I had a rule chain but it wasnā€™t working as assumed it would so now I am trying to use parentheses to group conditions into sub-rules so that groups of different day and time conditions can be evaluated one by one to turn on lamps based on a motion trigger and keep them on for 3 minutes unless motion stops.

Is it possible that following grouped rules with OR between them will work as expected?

(Days: Monday, Tuesday, Thursday, Friday, Saturday, Sunday
AND
Time: Sunrise to 0800
OR
Time: Sunset to 2200)

OR

(Day: Wednesday
AND
Time: 0600 to 0800
OR
Time: Sunset to 2100)

OR

(Day: Thursday
AND
Time: 0430 to 0800
OR
Time: Sunset to 2200)

Right now I have the first one with multiple days built and seems to work by itself.

What I donā€™t know is if I can just have only parenthesized sub-rules with OR between them so that it evaluates the first day and time conditions and then goes to evaluate the next if the previous is determined false.

Thoughts, concerns, suggestions are very appreciated.

You may have problems with this because you are using days.
I tried something very similar but the rule would evaluate at midnight, (because you are using days as a condition) and it would evaluate as true even though it was false. I reported this in and I know Bruce is aware but I think it is one of those scenarios that is difficult to fix.

Mine used Mon, Tue, Weds and Thurs as one condition and Fri, Sat and Sun as another condition.
I ended up breaking the rule into 2 rules and used the days in a restriction. It then worked fine.

1 Like

Here is what I have now.
Restriction of Monday to Thursday.

image

Restriction of Friday to Sunday.

image

Not sure if this will help you or not.

1 Like

This definitely gives me a better understanding and another option to look at! I do want to add Lux to this rule later once I update the firmware of my Aeon Multi 6 and use a Cobra App to combine motions sensors maybe.

The wife has an odd work schedule on Wednesday and Thursday that I have to accommodate for her getting up early those days.

This is what I currently have. The first sub-rule was firing no problem by itself, now to wait until tomorrow morning to see if the Wednesday one works without issue.

You are going to need more parenthesis to group your ORs that are already inside, otherwise RM is going to interpret them differently that you are intending. Try this instead:

(Days: Monday, Tuesday, Thursday, Friday, Saturday, Sunday
AND
( Time: Sunrise to 0800
OR
Time: Sunset to 2200) )

OR

(Day: Wednesday
AND
( Time: 0600 to 0800
OR
Time: Sunset to 2100) )

OR

(Day: Thursday
AND
( Time: 0430 to 0800
OR
Time: Sunset to 2200) )

If you don't add those extras, your rule will be evaluated true as follows: (edit - now that I re-read Bruce's post below, I'm not sure these are correct)

  • Every day except Wednesday from sunrise to 0800
  • Every day from sunset to 2200
  • Wednesday from 0600 to 0800
  • Every day from sunset to 2100
  • Thursday from 0430 to 0800
  • Every day from sunset to 2200
1 Like

Ok, thank you, I'll create one using that example.

It does makes sense to break up the time conditions after the AND.

1 Like

I could be wrong about the times I posted above that the rule would be true based on this post from Bruce, but regardless, you need those extra parenthesis.

As a general rule of thumb, I NEVER mix ANDs and ORs in the same subrule (inside the parenthesis). It's much easier to interpret a rule's logic if everything inside a subrule uses the same operator.

1 Like

Here is the rule I had that kept evaluating to 'TRUE' at midnight every day and would turn the light on even though it was false.
I then broke this into 2 rules with the days then moving into a restriction.
I'll be interested to hear if yours works OK.

image

1 Like

I had read that, but I think my mind needs to have an example to completely comprehend it. I found several of your and Bruce's RM related posts very helpful.

1 Like

Will do, building the rule now, but changing the times a bit for Wednesday and Thursday so I can have another rule turn on the lights when her alarm goes off... then this one hopefully will keep them on while she does her morning routine.

Ok, I think I got this right. I have 2PM in the first condition so I could test it firing.

Will see if it starts at sunset for evening part, then wait to see what happens in the morning.

That looks good :sunglasses:

1 Like

@bobbles and @destructure00 these rules seems to work perfectly!

This morning at 6AM the rule I made to fade the lights on when my wifeā€™s Alexa alarm went off worked and then after that the second motion sub-rule fires no problem or seems too.
Note: have to look at the timing between the fade on rule and the motion sub-rule though, didnā€™t catch the transition as the room was empty by then. Had to get coffee! :blush:

Iā€™m about as giddy as a kid on the first day of school right now. Coolest thing I have done in a very long time!

I asked my wife if the lights faded on properly at the right time and all I got was ā€œleave me alone, Iā€™m getting ready for workā€ :expressionless:

Will play with getting a morning wake up fade to work nicely for the third sub-rule tomorrow. If the third sub-rule works Iā€™ll select the @destructure00 post as being the resolution.

1 Like

I suppose the day problem that I mentioned will not be an issue for you as you are using a trigger. I cannot in my rule I'm afraid. I rewrote it yesterday and sure enough the lights turned on at midnight even though the rule was false.
I will just leave it as 2 rules.
Nice to know that triggers are not affected by this issue.

I donā€™t know enough about this stuff or how you wanted your rule to work, but couldnā€™t you use Lux level as your trigger?

I am glad you posted your rules either way, I like examples, and I will be playing with lux stuff soon enough.

As an update for anyone that needs to create a rule like this, the solution post was selected, you can look at the RM rule I posted as well.

Have had no issues with the rule firing as expected.

1 Like

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