O'Reilly Hacks
oreilly.comO'Reilly NetworkSafari BookshelfConferences Sign In/My Account | View Cart   
Book List Learning Lab PDFs O'Reilly Gear Newsletters Press Room Jobs  


 
Buy the book!
Smart Home Hacks
By Gordon Meyer
October 2004
More Info

HACK
#84
Check for Dead Motion Detector Batteries
Instead of scurrying about the house checking the batteries in your various motion detectors, have a script do the checking for you.
The Code
[Discuss (0) | Link to this hack]

The Code

This is a global script that is executed every other day by a repeating scheduled event :

    if (status of "Nobody Home") is false then -- don't do this if house is
    empty
        set mList to "" as list
        set mList to all of group "all motion detectors"
        set h to 72 -- how many hours of inactivity triggers decision

        repeat with x from 1 to count of items of mList
            set u to item x of mList

            if (time delta of u) is greater than h * hours then
                write log "Check batteries in motion detector: " & u
            end if
        end repeat
    end if

The first thing the script does is to check if anyone is at home . If the house is empty, and we've been away for a few days, the motion detectors will not have had a reason to fire lately and this might cause the script to falsely conclude there is a battery problem. (However, the detector's dusk detectors still should be sending a signal, so that's not an entirely sound assumption.)

If a motion detector hasn't been heard from in more than 72 hours, a message is written to the log with its name. Other possibilities would be to send an email, or to set the description of the unit so that it will stand out for you later.

    if (time delta of u) is greater than h * hours then
        set description of unit u to "Check my batteries!"
    end if

If you want to have different silent periods for some motion detectors, assign the detectors to different groups . For example, create a Daily Motion Detectors group and a Weekly Motion Detectors group. The latter might include motion detectors you're using to alert you to activity in seldom-used guest rooms or your liquor cabinet .

set mList to all of group "daily motion detectors"
    repeat with x from 1 to count of items of mList
        set u to item x of mList
        if (time delta of u) is greater than 72 * hours then
            write log "Check batteries in motion detector: " & u
            speak "Check batteries in motion detector"
        end if
    end repeat
    set mList to all of group "weekly motion detectors"
    repeat with x from 1 to count of items of mList
        set u to item x of mList
        if (time delta of u) is greater than 168 * hours then
            write log "Check batteries in motion detector: " & u
            speak "Check batteries in motion detector"
        end if
    end repeat


O'Reilly Home | Privacy Policy

© 2007 O'Reilly Media, Inc.
Website: | Customer Service: | Book issues:

All trademarks and registered trademarks appearing on oreilly.com are the property of their respective owners.