ADICON Support Forum Applied Digital, Inc.
Page 1 of 1 1
Topic Options
#21552 - 01/03/10 12:53 PM OR / AND issue?
Tozz Offline
newbie


Registered: 09/17/07
Posts: 21
I'm having a problem with a piece of code. It is part of a larger piece of code which I use to control a light in my hallway.

The code is:
 Code:
IF Variable #4 = 0
  OR Variable #4 = 2
  AND Variable #3 = 2
  AND Timer #2 > 10
    THEN Timer#2 = 179
    THEN Variable #3 = 0
    THEN Variable #4 = 0


Variable #3 is set to value '1' or '2' by HomeSeer. Value 1 means 'Door goes open', Value 2 means 'Door is closed'. Variable #4 is set by the Ocelot itself so I know which door was last opened.

The idea of this code is 'If hallway door is closed AND 'last door opened' = Hallway door AND 'time between opening/closing' > 10 secs THEN stop timer, reset vars, turn off light.

The 'stop timer' is done by setting timer #2 to 179. This will trigger an 'IF Timer#2 > 180' which stops the timer and turns the light off.

The problem seems to be with the check 'AND Timer #2 > 10'. My Ocelot seems to ignore this check. According to the 'debug timers and variables' the timer hasnt reached 10 yet, but it still sets the timer to 179 and reset the other variables.

Am I doing something wrong with the preference of the 'AND' 'OR' statements?

Top
#21555 - 01/03/10 02:10 PM Re: OR / AND issue? [Re: Tozz]
Guy Lavoie Administrator Offline
Beyond All Hope
*****

Registered: 12/21/02
Posts: 6548
Loc: Montreal, QC, Canada
It's hard to make a definitive analysis without seeing all the code relating to Timer #2 and to what actual events sets the variables (and the actual code...is your statement "AND Timer #2 > 10" in fact "is >" or "becomes >", etc).
_________________________
"If you don't know what you're doing, do it neatly..."

Top
#21558 - 01/03/10 02:36 PM Re: OR / AND issue? [Re: Guy Lavoie]
Tozz Offline
newbie


Registered: 09/17/07
Posts: 21
Alright. Here is the entire C-Max program I've loaded in the controller. Basicly what I want to do is:

When i'm entering the hallway using the livingroom-hallway door I want the light to go on. Then if I go through the front door the light should go off. Same thing for the other way around.

Also, When I go upstairs and open livingroom-hallway door I want the light to stay on for 3 minutes. There is a check to see if the door is closed within 10s after its opened. This to prevent that the light goes off when I close the door right after I went thru it.

