Smart(er) Home – Knowing when the power is out

One of the benefits of a smart home system is knowing that everything is okay when we are not at home. We live in an area with a very high water table and have water in our sump pump year round. Over the past ten years in the house there have been 3 sump pump fails, but only one resulted in a bad flood. I needed a way to know if the power has gone out. Yes, there are battery backups, and I will invest in one at some point, but for now just getting an early warning will do. It was time to come up with some technology to solve the problem.

I thought of ways that I can use a RaspberryPi to monitor the sump crock water level, but if the power goes out, the internet goes out, and the notification will not be sent. To get around this I wrote a small script that will ping my router. If it is offline, then the script will look at our local power companies outage page to see if there are reported outages on our street. If there is an outage it will use Pushbullet to send a notification to my phone to tell me that the power is out, how many customers on my street are impacted, and a time that it is expected to be restored. Now I have an early warning that there may be a problem, and I can head home to address it. I put the script together in Bash, however I may move it to Python at some point.

OUTAGE_URL={URL for the Power Company outage page for my town}
STREET=(My Street}
USERS_TOTAL=`grep (My Street} savedFileName.html | cut -d '>' -f5 | rev | cut -c 5- | rev`
USERS_OUT=`grep (My Street} savedFileName.html | cut -d '>' -f7 | rev | cut -c 5- | rev`
ETA=`grep (My Street} savedFileName.html | cut -d '>' -f9 | rev | cut -c 5- | rev`

# Test to see if home internet is up
if [ $? ] = 0 then
echo "Internet is Up, Power is alive"
`wget $OUTAGE_URL`
#if curl -s "$OUTAGE_FILE" | grep -q "$STREET"
if grep -q "$STREET" $OUTAGE_FILE
echo "Users Out: $USERS_OUT"
echo "Power Expected Back: $ETA"
# curl -s -u $PUSHAPI -d type=note -d title="Power May be Out" -d body="Users Out: $USERS_OUT ETA: $ETA"
echo "I have the POWER"

I have this running on a VPS that I have purchased for a few dollars a month to play with. Sometimes the internet will stay up in a power outage, and my servers and modem are plugged into a UPS, but for peace of mind it is better to run this offsite. Over the past year I have had 1 false positive, but there were two times that this saved our basement from a flood. I had ample time to get home, hook up the generator and keep things dry.