Raspberry Pi

Hi All,
Complete NOOB here.
I want to make a Mains Power outage & restoration notifier using a RPi.
I'm thinking something along these lines:
Power a relay or optocoupler with an old mobile phone charger connected to a non-UPS mains power source and have the output(s) of the relay/optocoupler trigger a RPi on UPS to send an SMS and/or eMail.
Would also probably need a routine to send a message when the RPi is first powered on to cover those situations where the UPS turns off.
For my SMS gateway, I was thinking of using Textbelt - https://textbelt.com.
I want SMS as it's instantaneous, no having to check email clients constantly to see if the power's back on (I'm not always home).
Would just use my Gmail credentials for the email gateway.
Has anyone built anything like this before that can show me how to start and go about it?
If no one here has done it, are there any other resources people can point me to?
Many thanks

  • Stupid question - are you hoping to get a notification when the power goes or just when it comes back? You don't mention how the pi will keep connectivity to be able to send the notification when everything else has lost power.
    For the notification, is it going to a smart phone? What level of data service will it have? Generally I'd use a service like pushover instead of sms gateways but if you're in an area with spotty data coverage sms may be more certain. Keep in mind though that sms delivery times (or even delivery at all) aren't guaranteed.
      • Not a stupid question at all, I missed some detail.
        The ISP modem and a switch will be powered by the same UPS that the RPi is on. I want to be notified when the power goes off, and when the power is restored. However, I have since realised that there is a flaw in my thinking because the modem can take a few minutes to resync once power is restored. So if the UPS shuts down, then the RPi, modem and switch will all have to power back up, and the modem resync being the last of those things to happen means there will be no Internet for a few minutes after power is restored.
        I'll have a look at pushover.
          • This also makes the assumption the power outage is localised to your house. Is the setup resilient enough or are you going to have an issue where the local cabinet that serves your street also loses power?
            The 4g option mentioned may serve you better. Still has the risk I mentioned above but chances are the mobile networks ups setup will be better than yours at home.
  • They have devices built to do this mostly for remote COLO's or NOC's often as add ons or built in to things like UPS's and PDU's.
    You need to make sure they support at least 4G (3G is shutting down) in the frequency bands your country supports. Here's an example device:
    https://www.pumpalarm.com/power-failure-alarm/
      • Thanks, but overkill for what I want. My interest is purely from a personal perspective and it seemed like a good use for a RPi and a simple project to get me started.
    • Also it is very possible rolling your own solution would be blocked by spam filters used by cell phone providers or email providers if you went that route. Many power companies will text you when they admit there's an outage. Often there's nothing you can do in an outage any way once you have a reasonable amount of battery backups and generators.
  • Use uptimerobot.com. Let it do a simple check to a webserver running on the rpi. Done.
    Power goes out, uptimerobot sends you an alert. Power comes back on (and assuming all switches/routers/modems come on successfully too), uptimerobot sends you an alert. You can setup multiple contacts in uptimerobot that connect to email, slack, pushbullet, pushover, webhooks, and more. On a free account, no less.