Jump to content

"IF" statement question


travcore

Recommended Posts

Hi everyone,

I need some clarification on the 'if" staement when programming. From what I have experienced, the 'if' statement is more of a 'when' statement. An example of what I mean is as follows:

(BTW, I am using X10 and Insteon)

 

IF

X10 'C1/On (3)' is Received

And Time is Sunset

 

Then

Porch Lite On

 

What happens is that when I press C1/on, when sunset happens, the porch lite turns on.

What I would like to happen is: When C1/on is sent, if it is sunset or past sunset, then turn Porch Lite ON otherwise wait until sunset and turn Porch Lite ON.

The application for this is when I set my alarm system and an X10 command is sent, I would like a lighting event to happen. I would like that event to happen when sunset arrives or after sunset has already happened. If I press the alarm button, I want to make sure the lighting event happens if I get home past sunset. If it is past sunset and I leave the house, I want to make sure the lighting event happens when I leave.

Conversly, when I arrive home and I disarm the alarm an X10 command is sent (C1/OFF), I want the lighting event to end.

Another application for this logic would be for watching a movie. I would like to press a button when I start a movie that would start a lighting scene if it sunset or past. If it is not sunset yet (during the day) then I dont't want the lighting scene to run until sunset begins, if I'm still watching the movie.

 

I hope this isn't too confusing and would appreciate any suggestions on how to program what I am hoping tobe able to do.

 

Thanks,

Paul

Link to comment

Hello Paul,

 

You were very close. The "Time IS" condition is generally used for one time on off events. You can use it with an "and" statement, but both conditions must be true at exactly the same time.

 

Try the following modification:

 

IF
X10 'C1/On (3)' is Received
And X10 'C1/Off' is not Received
And 
From Sunset to
To  XX:XX:XX

Then
Set Porch Light On

Else
Set Porch Light Off

 

In the above, the C1 signal will trigger the "then" statement between the prescribed times.

 

After the time has expired (or if a C1 Off is received) the light will be turned off (else statement executed).

 

IM

 

Edit - sorry, I missed that fact that you wanted to "latch" the C1 ON command for execution during the time window. See Marks post that follows (good catch Mark).

Link to comment

IndyMike's suggestion is good, although it doesn't address your desire to "latch" the C1/On when received prior to sunset so the light will turn on at sunset. And, as written, a C1/Off event has no effect at all (for reasons better explained elsewhere).

 

I don't think you can do what you want with one program. Here are several simple programs which should do what you want.

 

First, a trivial program which just remembers whether most recent C1 command was ON (program status TRUE) or OFF (program status FALSE):

 

Program "C1 status"
If
       X10 'C1/On (3)' is Received
   And X10 'C1/Off (11)' is not Received

Then
  - No Actions - (To add one, press 'Action')

Else
  - No Actions - (To add one, press 'Action')

 

And the program to actually turn lights on and off based on time and C1 status:

 

Program "C1 porch lite"
If
       From    Sunset
       To       2:00:00AM (next day)
   And Program 'C1 status' is True

Then
       Set Porch Lite On

Else
       Set Porch Lite Off
       //see below//Run Program 'C1 status' (Else Path)

 

The Run Program action in the Else resets the C1 status if the light is turned off because time expires (ready for the next day).

 

[Edit to add]

Ooops, my suggestion has a bug, too. You can't put the "Run Program" at the end of the Else, because it will incorrectly reset the C1 status when C1/On is received prior to sunset. So remove the line from that program, and create a third program which runs at, say, 3am with that line in the Then. Sorry!

 

--Mark

Link to comment

Archived

This topic is now archived and is closed to further replies.


×
×
  • Create New...