I have a GFI outlet that gets tripped randomly, resulting in a big pool of water in my basement when the condensate pump stops running.

I would like to plug a Raspberry Pi in the other outlet, and get a notification (e.g. by email) when the Pi goes offline. It's no problem if it takes even an hour or so to alert me. There is a version of this for a Photon board here. I have an old Pi lying around, so I'd love to use that.

The photon board seems to have an established IFTTT integration. I see that it is possible to communicate with the Pi via webhooks, but I wonder if there is something even simpler to just see whether it's up and running.

Thanks for any leads!

  • 1
    how do you expect the RPi to send an email when it is off line? – jsotola Dec 23 '20 at 3:01
  • @jsotola, sorry if I was not clear. The idea is to have IFTTT detect when it goes off line, and IFTTT sends me an email. There seems to be an easy way to do this with the photon board, and I am wondering if there is an easy way with the Pi. – Nat Kuhn Dec 24 '20 at 2:56
  • now it makes sense ... lol ... try this service uptimerobot.com ... there may be others – jsotola Dec 24 '20 at 5:18
  • 1
    @jsotola, that looks PERFECT. And a good reminder to me that it pays to be civil when responding to people. ;-) – Nat Kuhn Dec 24 '20 at 18:20

There are several ways to do this. I guess the Photon board would work, but $29 seems a bit pricey - and a B-O-R-I-N-G project.

Here's how I might do this if it were my project:

enter image description here