When its beeing closed and atleast 10s has passed (Timer 2) I'll assume I'm back from upstairs and the light can go off.

 Code:
 0001 -                                                    //  
 0002 -                                                    // ### CHECK IF ITS DARK OUTSIDE ###
 0003 -                                                    //  
 0004 - IF Time of Day is > Sunrise offset 30 minutes      // If the sun has risen
 0005 -   AND Time of Day is < Sunset offset -30 minutes   // But hasnt set yet
 0006 -     THEN Variable #5 = 1                           // Var 5 = It is light outside
 0007 -     ELSE Variable #5 = 0                           // Var 5 = It is dark outside
 0008 -                                                    //  
 0009 -                                                    // #### Toilet light ###
 0010 -                                                    //  
 0011 - IF Variable #1 becomes =  1                        // If Toilet Door opens
 0012 -   AND Timer #1 is = 0                              // And timer wasn't started yet
 0013 -     THEN X-10 House C / Unit 14, Turn ON           // Turn on toilet light
 0014 -     THEN Timer #1 = 1                              // Start Timer
 0015 -     THEN Variable #1 = 0                           // Reset Variable
 0016 -                                                    //  
 0017 - IF Variable #1 becomes =  1                        // If toilet door opens
 0018 -   AND Timer #1 is > 10                             // And timer was running for 10 secs
 0019 -     THEN X-10 House C / Unit 14, Turn OFF          // Turn off toilet light
 0020 -     THEN Timer #1 = 0                              // Stop Timer
 0021 -     THEN Variable #1 = 0                           // Reset Variable
 0022 -                                                    //  
 0023 - IF Variable #1 becomes =  2                        // If toilet door closes
 0024 -   AND Timer #1 is > 10                             // And timer was running for 10 secs
 0025 -     THEN X-10 House C / Unit 14, Turn OFF          // Turn off toilet light
 0026 -     THEN Timer #1 = 0                              // Stop Timer
 0027 -     THEN Variable #1 = 0                           // Reset Variable
 0028 -                                                    //  
 0029 - IF Timer #1 is > 1200                              // If light is on for 20 mins
 0030 -     THEN Timer #1 = 0                              // Stop Timer
 0031 -     THEN X-10 House C / Unit 14, Turn OFF          // Toilet light off
 0032 -                                                    //  
 0033 -                                                    // ### COMING HOME ###
 0034 -                                                    //  
 0035 - IF Variable #2 becomes =  1                        // If front door opens
 0036 -   AND Variable #5 is = 0                           // And its dark outside
 0037 -   AND Variable #4 is = 0                           // And its the first door that is used, we're coming home
 0038 -     THEN X-10 House C / Unit 11, Turn ON           // Turn on hallway light
 0039 -     THEN Timer #2 = 1                              // Start Timer
 0040 -     THEN Variable #2 = 0                           // Reset Variable
 0041 -     THEN Variable #4 = 1                           // Value 1 = Frontdoor
 0042 -                                                    //  
 0043 - IF Variable #3 becomes =  2                        // If livingroom door closes
 0044 -   AND Variable #4 is = 1                           // And previous op. was front door opening
 0045 -     THEN Timer #2 = 179                            // Skip timer to 179
 0046 -     THEN Variable #3 = 0                           // Reset Variable
 0047 -     THEN Variable #4 = 0                           // Value 0 = Teset
 0048 -                                                    //  
 0049 -                                                    // ### LEAVING HOME ###
 0050 -                                                    //  
 0051 - IF Variable #2 becomes =  2                        // If front door closes
 0052 -   AND Variable #4 is = 2                           // And previous door was livingroom door
 0053 -     THEN Timer #2 = 179                            // Skip timer to 179
 0054 -     THEN Variable #2 = 0                           // Reset Variable
 0055 -     THEN Variable #4 = 0                           // Value = Reset
 0056 -                                                    //  
 0057 -                                                    // ### GOING TO TOILET OR UPSTAIRS ###
 0058 -                                                    //  
 0059 - IF Variable #3 becomes =  1                        // If livingroom door opens
 0060 -   AND Variable #5 is = 0                           // And its dark
 0061 -   AND Variable #4 is = 0                           // And its the first door we use
 0062 -     THEN X-10 House C / Unit 11, Turn ON           // Turn on hallway light
 0063 -     THEN Timer #2 = 1                              // Start Timer
 0064 -     THEN Variable #3 = 0                           // Reset Variable
 0065 -     THEN Variable #4 = 2                           // Value 2 = Livingroomdoor
 0066 -                                                    //  
 0067 -                                                    // ### BACK FROM TOILET OR UPSTARS ###
 0068 -                                                    //  
 0069 - IF Variable #4 is = 0                              // If this is the first door used
 0070 -   OR Variable #4 is = 2                            // Or the last one was livingroom door
 0071 -   AND Variable #3 is = 2                           // And livingroom door is beeing closed
 0072 -   AND Timer #2 is > 10                             // And light has been on for 10s
 0073 -     THEN Timer #2 = 179                            // Skip timer to 179
 0074 -     THEN Variable #3 = 0                           // Reset Variable
 0075 -     THEN Variable #4 = 0                           // Value = Reset
 0076 -                                                    //  
 0077 -                                                    //  
 0078 -                                                    //  
 0079 -                                                    //  
 0080 -                                                    //  
 0081 -                                                    //  
 0082 -                                                    //  
 0083 - IF Timer #2 becomes > 180                          // After 3 minutes
 0084 -     THEN Timer #2 = 0                              // Stop Timer
 0085 -     THEN X-10 House C / Unit 11, Turn OFF          // Turn off light
 0086 -     THEN Variable #2 = 0                           // Reset frontdoor varable
 0087 -     THEN Variable #3 = 0                           // Reset livingroomdoor variable
 0088 -     THEN Variable #4 = 0                           // Reset temporary variable
 0089 -                                                    //  
 0090 - IF X-10 House P / Unit 1,  OFF Command Pair        // If alarm has been turned off
 0091 -   AND Variable #5 is = 0                           // And its dark
 0092 -     THEN X-10 House C / Unit 10, Turn ON           // Turn on livingroom light
 0093 -                                                    //  
 0094 - IF X-10 House P / Unit 1,  OFF Command Pair        // If alarm has been turned off
 0095 -     THEN Module #3   -SECU16 Relay #8 Turn OFF     // Restore HVAC to normal
 0096 -                                                    //  
 0097 - IF X-10 House P / Unit 1,  ON Command Pair         // If alarm has been turned on
 0098 -     THEN Transmit X10,  C - All Units OFF  (17)    // Turn off all lights on C-housecode
 0099 -     THEN Transmit X10,  B - All Units OFF  (17)    // Turn of all lights on B-housecode
 0100 -     THEN Module #3   -SECU16 Relay #8 Turn ON      // Put HVAC in 'away' mode
 0101 - End Program                                        //  

