Rule Condition Question

The following rule is to turn off a fan after 2 hours but only between certain hours as shown in the restrictions.

If the fan is already on before the time window, will it still turn off after 2 hours or does it need to go off then back on for the rule to take affect?

With a Rule it only does actions after a truth change, so in this case after the fan is off and then on again.

You could use a Trigger instead of a Rule. Easier to understand: When the fan turns on, it turns off 2 hours later. With your restriction, it will not turn off during those hours. If you turn it on after 7:45 PM and before 5:00 AM , it will never turn off. Turning it on at 7:46 PM means it would turn off at 9:46 PM, but the rule is restricted then so it won't turn off.

Not sure I understand. I know that if I turn the fan on after 9:45 pm it will automatically turn off 2 hours later. Which is what I want. So I know the rule as written works.

I can have the fan running during the day and it never shuts off automatically which is correct. The rule doesn't function unless it is between 9:45 pm and 5 am.

What I am unsure about, and I guess I can just try it, at 9:45 does the rule then look at the conditions to see if they are true at that time and if they are go ahead with the 2 hour delay.

I thought that the restriction says only look at the rule during that time period. Which it seems to do.

What has to be within those times? The time the fan turns on or the time the fan turns off? or both?

I agree with @bravenel, a triggered rule would be better. The trigger being the fan turns on, the condition being the time you want, the action for true being Turn off the fan with a delay of 2 hours.

During the day if we turn the fan on it should stay on till we turn it off. At night if we turn jt on when we go to bed it should only run for 2 hours then shut off.

The rule as written does exactly that. My question was if the fan was already on at 9:45 and we didn't shut it off and re start it, would it still shut off in 2 hours. I guess the question is, which is looked at first. The condition or the restriction?

Simplest thing for me to do is just test it.

If the fan was already on at 9:45, the rule truth will not have chaned so it will stay on forever. But this is going to be true of whatever time you have as the end of you window to remain on forever. You've told the system to only turn the fan off after 2 hours when it is turned on during the night. Not when it is already on when the time is the end of the day window.

That's why you would want to put the time as a condition, rather than a restriction. Having that would cause the fan to go off at 11:45. Because the rule truth would change from false to true. So, take out the restriction and you'll get that behavior.

However, with the two conditions, if the fan was turned on at 4:01 am, it would stay on until 9:45 that night.

Ok, I verified what you said. I turned the fan on at 9:30 last night. It didn't go off. So you answered my question.

That also explains how the rules programming was set up. The restrictions apply to the actions and not to the conditions or the rule as a whole. So it was a matter of me understanding how the programmer set it up.

I have been a programmer for almost 50 years now. And one of the things I have always said was if you give 10 people the same program to write you will get 10 different programs and 9 of them will work.

Thanks again for the help.

3 Likes

This isn't quite true (coming from the author). All of the entry points into the app from events (all but a couple of special cases) are protected by a check of the restrictions. If the restriction test fails (i.e., it is restricted), it exits. That is the first line of code in each entry point. It doesn't evaluate the conditions or the rule, nor run any actions in this case -- it does nothing at all. The exceptions are entry points that might undo a restriction, such as Private Boolean being set or the rule being Resumed after Pause, these actions having come from some other rule.

Hi @bravenel, I have a follow-up question for you...
When a restriction is removed, the rule truth is not re-evaluated, correct? And when a restriction is in place, the rule truth is also not evaluated, correct? When the restriction ends, in the case of a time restriction, if the rule was true before the restriction, it will be true after the restriction is lifted, regardless of what the real state of the rule should be at the time the restriction ends and regardless of any activities that took place during the restriction.

The reason I ask is because i believe this has caused some trouble for me in the past. After a restriction has ended, a rule, which should have evaluated as True was true but the problem was, the rule hadn't changed from False to True, so that action never took place. And i believe that is the only thing i could have contributed it to. I have since modified many of my restrictions into conditions and it seems to be working much more consistently.

If that being the case when my restrictions expired at 9:45 and the fan was already on it should have then scheduled a shutdown at 11:45. It did not until I stopped the fan and turned it back on. So it didn't evaluate the conditions after the restrictions ended.

The actions only execute when the rule's truth changes from False to True or True to False. Otherwise no actions will be execute.

Restrictions coming and going do nothing to the rule, beyond preventing or not preventing it from running. The restriction suspends everything. The lifting of a restriction is not an event.

Yes, but it's a good question that, I think, has not yet been answered. If a rule is true before it's suspended, what occurs when it comes out of suspension, and the rule-truth is now false, yet the rule is still functionally true? Given that it takes events to change rule truth, will the rule stay true, even though the rule truth is false, until there is a change in some trigger/condition?

Nothing happens its a bit like pause the rule is essential non existent to the system while the restrictions are in place so no event gets through to the rule, so no evaluation happens.

Correct the rule truth is what ever state it was before the restriction but as with rules just because it's come out of a restriction doesn't mean it will now run its previous rule truth actions; this is because they only run on change of truth. Once one of the conditions events change this will then force a re evaluation so if it was true and now evaluated to false the rule truth has changed so would then run the false actions.

1 Like

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