Logic help please.

Discussion in 'C-Touch/HomeGate/SchedulePlus/PICED Software' started by pbelectrical, Jul 12, 2007.

  1. pbelectrical

    pbelectrical

    Joined:
    Aug 16, 2004
    Messages:
    121
    Likes Received:
    0
    Location:
    hobart
    Just finished a project and all went well until - I set up a logic module in the PAC to do the following - When any of the three outdoor PIR were triggered and the security panel was armed I wanted the loads controlled by those PIR to come on then wait for 5 seconds and turn the main bed lights on then wait a further 5 seconds and turn some kitchen lights on and laundry lights on, then after 6 minutes turn the kitchen and laundry lights off and after 10 minutes turn the bedroom lights off. The idea being that to somone outside triggering the PIR it would look like someone inside had got up out of bed to have a look around. Hardware units involved are - PAC, outdoor PIR * 3, and 16 zone homesafe panel. The problem is that it runs even when the panel is disarmed, hence it woke my customers up 6 times during the night, hence I look like a clown and they are not happy. Following is the code I created using the module wizard.


    {If any of the external PIR are tripped and the alarm panel is
    armed. Wait 5 seconds and turn on main bed lights for 10
    minutes, Wait 10 seconds and turn on kitchen bench lights
    and laundry lights for 6 minutes.}

    once (GetLightingState("alley flood") = ON) or
    (GetLightingState("back door sensor") = ON) or
    (GetLightingState("front sensor") = ON) and
    (GetLightingState("panel armed") = ON) then
    begin

    Delay("0:00:05");
    PulseCBusLevel("79nelson", "Lighting", "main bed lts", 100%, 0, "0:10:00", 0%);
    Delay("0:00:05");
    PulseCBusLevel("79nelson", "Lighting", "kitchen bench lts", 100%, 0, "0:06:00", 0%);
    PulseCBusLevel("79nelson", "Lighting", "laundry lts", 100%, 0, "0:06:00", 0%);
    end;

    Sorry about the post length but if you have managed to get through it any help would be much appreciated.

    Regards,

    Peter Brown.
     
    pbelectrical, Jul 12, 2007
    #1
  2. pbelectrical

    Mr Mark

    Joined:
    Jan 27, 2006
    Messages:
    323
    Likes Received:
    5
    Location:
    FNQ
    Peter,
    You just need to add in the brackets around the first three lines.


    {If any of the external PIR are tripped and the alarm panel is
    armed. Wait 5 seconds and turn on main bed lights for 10
    minutes, Wait 10 seconds and turn on kitchen bench lights
    and laundry lights for 6 minutes.}

    once ((GetLightingState("alley flood") = ON) or
    (GetLightingState("back door sensor") = ON) or
    (GetLightingState("front sensor") = ON)) and
    (GetLightingState("panel armed") = ON) then
    begin...

    In effect you end up with the following options:
    "Alley Flood" AND "Panel Armed" OR
    "Back Door Sensor" AND "Panel Armed" OR
    "Front Sensor" AND "Panel Armed" turning on the lights.

    Mark
     
    Mr Mark, Jul 12, 2007
    #2
  3. pbelectrical

    Memphix

    Joined:
    Aug 31, 2006
    Messages:
    248
    Likes Received:
    1
    Location:
    Australia
    I hope that worked, but has the brackets fixed the problem? I am curious as to whether they are required. I have been told they make your code neater and add a little more security in your code but possibly do not actually matter.

    I was told to use brackets to try and fix a problem also but actually discovered that the light level sensor did not start working till it changed from dark to light or light to dark, i.e. it needed a change of state before the logic worked. Similarly, you may need the alarm panel to be armed/disarmed before the logic begins to work correctly.

    I'd appreciate hearing how it went. Thanks.
     
    Memphix, Jul 13, 2007
    #3
  4. pbelectrical

    Phil.H

    Joined:
    Jul 29, 2004
    Messages:
    466
    Likes Received:
    0
    Location:
    Sydney
    If you don't have heaps of modules already (sounds like you don't) it is easy to put your code into a dedicated module and have the state of the security panel enable and disable the module.

    The down side is there is a little overhead in the compiled code to accommodate the module however the upside (much greater) is your multi "or" condition does not have to be evaluated every second of the day.

    If you wish to stick with the original arrangement try a nested "if" condition based on the panel armed condition, this way the process only goes deeper into the code during the times the security panel is armed.

    You will get away with small amounts of inefficient code however if you add to it in the same fashion you will start to drag the little bugger down.

    The logic help and examples are very very good, even a dumby like me can understand them. ;)
     
    Phil.H, Jul 13, 2007
    #4
  5. pbelectrical

    ashleigh Moderator

    Joined:
    Aug 4, 2004
    Messages:
    2,397
    Likes Received:
    26
    Location:
    Adelaide, South Australia
    When in doubt (for expressions when coding) USE BRACKETS.

    I've been writing code for 25 years AND I CAN NEVER REMEMBER THE RULES FOR OPERATOR PRECEDENCE (in other words how things get grouped if you dont use brackets).

    I'm a firm believer in MAKE IT BLEEDIN OBVIOUS.

    So I use oodles of brackets everywhere, that way you always get exactly what you want.

    Brackets = good.

    No brackets = bad.
     
    ashleigh, Jul 13, 2007
    #5
  6. pbelectrical

    pbelectrical

    Joined:
    Aug 16, 2004
    Messages:
    121
    Likes Received:
    0
    Location:
    hobart
    Fixed

    Thankyou Mr. Mark, the brackets did the trick. Phil.H., I do like your idea of enabling and disabling the module, i have a few other modules that run when the alarm panel is armed so when i get time i will investigate slimming them down and using the one enable command for them all. Once again thanks all for your help.
     
    pbelectrical, Jul 25, 2007
    #6
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.