Jump to content

"AND" Logic in programs


C Martin

Recommended Posts

Posted

I use this program to control my closet lights:

If
       Control 'Closet Lights / Closet Motion-Sensor' is switched On
   And (
            $sSleepTime is 0
        And $sClosetOveride is 0
       )

Then
       Set Scene 'Closet Lights / Closet light Switch' On
       Wait  60 seconds
       Set Scene 'Closet Lights / Closet light Switch' Off

Else
  - No Actions - (To add one, press 'Action')

This program is used to over ride the Clost Motion program and will run for the time in the "Wait" Line.
The "Closet Motion Program" is also stopped and the "Closet Overide On - Day" program is also reset to a False status.

 

Please note: I just added the Parenthesis to the code.

So, my question is:

Without any Parenthesis, how does ISY evaluate the program?

I made the mistake of believing that all of the "AND" statements would be evaluated before any results would be yielded.

I was receiving inconsistent results. Sometimes the program would evaluate correctly and other times it would not. Kind of a Lazy, Rookie error and a poor assumption on my part.

Am I wrong?

I realize the Parenthesis adds "Logical Value" to the program but is it necessary for the program to work correctly?

What is the Logical flow to evaluating Logical Statements?

 

Please give me some guidance on this matter.

 

Clarence

Posted

At the end of your Wait 60 secs the 'If' is re-evaluated. If the Motion Sensor turns OFF during the 60 secs then the program will be aborted and it won't turn the closet light off.

 

To do this properly put your Then statements into a different program and Run (Then) of the new program in this program.

Posted

I've never had that happen.

The re-evaluation of the off state does not re-trigger the program to start again, and if it does, the motion sensor is not triggered "On" again.

The program actually works well.

The only problem I had was when there was no Parenthesis. The evaluation did not take into consideration all of the "AND" Statements.

Posted

I've never had that happen.

The re-evaluation of the "OFF" state does not re-trigger the program to start again, and if it does, the motion sensor is not triggered "On" again.

The program actually works well.

The only problem I had was when there was no Parenthesis. The evaluation did not take into consideration all of the "AND" Statements.

Posted

I have a slightly different take on it. Since the program is not looking for a “switched Off†from the motion, once it does switch off it will not affect the program – running or not. If at anytime during the “wait†the motion is switched on again or the state of either variable changes (I am assuming the programs are “stateâ€) then the program will re-evaluate immediately. If the condition evaluates true it will start the “then†over again. If it evaluates false the program will stop running and the program will turn false immediately, not completing the “then†section (in other words “Set Scene 'Closet Lights / Closet light Switch' Off†will not occur).

 

Is it possible that during the wait either one of the variable states may be changing which would halt the program?

 

Tim

 

Edit: As far as needing the brackets, I don’t use them unless I am using and/or combo’s and they are absolutely needed. I don’t believe you need them in this program. It has been my experience that having the 3 conditions listed as you have them without the brackets will evaluate anytime any one or more change state, but the “then†should not run unless all 3 “if†conditions are true. In answer to your other question, without brackets the order would be from the top down as far as I understand it.

Posted
I use this program to control my closet lights: ...

 

Hi Clarence,

 

There was a bug in using And(), Or() in a previous beta release, so make sure you are using the most recent beta firmware.

 

As for your specific problem, I'll have to test this out because

 

If      xxxxx
   And yyyyy
   And zzzzz
Then

 

Should behave exactly the same as:

 

If      xxxxx
   And (
             yyyyy
         And zzzzz
       )
Then

Posted

Hi Chris,

 

I thought so too. But from what I saw it is not consistent. It works sometimes and other times, it doesn't.

It had me very perplexed for a while, until I re-looked at my code and added the Parentheses.

It acts like it evaluates the first two and then nothing more. But again, it's not consistent.

 

Clarence

Guest
This topic is now closed to further replies.

×
×
  • Create New...