Monitor washing machines with Nagios / Icinga: check_gpio_pir

Winter time is crafting time! I spent the last couple of days on the Raspberry Pi and PIR sensors (Passive Infrared). Using this sensors it is possible to recognize motions - in combination with GPIO APIs you can create useful applications.

The first idea that came in my mind was to monitor my washing machine in the basement. Because I'm a very busy person I often forget the machine and so I thought about scanning the blinking LEDs on the front and automatically sending mails in case of status changes. Because I'm using Nagios respectively Icinga for monitoring my network anyway it was a good idea to develop an adequate plugin. ๐Ÿ™‚

Setup and functionality

My setup currently consists of the following parts:

  • Raspberry Pi B+ with installed CRUX-ARM linux
  • TP-Link AV500 powerline adapter starter kit (TL-PA 4010P) because Wireless LAN is unavailable in my basement
  • 5V PIR sensor (ordered on eBay)
  • Standard LED for displaying recognized motions
  • Breadboard and flexible plug-in jumpers

Schaltung

I secured the network connection between my flat and the basement with Port Security to lock out unwanted network participants.

The wiring looks like this:

  • GPIO #2 => VCC PIR (5 volt)
  • GPIO #7 => OUT PIR (GPIO4)
  • GPIO #6 => GND PIR + LED (shared)
  • GPIO #11 => VCC LED (GPIO17)

The PIR sensor is fixed to the machine's front using a provisional mount to scan the timer. Unfortunately my washing machine has no LED that displays a completed cleaning process. So I have to check whether the timer is still blinking - if not the clothes are waiting for being pegged out. This also means that I currently have to enable the monitoring explicitely because the timer is not blinking if the washing machine is turned off. I need to find a more creative solution for this. ๐Ÿ™‚

Sensor calibration

PIR-Sensor

The most PIR sensors offered on eBay have two potentiometer that control the sensor's behavior.

The first potentiometer controls the sensitivity while the second one controls the time frame the sensor is triggered in case of recognized motions.

By default both potentiometers should be set to 50% (middle). It is recommended to tune the sensitivity to match your own setup. My plugin offers a debugging function (parameter -d / --debug) which displays recognized motions in the console. Alternatively these motions can also be visualized using a connected LED (parameter -l / --enable-led) if you don't have a connected console.

Requirements and plugin

Python 2.x must be available on the Raspberry Pi. Beyond that my plugin requires the python module RPi.GPIO which can be downloaded for free. My plugin can be downloaded on GitHub:

1# wget https://pypi.python.org/packages/source/R/RPi.GPIO/RPi.GPIO-0.5.8.tar.gz
2# tar xfz RPi.GPIO-0.5.8.tar.gz
3# cd RPi.GPIO-0.5.8
4# python setup.py install
5# cd
6# wget https://github.com/stdevel/check_gpio_pir/archive/master.zip
7# unzip master.zip
8# cd check_gpio_pir-master

The plugin's behavior can be controlled by various configuration parameters - some of them:

Parameter Explanation
-t / --seconds Time period the sensor is checked
-c / --motion-threshold Threshold of recognized motions forcing a warning
-v / --invert-match Inverting match, missing motions will create warnings

Example: Monitoring with pre-defined values (3 motions forcing a warning, 15 seconds check):

1# ./check_gpio_pir.py
2OK: motion counter (0) beyond threshold (3)

The full documentation including various examples can be read on GitHub.

Nagios / Icinga configuration

To integrate the plugin in Nagios respectively Icinga you need to copy it into the appropriatge plugin directory. Afterwards you need to create a command:

1icinga# vi commands.cfg
2...
3define command{
4        command_name check_local_pir
5        command_line $USER2$/check_gpio_pir.py
6}
7
8ESC ZZ

If you plan to monitor remote hosts you need to define a NRPE command on the Icinga system and the remote host:

 1icinga# vi commands.cfg
 2...
 3define command{
 4        command_name check_nrpe_pir
 5        command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -t 60 -c check_gpio_pir
 6}
 7
 8ESC ZZ
 9
10remote# vi nrpe.cfg
11...
12command[check_gpio_pir]=/usr/lib/nagios/plugins/check_gpio_pir.py -v
13
14ESC ZZ

Afterwards the sensor can be monitored comfortably! ๐Ÿ™‚

Photos

Some photos of the setup:

Translations: