! HCS II Control Program ! ! XPRESSS programming language, release 2.0 ! T. Crites ! ! System consists of an HCS II, Buff-term interface board, PL-Link X-10, & ! LCD-Link ! Analog inputs include: ! ---------------------- ! A(0): Outside light level (0-light, 255-dark) ! A(1): Outside temperature via a LM34 temperature sensor (10mV/degree F). ! This signal is buffered by a signal conditioner with a gain of ! 4 and an offset of 0. ! A(2): Inside temperatur via a LM34 temperature sensor (10mV/degree F). ! This signal is buffered by a signal conditioner with a gain of ! 4 and an offset of 0. ! A(3): Not used. ! A(4): Not used. ! A(5): Not used. ! A(6): Not used. ! A(7): Not used. ! ! Digital inputs via the Buff-term interface board: ! ------------------------------------------------- ! I(0) : Toggle switch input ! I(1) : Normally open relay from the DT-100 dual-mode motion detector ! in the family room. Relay closes for 15 sec. when motion is detected. ! I(2) : Light level input from the DT-100 motion detector in family room. ! Input is high when light level is low. ! I(3) : Normally open relay from the CT100 PIR motion detector on the garage. ! Relay closes for 15 sec. when motion is detected. ! I(4) : Not used. ! I(5) : Not used. ! I(6) : Not used. ! I(7) : Not used. ! I(8) : Not used. ! I(9) : Not used. ! I(10): Not used. ! I(11): Not used. ! I(12): Not used. ! I(13): Not used. ! I(14): Not used. ! I(15): Not used. ! Digital outputs via the Buff-term interface board: ! -------------------------------------------------- ! O(0): LED - heartbeat LED on bench to indicate if the HCS is running. ! O(1): Not used. ! O(2): Buzzer in basement. Sound for 5 seconds on motion from motion ! detector on the garage, I(3). ! O(3): Not used. ! O(4): Not used. ! O(5): Not used. ! O(6): Not used. ! O(7): Night flag to indicate if the system thinks is day or night. ! 1 = day, 0 = night. config SC = SC1 config PL-Link = 1 config LCD-Link = 1 DISPLAY Modules = I,L ! ! **************************** ! define modules in the system ! **************************** ! Inputs ! ------ DEFINE OutsideLightLevelADC = ADC(0) ! read ADC outside light sensor DEFINE OutsideTempADC = ADC(1) ! outside temp sensor (LM34) DEFINE InsideTempADC = ADC(2) ! inside temp sensor (LM34) DEFINE Switch = Input(0) ! Switch on HCS DEFINE MotionFamilyRoom = Input(1) ! DT100 motion sensor in familyroom/kitchen ! dual ir/ultrasonic occupancy sensor DEFINE FamRoomLightLevel= Input(2) ! DT100 light level input (1 low light) ! only valid when motion is detected DEFINE MotionFrontYard = Input(3) ! CT100 outdoor PIR occupancy sensor ! Outputs ! ------- DEFINE HeartBeat = Output(0) ! LED on Bench DEFINE BuzzerBasement = Output(2) ! buzzer in basement !DEFINE NightFlag = Output(7) ! Day = 1, Night = 0 DEFINE LCDSw1 = Netbit(64) DEFINE LCDSw2 = Netbit(65) DEFINE LCDSw3 = Netbit(66) DEFINE LCDSw4 = Netbit(67) ! X10 Modules ! ------------- DEFINE BedroomLight = Module(L1) ! night stand lamp - lamp module DEFINE FamilyroomLight = Module(L2) ! familyroom lamp - lamp module DEFINE EntrywayLight = Module(L3) ! entryway ceiling fixture - 3-way DEFINE FrontPorchLight = Module(L4) ! front porch light - switch module DEFINE FrontYardLight = Module(L5) ! front yard light - switch module DEFINE BackPorchLight = Module(L6) ! back sliding door fixtures - switch module DEFINE AirCleaner = Module(L7) ! air cleaner in familyroom-apl. module DEFINE HeaterKidsRoom = Module(L8) ! Ceramic heater in kids bedroom DEFINE GarageLights = Module(L9) ! garage lights - switch module DEFINE Fan = Module(L10)! fan in upstairs hall DEFINE ChristmasLights = Module(L11) ! Variables ! --------- DEFINE DayToNightThreshold= 200 ! photocell input-light level between DEFINE NightToDayThreshold= 235 ! day & night. higher count is darker DEFINE Day/Night_Mode = Variable(0) ! holds day or night value DEFINE RandomVariable1 = Variable(2) DEFINE Menu = Variable(3) DEFINE Security = Variable(4) !DEFINE ADC(1) = Variable(5) !DEFINE ADC(2) = Variable(6) DEFINE InsideTemp = Variable(7) DEFINE OutsideTemp = Variable(13) DEFINE Day = 1 DEFINE Night = 0 DEFINE Yes = ON DEFINE No = OFF DEFINE OnN = ON ! Normal "on" state DEFINE OffN = OFF ! Normal "off" state DEFINE OnI = OFF ! Inverted "on" state DEFINE OffI = ON ! Inverted "off" state DEFINE Bedtime = 22:00:DY DEFINE Console = LCD(0) DEFINE OutsideTempLog = 1 DEFINE InsideTempLog = 2 DEFINE MotionFrontLog = 3 DEFINE MotionFamilyLog = 4 DEFINE OutsideLightLog = 5 ! DEFINE Seconds Timers (0 - 63) ! ------------------------------ DEFINE LCDUpdateTimer = Timer(0) DEFINE BuzzerTimer = Timer(1) DEFINE MenuTimer = Timer(2) ! DEFINE Minute Timers (64 - 128) ! ------------------------------- DEFINE FrontYardTimer = Timer(64) DEFINE AirCleanerTimer = Timer(65) DEFINE FamilyRoomTimer = Timer(66) DEFINE NightTimer = Timer(67) ! Hysterysis between day and night DEFINE RandomTimer1 = Timer(68) DEFINE ThirtyMinuteTimer= Timer(69) DEFINE HourTimer = Timer(70) DEFINE TempTimer = Timer(71) BEGIN IF Reset THEN Refresh = 0 ! Refresh X-10's every 0 minutes ResetIO ! ClearVariables; ClearTimers ! ClearLogged Menu = 0 Day/Night_Mode = Day ! = 1 FrontYardTimer = OFF FamilyRoomTimer = OFF AirCleanerTimer = OFF AirCleaner = ON NightTimer = OFF TempTimer = ON LCDUpdateTimer = ON ThirtyMinuteTimer = ON HourTimer = ON MenuTimer = OFF END ! Button 1 allways selects next menu IF LCDSw1 = ON THEN Inc(Menu) MenuTimer = ON END !Main menu IF (Menu = 0 OR MenuTimer >= 5) AND LCDUpdateTimer >= 15 THEN Variable(5) = ADC(1) Variable(6) = ADC(2) ! temp = ADC_Counts * 5 / 256 * 10mv/deg_F ! with 4 x gain = ADC * (5/256) / 40mV ) * 1000 OutsideTemp = ((Variable(5) * 195) / 40 ) InsideTemp = ((Variable(6) * 195) / 40 ) Console = "\e[2JTime: %A \n" Console = "%C, %E \n" Console = "Outside Temp = %P1\n",OutsideTemp Console = "Inside Temp = %P1",InsideTemp LCDUpdateTimer = ON Menu = 0 END IFA Menu = 0 THEN IF LCDSw4 = ON THEN END ! if lcdsw4 = on END ! Main menu IF Menu = 1 THEN Variable(5) = ADC(1) Console = "\e[2JMenu #%P0\n", Menu Console = "SW2-Air Cleaner\n" Console = "SW3-Front Lights\n" Console = "SW4-Security = %p0", Security END IFA Menu = 1 THEN IF LCDSw2 = ON THEN IF AirCleaner = OFF THEN AirCleaner = ON ELSE AirCleaner = OFF END Menu = 0 MenuTimer = ON END IF LCDSw3 = ON THEN IF FrontYardLight = OFF OR FrontPorchLight = OFF THEN FrontYardLight = ONA FrontPorchLight = ONA GarageLights = ONA ELSE FrontYardLight = OFF FrontPorchLight = OFF GarageLights = OFF END Menu = 0 MenuTimer = ON END IF LCDSw4 = ON THEN IF Security = ON THEN Security = OFF Console = "\e[4jSW4-Security = %P0", Security ELSE Security = ON Console = "\e[4jSW4-Security = %P0", Security END Menu = 0 MenuTimer = ON END END ! IFA Menu = 1 IF Menu >= 2 THEN ! Menu #1 Console = "\e[2JMenu #%P0\n", Menu Console = "SW2-All Lights On\n" Console = "SW3-All Units Off\n" MenuTimer = ON END IFA Menu >= 2 THEN ! Decode switch inputs for menu #2 IF LCDSw2 = ON THEN ! Switch 2 - All lights on AllLightsOn(L) Menu = 0 MenuTimer = ON END IF LCDSw3 = ON THEN ! Switch 3 - All units off AllUnitsOff(L) Menu = 0 MenuTimer = ON END IF LCDSw4 = ON THEN ! Switch 4 - Toggle Security Menu = 0 MenuTimer = ON END END ! IFA Menu = 2 ! Flash Heartbeat Light ! -------------------- IFA Heartbeat = OFF Then Heartbeat = ON ELSE Heartbeat = OFF END ! Set Day/Night_Mode (Day:Night) ! ------------------------------ IF (OutsideLightLevelADC > NightToDayThreshold) THEN Day/Night_Mode = Night ! = 0 END IF (OutsideLightLevelADC < DayToNightThreshold) THEN Day/Night_Mode = Day ! = 1 END ! Set Day/Night flag on IBM HOST screen IF Day/Night_Mode = Night THEN output(7)=OFF ! = 0 END IF Day/Night_Mode = Day THEN output(7)=ON ! = 1 END ! ****************************************** ! items that happen any time of day or night ! ****************************************** IF HourTimer >= 60 Then ResetIO Log(OutsideTempLog) = OutsideTempADC ! Log(1) = OutsideTempADC Log(InsideTempLog) = InsideTempADC ! Log(2) = InsideTempADC Log(OutsideLightLog) = OutsideLightLevelADC ! Log(5) = OutsideLightLevelADC HourTimer = ON END ! HourTimer ! Control Heater in Kid's Room ! ---------------------------- !IF Time > 19:30:DY OR Time < 05:30:DY THEN ! HeaterKidsRoom = ONA !END !IF Time > 05:30:DY AND Time < 19:30:DY THEN ! HeaterKidsRoom = OFF !END ! Turn Fan on if outside temp is lower than inside ! ------------------------------------------------ IFA InsideTemp > 65 THEN ! IF OutsideTempADC <= InsideTempADC THEN ! TempTimer = ON ! END ! IF OutsideTempADC > InsideTempADC THEN ! TempTimer = ON ! END ! IF (TempTimer >= 1) AND (OutsideTempADC <= InsideTempADC) THEN IF OutsideTempADC < InsideTempADC THEN FAN = ONA ! TempTimer = OFF END IF OutsideTempADC > InsideTempADC THEN FAN = OFF ! TempTimer = OFF END ELSE FAN = OFF END ! InsideTemp > 65 ! Turn On Buzzer in Basement on motion in front yard ! -------------------------------------------------- IF MotionFrontYard = Yes THEN BuzzerTimer = ON BuzzerBasement = OnN ! log motion in frontyard Log(MotionFrontLog) = 3 ! Log(3) = 3 END IF BuzzerTimer >= 3 THEN BuzzerBasement = OffN BuzzerTimer = OFF END ! Control Air Cleaner ! ------------------- IF MotionFamilyRoom = YES THEN AirCleaner = OFF !log motion in familyroom Log(MotionFamilyLog) = 4 ! Log(4) = 4 END IF MotionFamilyRoom = EDGE AND MotionFamilyRoom = OFF THEN AirCleanerTimer = ON END IF AirCleanerTimer = 180 THEN AirCleaner = ONA AirCleanerTimer = OFF END ! Turn on front lights in the morning ! ----------------------------------- IF Time = 06:30:DY THEN FrontYardLight = ONA FrontPorchLight = ONA ChristmasLights = ON END IF Day/Night_Mode = DAY THEN FrontYardLight = OFF FrontPorchLight = OFF GarageLights = OFF EntrywayLight = OFF ChristmasLights = OFF END ! global if mode = night ! ---------------------- IFA Day/Night_Mode = NIGHT THEN ! Turn on front lights if "NIGHT" and between 4:00 pm and 9:30 pm ! --------------------------------------------------------------- IF Time > 16:00:DY AND Time < 21:30:DY THEN FrontYardLight = ONA FrontPorchLight = ONA ChristmasLights = ON END ! turn off front lights weekdays at 10:00 p.m. ! ------------------------------------------- IF Time = 22:00:DY THEN FrontYardLight = OFF FrontPorchLight = OFF GarageLights = OFF ChristmasLights = OFF END ! Turn On Front Yard Lights on Motion ! ----------------------------------- IF MotionFrontYard = Yes AND FrontYardLight = OFF THEN ! without the AND statement, the lights would turn off between dusk ! and 9:30pm with motion FrontYardLight = ONA FrontPorchLight = ONA GarageLights = ONA FrontYardTimer = ON END IF FrontYardTimer >= 5 THEN FrontYardLight = OFF GarageLights = OFF END IF FrontYardTimer >= 10 THEN FrontPorchLight = OFF FrontYardTimer = OFF END END ! IFA Day/Night_Mode ! Security Section ! ---------------- IFA Security = ON THEN IF MotionFamilyRoom = Yes THEN AllLightsOn(L) FamilyRoomTimer = ON ! minute timer BuzzerBasement = ON END IF FamilyRoomTimer > 10 THEN BedroomLight = OFF FamilyroomLight = OFF BuzzerBasement = OFF END IF FamilyRoomTimer >20 THEN BackPorchLight = OFF FamilyRoomTimer = OFF AllUnitsOff(L) END IF Day/Night_Mode = Night THEN RandomTimer1 = ON ! minute timer RandomVariable1 = Random(30) END ! Turn lights on randomly between "Night" & "Night" + 30 minutes IF RandomTimer1 > RandomVariable1 THEN FamilyRoomLight = ON ! BedRoomLight = ON BackPorchLight = DIM(10) RandomTimer1 = OFF END IF Time = 20:00:DY THEN RandomTimer1 = ON RandomVariable1 = Random(30) END ! Turn BedroomLigt on randomly between 10:00 pm and 10:30 pm IF RandomTimer1 > RandomVariable1 THEN BedRoomLight = ON END IF RandomTimer1 > 60 THEN BedRoomLight = OFF END IF Time > Bedtime THEN FamilyRoomLight = OFF ! BedRoomLight = OFF BackPorchLight = OFF END END ! Security = ON