PDA

View Full Version : Logic help please.


pbelectrical
12 Jul 07, 10:37 PM
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.

Mr Mark
13 Jul 07, 12:28 AM
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

Memphix
13 Jul 07, 09:36 AM
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.

Phil.H
13 Jul 07, 09:46 AM
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. ;)

ashleigh
13 Jul 07, 10:51 AM
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.

pbelectrical
25 Jul 07, 11:01 PM
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.