Mary's job with the lights is very simple.  If it is dark outside and there is motion detected in an area, turn on the lights.  If there is no longer any motion detected regardless of day or night, turn the lights in that area off.  While this sounds very simple, the experience with the two previous programs led us to believe the wireless motion detectors just could not be relied upon to get a signal back to Mary to signal her that motion had stopped.

Another problem with the previous setup allowing the motion detector to start an event to turn lights on and off was there was way too much X10 traffic so it caused many delays.  When the CM11A was still installed, it would lock up much more frequently.  The reason for this is every time there was motion detected, the motion detector transmits.  Then Mary would respond by turning on all the lights associated with that motion detector (all of this via X10).  If there were more than the two people home, such as a family gathering, lights would do pretty much what ever they felt like.  More off than on and certainly not what would fit under the description of home automation.

The solution after all was said and done was to implement timers to make sure the lights were turned off.  After several different implementations, the following is what solved the majority of the problems.  These rules cannot be pasted into ECS but instead are written with generic names.  If these are to be plagiarized, be sure and change the items to items in your system.

The rules for the motion detectors work like this:

BEGINIF Motion is detected         ->This motion detector needs it's own name
If Daylight Is True                ->Daylight should be set with a light sensor
Then Timer Set 300                 ->This timer needs it's own name
Else If Daylight Is False
Then Timer Set 600
ENDIF 

Now that won't do much but make a timer count down to zero so the work gets done in another event that performs actions based upon the condition of that timer:

If Timer Is GE 1
Then Motion Set On
Else Motion Set Off                ->This item shows motion detection (motion)
If Timer Is Now 1
Then Room Set 0                    ->This item is set so we can call a group event
Then Event-Call Set Room           ->This event controls a room's lights
If Timer Is GT Now 300
Then Room Set 1                    ->This item is set so we can call a group event
Then Event-Call Set Room           ->This event controls a room's lights

Starting to get the idea?  In the daytime, we don't want to change the state of the light until the timer reaches 1 which will only turn off the lights off.  At night, we want to keep the number of X10 commands sent to the lights (may be a couple of lights in a room right?) to a minimum.  If there is constant activity, the timer will stay above 300 seconds all the time so there won't be any more commands sent out after the first one.

Each of these timers should be defined per the activity of the room.  The living room for instance can be a fairly low activity level room so the timer is set much higher.  The bedrooms on the other hand have a completely different approach.  We never want the lights to turn on in the middle of the night so the event that watches the timer is set higher than the motion detector event will ever set it.  This means the bedroom lights will be turned off when there hasn't been any motion but they will never be turned on in connection with motion.

There is one more thing I haven't talked about that belongs to the most recent iteration of event processing.  A good program should have either macros or sub-routines and variables so code repetition is kept to a minimum.  ECS lends itself well to that programming theory so an example of how that was accomplished is imbedded in the previous group of commands.  The hierchy of events in our case worked something like this:

Everything Inside/Outside Upstairs/Downstairs Areas Rooms Individual Lights
All Lights

Group, Inside

Grp, Upstairs

Area, Lt, Living

Rm, Living

Lt, Living, Floor

Lt, Living, SW

Lt, Living, NE

Rm, Stairs

Lt, Stairs

Rm, Kitchen

Lt, Kitchen, Ovhd

Lt, Kitchen, Sink

Lt, Kitchen, Hood

Rm, Dining

Lt, Dining

Area, Lt, Bd

Rm, Bath, Master

Lt, Bath, Master

Lt, Sink, Master

Rm, Bd, Master

Lt, Bd, Master

Rm, Closet, Master

Lt, Closet, Master

Rm, Fan, Bd

Fan, Bd, Master

Rm, Bd, Other

Lt, Bd, Casey

Lt, Bd, Bailey

Lt, Bd, Spare

Rm, Hall, Up

Lt, Hall, Up

Rm, Bath, Up

Lt, Bath, Up, Tub

Lt, Bath, Up, Sink

Grp, Downstairs

Area, Lt, Theater

Rm, Theater

Lt, Theater

Lt, Rec Room

Rm, Hall, Down

Lt, Hall, Down

Rm, Bath, Down

Lt, Bath, Down

Rm, Laundry

Lt, Laundry

Area, Lt, Office

Rm, Office

Lt, Ofc, Lamp, Rick

Lt, Ofc, Lamp, Pam

Lt, Ofc, Ovhd, Rick

Lt, Ofc, Ovhd, Ctr

Lt, Ofc, Ovhd, Pam

Lt, Ofc, Fl, Rick

Lt, Ofc, Fl, Pam

Printer, Laser

Area, Lt, Garage

Rm, Garage

Lt, Garage, Ovhd

Lt, Garage, West

Lt, Garage, East

Rm, Gar, Stereo

Sw, Garage, Stereo

Grp, Xmas, In

Area, Xmas, In

Rm, Xmas, In

Lt, Xmas, Inside

Group, Outside

Grp, Lt, Front

Area, Lt, Front

Rm, Front

Lt, Front

Grp, Lt, Rear

Area, Lt, Rear

Rm, Rear

Lt, Deck, Up

Lt, Deck, Down

Lt, Rear Garage

Grp, Xmas, Out

Area, Xmas, Out

Rm, Xmas, Out

Lt, Xmas, West

Lt, Xmas, Center

Lt, Xmas, East

There is a similar hierchy for setting timers so we can set all the timers in an area of the house to the same value with one event.  Then that event will get tied to a button press of some kind; either on a PC console or a remote control.  As seen in the example above, we keep the name of the event and the name of the item containing the new state the same for troubleshooting purposes.

For the pages below this one, we will talk about the challenges each one has faced if they are unique and the solution to those challenges.  The above Hierchy chart will serve as a guide throughout the pages below.