Top
#21559 - 01/03/10 05:24 PM Re: OR / AND issue? [Re: Tozz]
Guy Lavoie Administrator Offline
Beyond All Hope
*****

Registered: 12/21/02
Posts: 6548
Loc: Montreal, QC, Canada
Ah, I see 3 seperate code sections that could set Timer #2 to 179; code sections starting at lines 43, 51 and 69. The first two of those code sections are not checking for any minimum value for Timer #2 before setting it to 179, so I suspect that it is one of those sections that is doing this. Try monitoring the variables that those sections evalute to see if one of those sections is testing true and then setting Timer #2 to 179. If so, you might need to add also a check for minimum timer value to those sections too, or implement other logic.
_________________________
"If you don't know what you're doing, do it neatly..."

Top
#21565 - 01/04/10 12:26 PM Re: OR / AND issue? [Re: Guy Lavoie]
Tozz Offline
newbie


Registered: 09/17/07
Posts: 21
The code section starting at 43 is correct. If I came into the house using the frontdoor (Var #4 = 1) and I exit through the livingroom door the light should go off, regardless of any timer.

The same goes for code at 51 but there its backwards (going through the hallway door and leaving through the frontdoor).

Timer #2 is implement for the sole function to prevent the light from turning off when I close the door right after I went through it.

I'll go through the code again, there must be something wrong \:\)

Monitoring the variables is a bit hard. The variables are only updated once every so many seconds. Sometimes the light goes off before C-Max has updated its variable status.

Top
#21566 - 01/04/10 01:13 PM Re: OR / AND issue? [Re: Tozz]
Tozz Offline
newbie


Registered: 09/17/07
Posts: 21
Found it. The problem is the check starting from line 69. The complete test will only test true once the timer has passed 10 secs and then it will turn the light off. When Timer 2 hasnt reached 10s yet it will just continue with the rest of the code until timer 2 has passed 10 secs.

I've added an extra check that if Timer 2 HAS NOT reached 10s yet it resets variable 3 (the closing door) to zero so the door-close-action is completely ignored.

Thnx for your time!

Top
Page 1 of 1 1


Moderator:  Dan Smith, Monte G, ADI Tech Support, Guy Lavoie 
Hop to:
Who's Online
0 registered and 51 anonymous users online.
Recent Posts
Shout Box

Newest Members
brigiel, vevevie, zhutree, 416, saiqul
3003 Registered Users
Forum Stats
3003 Members
19 Forums
4004 Topics
23442 Posts

Max Online: 132 @ 11/13/16 10:07 AM
December
Su M Tu W Th F Sa
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31