First - an email alert is useful (if I'm out), but I wouldn't depend on it to wake me from a sound sleep. I want an annunciator for when I'm in the house, and email when I'm not - I want both of these alerts.

Second - I don't want a battery-powered RPi as part of the solution - more complexity, less reliability & more expense. Instead, I'll use a "2nd RPi" (or any PC/device with a network stack) to monitor the "basement RPi". One simple way to implement the event detection software is:

2nd RPi will periodically ping basement RPi
if basement RPi fails to respond then 2nd RPi activates alarm & sends email

This may be implemented in Python, a shell script - or virtually any other programming language. And obviously this scheme requires both RPi's to be connected to a network.

Third - send an email message from the 2nd RPi (or PC/whatever). Again, several platform-dependent ways to do this, but here's one way that uses RPi's mail program, a GMail account in a simple Python script..

Fourth - trigger the annunciator/alarm from the 2nd RPi. This is the interesting part: When I think of a hard-to-ignore annunciator, I think of a smoke detector - those little white pucks mounted on the ceiling or wall in every house. Since all we need is the annunciator, it's not necessary to have a new smoke detector. In fact, the sensor components are not needed at all as the annunciator will be activated via the "push-to-test" contacts.

As with all things, there are YouTube videos that illuminate the way... I didn't have time to find a good YT video; this one covers the essentials of the push-to-test hardware in a small fraction of the total run time.

The event detection software described above will do two things once it has detected the "basement RPi" isn't responding:

  1. Send the email
  2. Set a GPIO pin

The GPIO pin will actuate the annunciator through a hardware interface - a relay, or a transistor switch. There are numerous Q&A here that explain this (one example)

Finally - This is only an outline - an approach if you like - to meeting your requirement. It's an interesting project IMHO - you'll have learned a lot when you complete it. You may have specific questions as you work your way through the project. We'll try to help with those also.

  • Wow, @Seamus, thank you for this detailed and very interesting answer. It sounds like a perfect project for someone, but not for me right now. I actually don't want to be awakened in the middle of the night (there are $15 things that will do that BTW). If I am asleep for 8 hours while some water hits my basement floor, I'm OK with that, it's 2-3 days that I want to avoid. I also have more interesting projects already than time, so something quick would be good. But I appreciate your efforts, and hope someone else will find them and benefit. – Nat Kuhn Dec 24 '20 at 18:17
  • @NatKuhn: I'm glad you found it interesting. If all you want is the email alert, simply ignore the addition of the smoke alarm & GPIO assertion. The event detection will work exactly the same, and you can send email from your RPi using a shell script, Python, or most any other language. Also - feel free to register your opinion by voting. – Seamus Dec 24 '20 at 18:27
  • Thanks, @Seamus, already upvoted yesterday. – Nat Kuhn Dec 25 '20 at 1:53
  • @NatKuhn: Merci beaucoup. If you proceed with this project & have success, I hope you'll consider writing your solution up as an answer. – Seamus Dec 25 '20 at 14:05
  • All done, @Seamus. – Nat Kuhn Dec 25 '20 at 20:07

Following the suggestion of @jsotola, I managed to solve this, using only stuff I had lying around the house, and following @Seamus's suggestion, I am posting it here. (Also see my comment below for a simpler way.)

  1. I had an old Pi 2 Model B v1.1 and a wifi dongle. Unfortunately I did not have a USB keyboard, so I followed instructions for a "headless" installation—there are some older links floating around but that one seems up-to-date.

    I used the Raspberry Pi Imager and a 32 GB micro SD card I had floating around. I installed the standard RPi OS so that I can connect to the desktop via VNC if I want to, but you could certainly use the "Lite" version without a desktop.

    You need to create a blank file named ssh in the boot folder to enable ssh on the Pi. I did have a USB mouse and an HDMI cable, so I used that to set the timezone, language, etc.

    To connect automatically to wifi, you need to create a wpa_supplicant.conf file in the boot folder looking like this:

     ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev

    At that point, you can put your SD card in the Pi and plug it in. (I had not remembered that you need a fairly hefty power source; fortunately I had a charger from an old Moto X which is rated at 2.85A lying around.) When you ssh in, don't forget to use passwd to change the pi password from the default raspberry.

  2. You also want to reconnect automatically to wifi if you lose the signal. You will see lots of suggestions on how to do this using cron tasks, but there is a much simpler way, which I used.

  3. In order to use uptimerobot for the email notification, your Pi needs to be accessible from the internet. My Netgear router is set up to use no-ip.com for dynamic DNS (DDNS), but you need to make sure you renew every 30 days in their free tier, which is not good for a plug-it-in-and-forget-about-it project. I use dynu.com as my DDNS system for another project. You can set up a free subdomain (like example.ddnsgeek.com) with a number of choices for top-level domains. You need to set up the Pi so that it will refresh dynu every 5 minutes—here are the instructions for that. (Where they say vi you can use nano or another editor of your choice.)

  4. On your router, you need to forward a port to the Pi. To do the port forwarding, your Pi almost certainly needs to have a fixed local IP address. On my Orbi router, you can do this by "address reservation" which is quite hard to find; it's under "LAN Setup." Alternatively you could give your Pi a static IP address in whatever range your router has for that. I'm sure it's not difficult, but I was glad I didn't need to do it.

  5. For the port forwarding, I chose to use port 7022 coming in and route it to 22 on the Pi. You could probably just forward 22 to 22, but 7022 makes it a bit more secure. In my case I have a Verizon router, and my Orbi base station is plugged into it, so on the Verizon router I have to forward 7022 to 7022 on the Orbi base station, and on the Orbi base station I forward 7022 to 22 on the Pi.

    At that point, you should be able to connect to your Pi from a terminal by saying:

     ssh pi@example.ddnsgeek.com -p 7022

    The terminal could be anywhere in the world.

  6. Then create your uptimerobot account, and click on "Add new monitor." Make a port monitor, give it a name (like "my pi"), put in your domain name, port 7022 (or whatever port you use for SSH), and set the monitoring interval. I chose 15 minutes, because I want to give the Pi time to reconnect to wireless, change the DDNS assignment—or whatever else—in between checks.

Of course, you might not want ssh to be accessible over the internet, even though you changed the password. (You changed the password, right?) uptimerobot has various other options, but I think they will all involve some port forwarding, and I thought it would be cool to be able to SSH in from anywhere, for some unknown future project.

  • My son Ben points out that there is an easier way: do steps 1 & 2 (or equivalent). Then set up a cron job to report in to a service like Dead Man's Snitch or cronitor.io, which will alert you if the cron job stops. The cron task is just a curl command to a URL they give you. Both of those services will give you one free monitor. No need for messing with port forwarding, but no SSH into your Pi from Pago Pago, for better or worse. – Nat Kuhn Dec 26 '20 at 4:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.