! This HCSII code shows how I handle several interesting conditions. ! ! One is a power fail flag that is taken from pin 6 of the 7407 on the ! PL-Link. This pin goes low when the TW523 module loses power. The ! HCS inverts this as input(1) and it is edge detected to turn refresh ! back on after power returns. Also I have a chime module that is used ! to sense both when a Stanley Lightmaker garage door opener opens, ! module(J9), but also if an X10 floodlight motion detector senses motion,. ! module(K14). Either condition sends an ON to chime(K1). There is also ! a go to bed sequence that turns on 2 lights, and turns off 3 interior ! lights after 4 minutes. A dusk detector on the same floodlight unit also ! turns on several lights even if the normal on time has not been reached. ! Handy when I forget to compensate for shorter days in winter. I wish the ! HCS had a calculate dusk and dawn routine. The whole HCSII is powered from ! a 12 Volt 24 AH gel battery and charger that I picked up as surplus. ! I haven't let it run completely down but I'm sure it would run for several ! days on battery power. I hope some of this code will help others. BTW, ! I monitor the housecode "A" only because one of my neighbors is using it ! and the HCSII sees it! GWC ! ! ! HCS II Control Program 12/17/93 - PGM.HCS ! CONFIG SC = SC1 CONFIG PL-Link = 1 CONFIG LCD-Link = 1 ! LCD(0) uses a 2 X 40 LCD Display Display Modules = A,J,K ! Show status of X10 Modules for housecodes A,J,K DEFINE Pwrfail = Input(1) DEFINE Sensor = Input(0) DEFINE Garage = Module(J1) DEFINE Bedroom = Module(J2) DEFINE LVLights = Module(J3) DEFINE Livingroom = Module(J4) DEFINE WestShop = Module(J6) DEFINE WestRearPorch = Module(J7) DEFINE FrontPorch = Module(J8) DEFINE OldDiningRoom = Module(J9) DEFINE NewDiningRoom = Module(J10) DEFINE EastRearPorch = Module(J11) DEFINE Bathroom = Module(J13) DEFINE EastRearFlood = Module(J14) DEFINE SouthRearFlood = Module(J15) DEFINE WestRearFlood = Module(J16) DEFINE Chime = Module(K1) DEFINE Dusk = Module(K5) DEFINE Motion = Module(K14) DEFINE LampDelay1 = Timer(6) DEFINE LampDelay2 = Timer(2) DEFINE RawTemp1 = Variable(1) DEFINE RawTemp2 = Variable(2) DEFINE RawTemp3 = Variable(3) DEFINE RawTemp4 = Variable(4) DEFINE RawTemp5 = Variable(5) DEFINE RawTemp6 = Variable(6) DEFINE Windspeed = Variable(7) DEFINE RawV = Variable(23) DEFINE PwrFlag = Variable(16) BEGIN IF Reset THEN ! Do power on or program load initialization here ClearVariables; ClearTimers ClearLog LCD(0) = "\b\e[2J ************ System\n Reset ************\b" ! Send reset Timer(3)=ON ! message to LCD(0) & beep sounder for 1 second. END IF Pwrfail=ON THEN ! Begin power fail routine Timer(3)=OFF ! Shut off Timer to hold next message on LCD(0) LCD(0) = "\e[2J%C %E \nTime = %A \n** AC Line Power **\n*** Has FAILED ***" END IF Pwrfail=EDGE AND Pwrfail=OFF THEN ! When power returns Timer(3)=ON ! Turn display timer back on PwrFlag=ON ! Set power returned flag to on Timer(73)=ON ! Start a minutes counter END IF Timer(73)>=30 THEN ! After 30 minutes, turn timer off PwrFlag=OFF ! Reset power returned flag to off Timer(73)=OFF END IF Module(J9)=ON OR Module(K14)=ON THEN ! If garage door opener is activated or Chime = ONA ! motion detector in back yard senses Timer(10) = ON ! motion, sound chime module. END IF Timer(10)>=15 THEN Chime=OFF Timer(10) = OFF END IF Motion=ON THEN Timer(40)=ON EastRearFlood=ON END IF Timer(40)>=5 THEN SouthRearFlood=ON END IF Timer(40)>=10 THEN WestRearFlood=ON END IF Timer(40)>=180 THEN EastRearFlood=OFF END IF Timer(40)>=190 THEN SouthRearFlood=OFF END IF Timer(40)>=200 THEN WestRearFlood=OFF Timer(40)=OFF END IF Timer(3)>=5 THEN ! Display for 5 seconds Date, Time, Inside, Outside temps RawTemp1 = ADC(5) RawTemp2 = ADC(0) Variable(11)=(RawTemp1*500)/256 Variable(12)=((RawTemp2*250)/256)*2 ! Avoids 32767 overflow problem LCD(0) = "\e[2J%C %E \nTime = %A \nInside Temp = %P0\xDF\nOutside Temp = %P0\xDF",Variable(11),Variable(12) END IF Timer(3)>=10 THEN ! Display for 5 seconds Date, Time, Shop, Garage temps RawTemp3 = ADC(1) RawTemp4 = ADC(4) Variable(13)=(RawTemp3*500)/256 Variable(14)=(RawTemp4*500)/256 LCD(0) = "\e[2J%C %E \nTime = %A \nShop Temp = %P0\xDF\nGarage Temp = %P0\xDF",Variable(13),Variable(14) END IF Timer(3)>=15 THEN ! Display for 5 seconds Date, Time, Solar, and Tank temps RawTemp5 = ADC(2) RawTemp6 = ADC(3) Variable(15)=((RawTemp5*250)/256)*2 Variable(16)=((RawTemp6*250)/256)*2 LCD(0) = "\e[2J%C %E \nTime = %A \nPanel Temp = %P0\xDF\nTank Temp = %P0\xDF",Variable(15),Variable(16) END IF Timer(3)>=20 THEN ! Display for 5 seconds Date, Time, Wind Speed, Direction RawV = ADC(6) ! This function requires another circuit not finished yet Variable(22)=(RawV*500)/256 ! Code is for display sample only LCD(0) = "\e[2J%C %E \nTime = %A \nWind Speed = %P0 MPH\nDirection = NNW ",Variable(22) Timer(3)=ON ! Reset Timer by turning it on again END IF Module(J12)=ON OR NETBIT(64)=ON THEN ! Get ready for bed. Turn Bedroom and Bathroom lights on LCD(0) = "\e[2J%C %E \nTime = %A \n Good\n Night!" Timer(4)=ON ! by pushing 12 on any X10 controller or Bathroom=ON ! pushing button one, netbit(64) on LCD Bedroom=ON END IF Timer(4)>=240 THEN ! After 4 minutes, turn Bedroom, Bathroom, & LivingRoom Module(J12)=OFF ! lights off. Reset Module(12) status. Bathroom=OFF Bedroom=OFF Livingroom=OFF Timer(4)=OFF END IF NETBIT(65)=ON OR NETBIT(66)=ON OR NETBIT(67)=ON THEN LCD(0) = "\e[2J%C %E\nTime = %A \n This Key Is Not\n Programmed Yet." END IF Time>23:00:DY OR Time<06:00:DY OR PwrFlag=ON THEN ! Refresh modules between Refresh=30 ! 11 PM and 6 AM daily END ! Or if power has failed IF Time>06:00:WK AND Time<08:00:WK AND PwrFlag=OFF THEN ! Don't refresh modules Refresh=0 ! between 6 AM and 8 AM on weekdays END IF Time>08:00:WK AND Time<16:00:WK OR PwrFlag=ON THEN ! Refresh modules between Refresh=30 ! 8 AM and 4 PM on weekdays END ! Or if power has failed IF Time>16:00:WK AND Time<23:00:WK AND PwrFlag=OFF THEN ! Don't refresh modules Refresh=0 ! between 4 PM and 11 PM on weekdays END IF Time>06:00:EN AND Time<23:00:EN THEN ! Don't refresh modules betwwen 6 AM Refresh=0 ! and 11 PM on weekends END IF Time=17:30:DY THEN ! Setup variable to turn garage light on between Timer(64) = ON ! 5:30 PM and 5:50 PM Variable(10) = Random(20) END IF Timer(64)>Variable(10) OR Dusk=ON THEN Garage = ON Timer(64) = OFF END IF Time=00:00:DY THEN ! Turn garage light off at midnight Garage = OFF END IF Time=17:30:DY THEN Timer(65) = ON Variable(11) = Random(20) END IF Timer(65)>Variable(11) OR Dusk=ON THEN LVLights = ON Timer(65) = OFF END IF Time=02:00:DY THEN LVLights = OFF END IF Time=16:50:DY THEN Timer(66) = ON Variable(12) = Random(30) END IF Timer(66)>Variable(12) OR Dusk=ON THEN Livingroom = ON Timer(66) = OFF END IF Time=23:05:DY THEN Livingroom = OFF END IF Time=17:15:DY THEN WestShop = ON END IF Time=23:00:DY THEN WestShop = OFF END IF Time=16:50:DY THEN Timer(67) = ON Variable(13) = Random(30) END IF Timer(67)>Variable(13) THEN WestRearPorch = ON Timer(67) = OFF END IF Time=04:30:DY THEN WestRearPorch = OFF END IF Time=16:35:DY THEN Timer(68) = ON Variable(14) = Random(30) END IF Timer(68)>Variable(14) THEN EastRearPorch = ON Timer(68) = OFF END IF Time=00:38:DY THEN EastRearPorch = OFF END IF Sensor=EDGE AND Sensor=ON THEN ! Motion detector in bathroom BathRoom=ON LampDelay1=ON END IF LampDelay1>=240 THEN ! You get 4 minutes to do your thing BathRoom=OFF LampDelay1=OFF END IF Time>=08:00:DY THEN ! Periodic refreshes during the day AllUnitsOff(J) ! "just in case" END IF Time>=12:00:DY THEN AllUnitsOff(J) END IF Time>=16:00:DY THEN AllUnitsOff(J) END