Help with Rule If-Then

Hi
I’m trying to make a rule that: at all days except Friday 20 before sunset till Saturday 40 min after sunset a motion sensor will activate a device when detecting movement and deactivate when no motion (2 min)
how should a rule like that be made (if-then etc.)

@lior_zilber, you will need two rules for this. See below for the detailed instructions:

  1. Create a True/False variable (isMotionPaused in my screenshot example)
  2. Create a rule to set this variable to true or false based on the time
  3. Create another rule to be triggered by the motion changed to active or stays inactive for 2 minutes, and check the variable isMotionPuased status and the triggering value (motion active or inactive) to decide what action to take.

thank you:
didn’t understand 1: how do i do it?
2. in the condition “today is Friday…” - what does it mean
thank you

Do you mean how to create a variable? You can tap Manage Variables as shown in the Rule List page as shown in the screenshot below.


Then create a True/False variable called isMotionPaused or whatever you want.

Or please let me know which part you need help with if this is not what you were asking for.

So the first rule is configure to be triggered either 20 minutes before sunset on Friday or 40 minutes after sunset on Saturday, and the reason of the IF condition checking if it is Friday today is because I want to set the variable isMotionPaused to true only on Friday (triggered by 20 minutes before sunset on Friday). Then this variable being set to true will prevent the 2nd rule from doing anything when the motion is triggered or stays inactive for 2 minutes. And when the 1st rule is triggered again on Sat 40 minutes after sunset, it will set the variable back to false because it is NOT Friday per the check in the IF condition.

ok thanks now I follow
another question (last? :slight_smile: )
what does the marked mean

It’s using Context Variables which makes the rule faster as it is able to use the event that triggered the rule rather than having to query SmartThings and check the status of the motion sensor.

So the equivalent of this would be:

IF Living Room - motion is active

But in that case, the rule would have to reach out to SmartThings to get the status of the motion sensor, so it adds a slight delay. (maybe 0.5-2 seconds).

Since are are dealing with motion and we want the rule to process as fast as possible, James is using a trick where you can use the event that triggered the rule in the IF Comparison. This means the rule can instantly proceed with the comparison since it uses the existing value of the the motion event that triggered the rule (rather than having to wait a moment while it asks SmartThings for the latest state).

https://imgur.com/ZYIEng5

1 Like

Neat! Learned something new!

It seems I did everything as explained, but some how it does not work, can u give a look please
thx

@lior_zilber , can you post the screenshots of your so we can better understand how the rule is configured now? And it will help us understand the issue greatly if you can describe with details which part of the rule is not working or what behavior(s) was observed, but not expected.

1 Like

nothig works. it doesn’t open the light’s at all…



Can you share more details about what you tried? Otherwise we are just guessing as to what was tested, what you expected to happen, and what actually happened.

Was the $ismotion variable set to false when you tested the rule? Since Friday/Saturday hasn’t passed since you created the rule, the $ismotion (eg. isMotionPaused from James’s example) must be false otherwise the rule will immediately end.

I have a motion sensor that turns on a light, and turn it off after 2 min of no motion -I wanted this rule to happen only from Sunday-Friday but not Saturday
for now it does not turn the light on at all.
and yes $ismotion was set to false

@lior_zilber, can you please take a screenshot of your $ismotion variable so we can verify its value? I’ve checked your rule and the system log and it appears this variable is causing the rule to skip the action based on the IF condition configured in the 2nd rule in your screenshot.

You can find the variable by tapping ... at top-right corner in the Rule list page, and select Manage Variables.

Click on ismotion in the list and take a screenshot of the variable modal like shown below.

thank you so much!
somehow I missed it
now it works
just hope it will open the light indeed on Saturday…

1 Like

Me again, I’m trying to use the same rule above for another thing, the difference is that i Would like it to work only nights & not Saturdays
A. what should I add
B. The same rule can apply to several devices ? (somehow it seems to work only with one device)
thank you!

Depends on your goals for your rules. The approach James provided above has a separate rule that sets the ‘schedule’ and then uses a variable to as a ‘flag’ that can be used in other rule to determine if they should proceed (eg. as an IF Condition).

That approach works especially well when you want the same ‘flag’ or set of conditions to apply across multiple rules as you only have to control the one ‘flag’. I believe it was also necessary to meet your original specification which included a sunset/sunrise offset – the IF Condition does not allow sunset/sunrise offsets, but the Triggers do allow it.

So if you have multiple rules that you want to easily flag enabled/disabled, then using the same approach with a variable could work well here. Basically, create one rule that defines the ‘schedule’ using triggers and sets the variable accordingly in the Flow.

Simplified Approach

Otherwise you can just use normal rule and set the If Condition accordingly. (eg. Time is your desired ‘night’ hours and the day is anything except Saturday):

1 Like

Thank you!
it will take me time to figure it all out
i’m trying to learn and understand so I can make by myself some rules…

2 Likes