Use of ( ) in logic

Discussion in 'C-Touch/HomeGate/SchedulePlus/PICED Software' started by Memphix, Mar 8, 2007.

  1. Memphix

    Memphix

    Joined:
    Aug 31, 2006
    Messages:
    248
    Likes Received:
    1
    Location:
    Australia
    I have an unknown problem with a network which may be due to my logic.

    Code:
    once (GetLightingState("Night") = ON) and
         (GetLightingState("Home") = ON) and
         (GetLightingState("HallPIR") = ON) then
    begin
       SetLightingLevel("Hall", 100%, "0s");
    end;
    Should I have extra brackets around the once statement... like this:

    once ((GetLightingState("Night") = ON) and
    (GetLightingState("Home") = ON) and
    (GetLightingState("HallPIR") = ON)) then
     
    Memphix, Mar 8, 2007
    #1
  2. Memphix

    Richo

    Joined:
    Jul 26, 2004
    Messages:
    1,257
    Likes Received:
    0
    Location:
    Adelaide
    The extra brackets should not be necessary.
     
    Richo, Mar 8, 2007
    #2
  3. Memphix

    ashleigh Moderator

    Joined:
    Aug 4, 2004
    Messages:
    2,397
    Likes Received:
    26
    Location:
    Adelaide, South Australia
    But adding more brackets for CLARITY is never a bad thing!
     
    ashleigh, Mar 9, 2007
    #3
  4. Memphix

    Josh

    Joined:
    Aug 25, 2004
    Messages:
    241
    Likes Received:
    0
    Location:
    Pretoria, South Africa
    Code:
    once ((GetLightingState("Night") = ON) and
         (GetLightingState("Home") = ON) and
         (GetLightingState("HallPIR") = ON)) then
    
    I usually do that as well as white spacing, it helps in terms of reading the code
     
    Josh, Mar 9, 2007
    #4
  5. Memphix

    JasonCox

    Joined:
    Aug 17, 2004
    Messages:
    75
    Likes Received:
    0
    I think I know what you are trying to do here...try the following code


    Code:
    if (Time > SunSet) and (Time < SunRise)
      and GetLightingState("Home") then
      begin
        once GetLightingState("HallPIR") then
        SetLightingState("Hall", OFF);
      end;
    I had this same annoying problem with some alarm integration code (looked a lot like yours). The welcome home scene would trigger at night at an odd time (Turns out it was the sunset time). At first glance there wasn't anything wrong, but it was that ONCE command....use it wisely as I found out :)
     
    JasonCox, Mar 13, 2007
    #5
  6. Memphix

    Darren Senior Member

    Joined:
    Jul 29, 2004
    Messages:
    2,361
    Likes Received:
    0
    Location:
    Adelaide, South Australia
    The number one rule with the once statement it to never put it inside an if statement. Refer to the logic help file topic "When to use if and once" for details.
     
    Darren, Mar 14, 2007
    #6
  7. Memphix

    Darren Senior Member

    Joined:
    Jul 29, 2004
    Messages:
    2,361
    Likes Received:
    0
    Location:
    Adelaide, South Australia
    Has this problem been resolved ?

    If you still need help, you will need to provide more details. It is impossible to resolve an "unknown problem".
     
    Darren, Mar 14, 2007
    #7
  8. Memphix

    JasonCox

    Joined:
    Aug 17, 2004
    Messages:
    75
    Likes Received:
    0
    My BAD...

    I was going off of my very tired memory...here is the real code
    :eek:
    Code:
    Once GetLightingState("Home") and (((Time > SunSet) or (Time < SunRise))
    and GetLightingState("HallPIR")) then
    SetLightingState("Hall", OFF);
    
     
    JasonCox, Mar 14, 2007
    #8
  9. Memphix

    Memphix

    Joined:
    Aug 31, 2006
    Messages:
    248
    Likes Received:
    1
    Location:
    Australia
    Thanks for your concern Darren.

    I thought that not enclosing the whole once statement in brackets could of solved the issue. I don't believe that is a problem.

    My problem was with the light level sensor and the sunset. The light level sensor does not broadcast on the network that its dark (turn the group address on) if you update it when its already dark. And similarly, the touch screen only broadcasts to the network that its sunset or after at the actual time the sunsets. I was on site and making changes after sunset when it was dark... and therefore the logic did not know that it was dark or after sunset :eek: Important lesson there.

    Baldness does not run in my family... but I think it may of started ;)

    Although that was my issue that raised this post, I still have a few mystery actions. An unexplained light turning on randomly durring the night.

    I am having the same sort of problem with my PIRs also. They have an overide which is dimmable. When the overide is switched off the PIR is already on and therefore does not switch the light on till it then times out and then turns on again.
     
    Memphix, Mar 15, 2007
    #9
  10. Memphix

    Darren Senior Member

    Joined:
    Jul 29, 2004
    Messages:
    2,361
    Likes Received:
    0
    Location:
    Adelaide, South Australia
    The best way to track down this sort of problem is to use the Diagnostic Utility to find where the commands are coming from.
     
    Darren, Mar 18, 2007
    #10
  11. Memphix

    [IL]NewGen

    Joined:
    Aug 3, 2004
    Messages:
    121
    Likes Received:
    0
    Location:
    Melb, Australia
    Yes, for tracking purposes the Diagnostic Utility is like the best thing since sliced bread. Many probs that occur will get the finger pinned on them from this tool, good game guys.:cool:
     
    [IL]NewGen, Mar 19, 2007
    #11
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.