Conditional Logic Question

broconne

Active Member
I have a blocks of code that does not seem to be functioning as I expect. I think it may be because I do not understand how "or"ing works in HAI.

Code:
76. WHEN Front Door Timer OFF
WHEN Expect Guest Timer OFF
  AND IF Expect Guest Timer OFF
  AND IF Front Door Timer OFF
  AND IF TIME IS GREATER THAN Front Lights Off Time
  OR
  AND IF TIME IS LESS THAN SUNSET
   THEN Outside Front OFF
77. WHEN Front Door Timer OFF
WHEN Expect Guest Timer OFF
  AND IF TIME IS LESS THAN Front Lights Off Time
  AND IF Expect Guest Timer OFF
  AND IF Front Door Timer OFF
   THEN SET LIGHTING LEVEL Front Porch Light TO 55%

I have two timers. I have a front door timer (that is started when the front door is opened or if someone presses the "guest leaving" scene and I have an expect guest timer started from a scene of the same name. Both timers turn on all the front lights. The front door timer is a 10 minute window, the expect guest timer is a 2 hour window.

I am trying to have block 76 perform the following logic:
Whenever the expect guest timer or front door timer changes to off, if both of those timers are off and its after the front lights off time then turn off the lights.

Line 77, performs essentially the same logic but says if it is before that time, then dim the front porch light to 55%.


What I am noticing is that when I press the guest leave button, the front door timer goes on for 10 minutes but when it transitions to off the lights are turning off.
 
Code:
76. WHEN Front Door Timer OFF
WHEN Expect Guest Timer OFF
  AND IF Expect Guest Timer OFF
  AND IF Front Door Timer OFF
  AND IF TIME IS GREATER THAN Front Lights Off Time
  OR
  AND IF TIME IS LESS THAN SUNSET
   THEN Outside Front OFF

Line 76 says, that when either of these events occur:
Code:
WHEN Front Door Timer OFF
OR
Code:
WHEN Expect Guest Timer OFF

And EITHER one of these sets of criteria is met:
Code:
  AND IF Expect Guest Timer OFF
  AND IF Front Door Timer OFF
  AND IF TIME IS GREATER THAN Front Lights Off Time
OR
Code:
  AND IF TIME IS LESS THAN SUNSET

Then perform this action
Code:
   THEN Outside Front OFF

So if time is less than sunset and either one of the timers goes off the lights will go off.
When the time is greater than lights off time, and both timers go off, the lights will go off.

What is your lights off time? You may be having a problem with time greater than / less than.

If sunset is 6PM.
The lights will go off when either one of the timers goes OFF between 12:01AM and 5:59PM.

Think of it rewritten in four blocks:

Code:
76. WHEN Front Door Timer OFF
  AND IF Expect Guest Timer OFF
  AND IF Front Door Timer OFF
  AND IF TIME IS GREATER THAN Front Lights Off Time
   THEN Outside Front OFF
Code:
76. WHEN Expect Guest Timer OFF
  AND IF Expect Guest Timer OFF
  AND IF Front Door Timer OFF
  AND IF TIME IS GREATER THAN Front Lights Off Time
   THEN Outside Front OFF
Code:
76. WHEN Front Door Timer OFF
  AND IF TIME IS LESS THAN SUNSET
   THEN Outside Front OFF
Code:
76. WHEN Expect Guest Timer OFF
  AND IF TIME IS LESS THAN SUNSET
   THEN Outside Front OFF

If your front lights off time is after midnight, then the "less than sunset" line will always turn the lights off because 12:30AM, or 1:00AM or what have you is before sunset.

The only period the first group of conditions will apply is between sunset and midnight.

Line 77 requires both timers to be off as well.


If you don't want the lights to go off prior to sunset unless both timers are off, then you have to add the conditionals to that block as well, like this:

Code:
76. WHEN Front Door Timer OFF
WHEN Expect Guest Timer OFF
  AND IF Expect Guest Timer OFF
  AND IF Front Door Timer OFF
  AND IF TIME IS GREATER THAN Front Lights Off Time
  OR
  AND IF Expect Guest Timer OFF
  AND IF Front Door Timer OFF
  AND IF TIME IS LESS THAN SUNSET
   THEN Outside Front OFF
 
Your last item fixed it.. Adding the conditionals to both sides of the OR block was the piece that I didn't understand.


Thanks as always!
 
Trying to do something similar - and am very new to HAI programming...

I am trying to have my landscape lighting turn ON at sunset and OFF at 11p. I have the following code written:

Code:
1. TIMED SUNSET MTWTFSS
  AND IF TIME IS LESS THAN 11:01 PM
   THEN Landscape lighting ON
 
You don't need the conditional.
The timed trigger will only fire once a day.
Sunset should always be before 11PM unless you live in northern Alaska :)

Just use something simple like this.


Code:
1.  TIMED SUNSET MTWTFSS
	   THEN Landscape lighting ON
2.  TIMED 11:00PM  MTWTFSS
	   THEN Landscape lighting OFF
 
Follow-up question:
In the initial example:
 
76. WHEN Front Door Timer OFF
WHEN Expect Guest Timer OFF
AND IF Expect Guest Timer OFF
...
 
Are the first two lines, "When Front..."   and  "When Expect Guest..." executed as AND conditions or OR conditions.  In other words can either of these two events (regardless of the other's condition) cause entrance into the rest of the steps?  Or, must bioth simutaneously be true to procede?
 
Thanks
 
 
 
 
 
 
awardblvr said:
awardblvr, on 08 Nov 2013 - 10:44, said:
Follow-up question:
In the initial example:


76. WHEN Front Door Timer OFF
WHEN Expect Guest Timer OFF
AND IF Expect Guest Timer OFF
...

Are the first two lines, "When Front..." and "When Expect Guest..." executed as AND conditions or OR conditions. In other words can either of these two events (regardless of the other's condition) cause entrance into the rest of the steps? Or, must bioth simutaneously be true to procede?

Thanks
Stacked WHENs are executed as ORs.

WHEN Condition 1
(OR)
WHEN Condition 2
(OR)
WHEN Condition 3...etc.
THEN Do Task 1

The Stacked WHENs allow you to execute the same code block with multiple triggers, it's a short hand to save programming lines.

They execute exactly the same as typing:

WHEN Condition 1
THEN Do Task 1

WHEN Condition 2
THEN Do Task 1

WHEN Condition 3
THEN Do Task 1


Stacked AND IF conditionals must all be satisfied to execute the code below them.
Stacked OR conditionals are separated into groups of conditions with each group acting as a group of AND IFs.

i.e.

AND IF Condition 1
AND IF Condition 2
OR
AND IF Condition 3
AND IF Condition 4

Will execute if BOTH Condition 1 AND 2 are true OR BOTH Condition 3 AND 4 are true.

You may duplicate conditions in the stacks

i.e.

AND IF Condition 1
AND IF Condition 2
OR
AND IF Condition 1
AND IF Condition 3

Will execute if BOTH Condition 1 AND 2 are true OR BOTH Condition 1 AND 3 are true.



In this example:

76. WHEN Front Door Timer OFF
WHEN Expect Guest Timer OFF
AND IF Expect Guest Timer OFF

It is the same thing as:

76. WHEN Front Door Timer OFF
AND IF Expect Guest Timer OFF
THEN (Do something)

77. WHEN Expect Guest Timer OFF
AND IF Expect Guest Timer OFF
THEN (Do something)


So it will excute if EITHER "Front Door Timer turns OFF" OR "Expect Guest Timer turns OFF" as long as "Expect Guest Timer is OFF".
 
Back
Top