browser icon
You are using an insecure version of your web browser. Please update your browser!
Using an outdated browser makes your computer unsafe. For a safer, faster, more enjoyable user experience, please update your browser today or try a newer browser.

SMS Power Failure Notification

Posted by on April 12, 2010

We get frequent power failures at home due to ( our neighbor overloading his sockets and playing alot with electricity ) i setup this small system to notify me when power goes off and returns, unfortunetly i had this setup months back but due to a hardware failure i lost all settings.
Last night i decided its time to rebuild my setup again from scratch and this time document it 🙂

My Setup:
1-eeepc 900 netbook running Debian lenny

2-APC UPS 1000 with USB connection

3-Sony Ericsson K800i mobile ( Viva line ) with USB Cable



4-Gnokii

5-apcupsd

Step 1:
first step is to connect the mobile USB cable to the laptop & configure gnokii
These are the changes i made:

/etc/gnokiirc:
# For the Linux USB cables you will need one of the following settings (or
# similiar)
# port = /dev/ttyUSB0
# port = /dev/tts/USB0
port = /dev/ttyACM0
# the last one will work only with AT driver. The correct setting should be
# given in the dmesg output.

# mode use:
model = AT

# For Bluetooth and AT driver use the following setting
connection = serial


The rest is default.

/root/.gnokiirc

onfig : Linux, bluetooth connection
port = /dev/ttyUSB0
model = AT
connection = serial

To test the connection :

echo "TEST" | /usr/bin/gnokii --sendsms xxxxxxxx

Replace xxxxxxxx with your phone number

STEP 2: Configure apcupsd

Connect your UPS unit to the USB port on your laptop

edit /etc/default/apcupsd :

#set
ISCONFIGURED=yes

edit /etc/apcupsd/apcupsd.conf :

#set UPS Name
UPSNAME xxx

# UPSCABLE
# Defines the type of cable connecting the UPS to your computer.

UPSCABLE usb

UPSTYPE usb
DEVICE
# NOTE in USB TYPE DEVICE is left blank to auto detect

POLLTIME 60
# depends on your preference

the rest is default settings.
test the setup by disconnecting the main power from the UPS unit you should get a warning when the plug is removed and when its replaced back

STEP 3:Sending the SMS notifications

in /etc/apcupsd directory there are 4 small scripts that are used to send out notification emails : onbattery, offbattery, commok, commfailure
the first two are used for power failures and the latter two are for connectivity problems with the usb port.
you need to add one line to these scripts since they are all the same except for the message.

in this example i will take the offbattery script vi /etc/apcupsd/offbattery


#!/bin/sh
#
# This shell script if placed in /etc/apcupsd
# will be called by /etc/apcupsd/apccontrol when the
# UPS goes back on to the mains after a power failure.
# We send an email message to root to notify him.
#
SYSADMIN=root
APCUPSD_MAIL="mail"

HOSTNAME=`hostname`
MSG="$HOSTNAME Power has returned"
#
(
echo "Subject: $MSG"
echo " "
echo "$MSG"
echo " "
/sbin/apcaccess status
) | $APCUPSD_MAIL -s "$MSG" $SYSADMIN

#Add the following line and replace xxxxxxxx with your number:

echo "$MSG `date`" | /usr/bin/gnokii --sendsms xxxxxxxx

exit 0

Repeat the test in STEP 2 by unplugging the main power cable or simply switching off the power source feeding the UPS you should get something like this :

#when power is off
UPS_NAME Power Failure !!! Sun Apr 11 03:10:41 AST 2010

#when power is restored:
UPS_NAME Power has returned Sun Apr 11 03:10:46 AST 2010

as you see from above i spent the whole night fixing this thing ( Don’t do this at home unless u have no work next morning 😛

The use of the above setup is not limited to Power failures, you can do anything you need to be alerted about using gnokii previously i used it to notify me when a download is completed.. please don’t hesitate sharing any good ideas using sms notifications.

NOTE:SMS Charges may be applied depending on your carrier and plan

4 Responses to SMS Power Failure Notification

Leave a Reply

Your email address will not be published. Required fields are marked *

Q8i.Org