Introduction: Mouse As Door Alarm

A friend of mine who own a shoes store, since he had some missing articles,   asked me a way to monitor the door of the stock.
He just want a cheap system, connected to a pc, which will be able to send emails alarm when the stock door will be open during the days-off.

I decided to hack a old usb mouse and use the existing reed switch as click emulator.

A piece of python on a linux box will detect the mouse click as a open/close door alarm, and send a email.

Step 1: Prerequisites


You will need :

 - a old wired usb mouse
 - a linux box using Xorg/X11 (tested on Linux Mint and Ubuntu)
 - a reed switch (not on the photo) or a other mecanical switch
 - an iron solder
 - terminal blocks
 - some cables

Step 2: Hack the Mouse

Open your mouse carrefully, take care about all screws.

Next, identify the mouse buttons. Depending on the mouse, you can have 2 to 5 or 6 buttons.

Next, bypass the button switch. You can  desolder the switch or solder directly the cable on the mouse board.
Here, i've decided to solder directly, to be able to reuse the mouse later.
Also, i've only used one switch, but the python script can handle 3 switches.

Once completed, the mouse up and get out the cable to the outside.

Solder the cable to the terminal blocks. These blocks will be used to connect the alarm switch (reed switch or mecanic switch).

Step 3: Setup Python Script

The python script will do :

 - disable the mouse from X11, to prevent bad inputs
 - listen mouse events from raw inputs
 - detect mouse click (simulate by the alarm switch)
 - check if the click occurs during the days-off
 - if yes, it sent a email


Before to run the script, you need to edit it, and customize it. All configuration variables are on the beginning.

device_name : the mouse name from X11
xinput_id : the id of mouse from X11

$ xinput list | grep "slave  pointer"
    Virtual core XTEST pointer               id=4 [slave  pointer  (2)]
    SynPS/2 Synaptics TouchPad               id=10 [slave  pointer  (2)]
    PS/2 Generic Mouse                       id=11 [slave  pointer  (2)]
Kensington Kensington PocketMouse Pro    id=13 [slave  pointer  (2)]




When done, just run the script with sudo, to have read access on mouse raw input.

$ sudo python MyMouseAlarm.py

Step 4: Connect Your Alarm Sensor

Just connect your alarm sensor to the blocks.

Your sensor should be passive, act as a mecanic switch, it's could be a reed switch, a microswitch, a mercury switch.


Thanks for reading.