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.
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)
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.
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.
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.
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.
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!
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ā
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.
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.