-
Notifications
You must be signed in to change notification settings - Fork 130
MotionDetection
A fun and popular MisterHouse project is to add motion detection to your house. This project is fairly simple to set up and works well. In order to begin, you'll need to have previously done the following:
- MisterHouse set up and configured.
- Insteon PLM, CM11 or TW523 serial X-10 unit installed and running (this unit pulls the signals off of the electric lines and sends them to the computer's COM port [serial])
- A Transceiver (i.e. part number RR501 or TM751) installed and running (this unit pulls the radio signals sent by the motion detector out of the air and sends them to the transceiver unit over the electrical lines). An alternate solution to the transceiver solutions listed above would be to have PC Receiver installed and running (part MR26A, about $30 or W800).
- As another alternative see also the BX24-AHT for a more advanced transceiver that can also receive other wireless devices.
Select an unused set of two adjacent unit codes within a house code for the detector, for example, F3 and F4. The first will be used by the motion detector to send signals announcing that motion has been detected, the second will be used to send signals announcing that it has detected a change from light to dark, or vice versa. Note that if you are using the ActiveHome/Transceiver method to receive the signals, you must have a transceiver listening on the house code that you choose (i.e. 'F' in this example). The PC Receiver listens to all house codes, but its range is limited without modifications to the MR26A's antenna.
Set the house and unit codes for the detector. Slide open the detector and add two AAA batteries. Set the house code with the left button and the unit code with the right. As you hold down the button, it will flash rapidly, then stop and blink a certain number of times to indicate its current setting, once for house code A, twice for B, etc. Once it has stopped, press the button the appropriate number of times for the house code you wish it to have. In our example we want the house code to be 'F' so we would press the button 6 times. The tricky part here is to note that on the last button press, you need to hold it down. As you hold it, the unit will then blink the number of times it thinks you pressed the button. Count the blinks and if it is correct, stop pressing the button and you're done. Follow the same instructions to set the unit code. Slide the cover back on and place the motion detector where you wish it to be located.
Now you'll need to tell MisterHouse that there is a new item that it needs to know about. One method is to add the following items to your 'MHT' file. This file should be named 'items.mht' and will be located in your code directory. Edit the file and add lines similar to the following:
code X10A, F3, Kitchen_Motion, Hidden X10A, F4, Kitchen_Darkness, Hidden code
Now that MisterHouse knows about this device, we need to write some instructions for what should be done when motion is detected from the device. I have a file that I have named 'x10items.pl' which I have created and placed in my code directory. This is where I put all of my personal code for motion detectors, switches, etc. Create a file similar to the above and place the following code in it:
code format="perl" my $Kitchen_Motion_timer = new Timer;
my $Kitchen_Motion_state;
if ($state = state_now $Kitchen_Motion) {
set $Kitchen_Motion_timer 120;
if ($Kitchen_Motion_state ne $state) { if ($state eq 'on') { speak "Someone's in the Kitchen."; } else { speak "The Kitchen is quiet.";
set $Kitchen_Motion_timer 0; }
$Kitchen_Motion_state = $state; }
}
- Sometimes the 'no more motion' signal is missed. This timer will
- ensure that we get the signal two minutes after the last motion
- has been detected and logs the fact that it had to do this.
set $Kitchen_Motion 'off'; print_log "Kitchen Motion Timer Expired.";
}
my $Kitchen_Darkness_state;
if ($state = state_now $Kitchen_Darkness) {
if ($Kitchen_Darkness_state ne $state) { if ($state eq 'on') { speak "The Kitchen is dark."; } else { speak "The Kitchen is lit."; }
$Kitchen_Darkness_state = $state; }
}
code After you save the above code in your file, you'll need to either start MisterHouse, restart MisterHouse, or have MisterHouse reload its code. Once that has been done, go try out your new motion detector.
You can modify the above code which responds to motion or light being detected to have MisterHouse do almost anything. Here are some examples:
- Turn on lights when it gets dark. - Turn on lights when someone is in a room. code format="perl" $timer_airlock_movement = new Timer(); code
- Turn on the airlock light if motion is detected at night.
- this will reset the timer every time motion is detected, no
- fancier logic is required.
print_log "airlock motion detected";
if (time_greater_than "$Time_Sunset - 0:15" and time_less_than "$Time_Sunrise") { set $airlock_light ON; set $timer_airlock_movement 300; print_log "airlock light turned on due to motion"; }
} code
- off when the timer expires, and it's night. We check for "sunrise + 15" in
- case we turned the light on *just* before sunrise.
if (time_greater_than "10:00 PM" or time_less_than "$Time_Sunrise - 0:15") { set $airlock_light OFF; print_log "airlock idle; turning light off"; }
} code - Send an email or AIM message when motion is detected in your house on a weekday during hours you're at work. - Turn off your MP3 player when someone is at the front door. - detect dead lightbulbs. code format="perl" $timer_pantry_movement = new Timer(); code
- Saw motion
- light is on same housecode as detector, to reduce latency
set $pantry_light ON; set $timer_pantry_movement 120; print_log "motion in the pantry";
} elsif (expired $timer_pantry_movement) {
print_log "turning off pantry light"; set $pantry_light OFF;
}
- sometimes the X10 command doesn't get through; we try again here.
if (state $pantry_darkness eq ON) { print_log "resend pantry light ON"; set $pantry_light ON; }
} code
- The light still has not come on; assume the bulb is dead.
if (state $pantry_darkness eq ON) { print_log "pantry light is probably burned out."; }
} code