Motion detectors in the bathroom are only useful if the person in the bathroom is mobile.  The second they jump behind a curtain or stop moving for some other reason (insert reason here) the notion of watching for movement becomes obsolete.  This doesn't mean the motion detector is useless in the bathroom; it just means we need to augment the detection equipment with another method.  Another thought worthy of mention is we want the lights in the bathroom to turn off as quickly as possible since they do spend a large amount of the time unoccupied. 

There are some basic rules with regards to the bathroom:

  1. If you are inside and the door is closed, chances are you might not be moving for a while but don't want the lights turning off while you are inside.
  2. After the door is closed and it opens, chances are you are finished and the lights are no longer required.
  3. If the door is open and there is motion detected, chances are you need some light.

So keeping in mind there are still motion detectors in the main bathrooms, the events get just a little trickier...  The main bath motion event:

BEGINIF PLC-Button H Is 9/On                -> Motion detector transmits H/09
Then Text-A T1<-T1 Text, H9                
-> Build a log message
Then Text-A Set <Space>
Then Text-A T1/A<-Stt PLC-Command H
Then Text-A Set Log                        
-> Send it to the log
If Door, Bath, Up Is Off                   
-> Check the bathroom door
Then Timer, Bath, Up Set 90                
-> If door is open, set timer to 90
ENDIF
;----------------------------------------------------------------
BEGINIF PLC-Button H Is 9/Off              
-> Here we only log the activity of
Then Text-A T1<-T1 Text, H9                
-> the motion detector transmitting
Then Text-A Set <Space>                    
-> 'no motion'
Then Text-A T1/A<-Stt PLC-Command H
Then Text-A Set Log
ENDIF

The main bath timer:

If Timer, Bath, Up Is GE 1                  -> Set an item to follow the motion
Then Motion, Bath, Up Set On                -> detection of the room.  This is
Else Motion, Bath, Up Set Off              
-> used by "Sign of Life".
If Timer, Bath, Up Is Now 1                
-> When the timer is allowed to
Then Rm, Bath, Up Set 0                     -> expire, turn off the lights
Then Event-Call Set Rm, Bath, Up
BEGINIF Timer, Bath, Up Is GT Now 45       
-> Any time the timer becomes >45 sec
BEGINIF Awake Is True                      
-> While state of house is known as awake
Then Rm, Bath, Up Set 1                     -> Proceed to turn lights on at full
ENDIF                                      
-> intensity.
BEGINIF Awake Is False                     
-> While state of house is know as sleeping
If Time Is GT Awake Time                   
-> While it is before midnight
Then Rm, Bath, Up Set 5                    
-> Set lights at 50%
If Time Is LE Awake Time                   
-> While it is after midnight
Then Rm, Bath, Up Set 3                    
-> Set lights at 30%
ENDIF
Do Event-Call Set Rm, Bath, Up             
-> Run event to turn lights to desired
ENDIF                                      
-> setting.

Finally, the simple door closing/opening event:

If Door, Bath, Up Is Now On                 -> Door closes
Then Text-A T1<-T1 Text, Door, Bath, Main   -> Log event
Then Text-A Set <Space>
Then Text-A T1/A<-T1 Text, Closed
Then Text-A Set Log
Then Timer, Bath, Up Set 3600               -> Set timer (note the really long time here)
If Door, Bath, Up Is Now Off                -> Door opens
Then Text-A T1<-T1 Text, Door, Bath, Main   -> Log event
Then Text-A Set <Space>
Then Text-A T1/A<-T1 Text, Open
Then Text-A Set Log
Then Timer, Bath, Up Set 10                 -> Set timer so light will turn off in 10 sec
Then Rm, Bath, Up Set 0                     -> Turn light off now (this allows for X10 mishaps)
Then Event-Call Set Rm, Bath, Up