Need help with creating Rule

Hello,
Iā€™ve been using the simple automation rule to turn on my foyer lights on at sunset -30 and off at 11pm.
In an attempt for more energy savings, I added a NYCE ceiling sensor and modified my original on/off rule to set dinner to 20%, and created another rule in motion app that turns the lights on to 100% when motion sensed and delay off for 3 min then go back to the 20% until 11pm. However, the two rules never seem to work.
What I need help with is creating a rule that will do the above and will actually work.
I am 100% new to rule machine and would actually prefer someone do it for me so I can see what it takes and learn from that. Any advice?

Probably not the best way. Definitely not the only way, but I'll give it a shot...

image

What you should think about is, that if you go out and return after 23:00, the lights will not go on. Also, if you turn them on in any aother way, outside sunset -30 and 23:00 time block, they will be turned off by this rule (if triggered by motion or times in the trigger).

I would make two simple motion rules. One turns the light to 100% between sunset -30 and sunrise. Return to 20% until 23:00. The second rule turns the lights on to 100% between 23:00 and sunrise and return to off after that.

I see your point (not really just yet but Iā€™ll take your word) about switch use deactivating the rule. I will try your recommendation.
Your rule does bring up a ton of questions though, with the end-if, else, etc. Iā€™ll do some research but if you have a minute, Iā€™d love if you could explain a little. But otherwise, thank you.

Using two simple motion rules would probably be a better solution for you. However, I will explain my rule to you, even if it's just for education and entertainment... :smiley:

image
The first IF is to only run the rule duing the desired time block. If the time of day is not in this block, RM will go to the ELSE statement in line underneath the IF. In this case it will be:
image
So if the rule runs between 23:00 and sunset -30, it will turn the lights off.

The above is what will happen if the movement sensor fires the rule during the day.

Now, if the first IF statement is true, RM wil follow the commands in the lines under the IF. The lines are indented, to make it easier to read.

image
Okay, now if the time is after sunset -30, but before 23:00, the IF will be TRUE.
"Cancel Delayed Actions" will cancel all delayed actions that are currently running. In this case it could be the image further down.

This is usefull when there's movement and the lights go on at 100% and then within 3 minutes there is movement again - the lights will then stay on 3 minutes after the last movement, until no movement have been detected for 3 minutes.

We then jump into another IF statement. For clarity, let's just look at the IF and ELSE that's aligned under each other. And we end our IF statements with and END-IF.
image
So the rule is firing in the desired time block. It could be the movement sensor triggering the rule, or it could be one of the time triggers.

So if the rule is triggered by time, the image would be FALSE and RM will jump to the ELSE in line under the IF. In this case image (It's sunset -30 o'clock. The rule fires an sets the lights to 20%)

If there is movement, the image would be TRUE.
RM will then continue on the commands under th IF statement.
image
It will dim the lights to 100% and then it will sit there for three minutes.

After three minutes with no motion, it will continue and be met with yet another IF statement:
image
After the delay, the lights will go back to 20%.

Let's say you come home at 22:58. The lights will go to 100% and you'll have a delay of 3 minutes. You will then be outside the time block of the rule - the lights should go off. This should explain the extra IF statement.

I hope that this explains it a bit. I haven't tested the rule, it could be that I've made mistakes somewhere, but this should work...

Maybe this will help you to distinguish the IF statements:
image
Blue will execute first. If TRUE, it will continue to purple and if purple is TRUE it will continue to green. Or else it will continue to ELSE :slight_smile:

And I've just seen a better place for the "Cancel Delayed Actions" command.
You could better put that above the "Dim:PorchLamp: 100" command (in the prurple IF statement)

Try Lights On Motion Plus community app. It probably will do most of if not all of what you are wanting to do. Admittedly it isn't Rule Machine, but sometimes it takes a lot of "code" to get what you want, and an app is more appropriate.