Power Outage detector

Hi all,
I’m thinking of a way to detect power outages. They are not very frequent (less than 5 per year), but when they happen I would like to be notified on my iPhone, so I can check if everything is ok (especially Philips Hue lights which, as you know, turn on after a power cycle, but are also controlled by dumb switches at my home).

My RPi, router/modem and hue bridge are all under an UPS, so my idea is to use the availability_topic of a Sonoff switch in order to determine if the there is a power outage. When the switch became unavailable an automation should trigger an iOS notification (no idea how to do this exactly, yet).

What do you think? Would this be feasible and fast enough in the case of a very short power outage?

1 Like

I just have a notification when homeassistant starts and a maintenance mode input boolean.

If maintenance mode is on (I’m working on the system), no message. If its off, possibly a power cut, send the message.

2 Likes

thanks for your reply @anon43302295!
But, as I wrote, my HA is running on a raspberry pi which is attached to an UPS, so HA never restarts when there is a power outage.

Does your UPS have a ethernet connection? If so I believe you could use NUTs and monitor it so when it switches from power to battery you send an alert.

http://wynandbooysen.com/raspberry-pi-ups-server-using-nut.html

Unfortunately, it doesn’t. I should think about getting a decent APC UPS, but in the meanwhile I would like to find a workaround :slight_smile:

you just need a UPS with NUT, you connect it to the pi3

  - platform: nut
    name: UPS Hassbian
    host: 192.168.1.239
    alias: ups
    username: !secret nut_username
    password: !secret nut_password
    resources:
      - input.voltage
  #    - input.frequency
  #    - output.voltage
      - battery.charge
      - ups.status
      - ups.load

thanks @anon35356645, I have a “dumb” UPS at moment, no serial, no ethernet, no usb… anyway, in the future this info will be useful!

Ohh then is different. I bought a very cheap UPS and it had it, then I followed this

http://wynandbooysen.com/raspberry-pi-ups-server-using-nut.html

With the default configuration, the timeout for a Sonoff to go offline is 30 seconds. For very short interruptions they can reboot and reconnect in that time, never going offline.
A Sonoff Pow can report line voltage on a chosen schedule, even every second of you need, but only when the load is ON.

EDIT: I missed you have a RPi… you can use the GPIO pin to connect a simple detector circuit, like these:

Or this:
http://learn.edwinrobotics.com/230v110v-ac-mains-detection-using-arduino-raspberry-pi-and-esp8266-thing/

Just look up on Google for “raspberry pi mains detection”, there are plenty of solutions.

I struggled finding a simple solution to this too. After looking at several options, the simplest/cheapest (free) solution I came up with was using a Windows server I have that is connected via USB to my UPS. I have the APC PowerChute client which logs events to the Windows Event Viewer. I then assigned a task (using Task Manager) for each APC power on/off event to start a program (simple batch file) that sends a MQTT publish message to my MQTT server using a pcname/upspower topic. I then setup a HA MQTT sensor on that topic and it will track “On/Off” status, where I can then assign an automation like any other sensor.

Simpler is to use nut server and nut client

Agreed it would be a better/simpler solution but I don’t have a L/Unix server built. Would prefer a R-PI which I may do one day. :slight_smile:

You put the nut server and client on the same pi.

You just need to connect with USB the ups to the pi

Well I run HassIO so that’s not an option. :frowning:

you can, on my NUC I have HASSIO and Ubuntu. Should be possible also on the pi

My Sonoffs drop off with LWT after 5 seconds and would be perfect. But I do have a USB UPS on my box as well and just have a notification if the input voltage drops below a threshold.

I didn’t want to create a new topic so here it is.
I’ve created a power outage sensor with a cheap 5V relay. Homeassistant is running on a rasp pi.
This is the relay I am using. It costs less than 1 dollar.

You first need to solder the IN port to GND.

image
and power the relay from a power adapter from which you want to see the power state.

For the data part; connect a spare 3.3Volt pin to the COM port and any BMC pin to NO port.

image

And configure as follows:

binary_sensor:
  - platform: rpi_gpio
    ports:    
      18: Home Power
    pull_mode: DOWN

pull mode is important here. Otherwise it won’t work. So far this is the fastest and most reliable method for me to see when the power goes offline.
It is also important that your rasppi is powered through a UPS obviously. For this I use a cheap powerbank. This is the cheapest method I’ve found for a UPS for the rasppi. Around $12.

7 Likes

404 :frowning:

What about this “sensor”? It based on resistive voltage divider, which can be made of couple resistors. Voltage Sensor
I have one, but have no idea how to connect it to hassio on RPi

UPD Want to detect 5v outage

I know this is old topic but i found a cheap solution and it may help someone someday.

I Used
1- Sonoff Basic (with Tasmota firmware )
2- 220v/120v Relay (will leave link but any 220/120v AC relay will work) (You need to know how relay works :slight_smile: but i will try to explain )

Relay function is to take input AC signal (220v or 120v), and it makes two output totally separate from input voltage outputs called NO (normaly open) or NC (Normally closed )signal (Think of it as a wire either connected or disconnected by default “switch” so if 220v is present then wire is connected if not then wire is disconnected).

At our example let assume using the 2 pins for NO (Normally Open) at relay will be connected at ground and at Rx pin for example at sonoff then from here you can play with it as a normal switch and configure sonoff tasmota as switch.

Of course Sonoff need to be on UPS and Wire input to relay need to be on non-ups outlet.

Relay link : https://www.aliexpress.com/item/32650628066.html?spm=a2g0o.productlist.0.0.47652910S60tao&algo_pvid=995c7d06-851e-40fa-b3e0-6abe1781c513&algo_expid=995c7d06-851e-40fa-b3e0-6abe1781c513-0&btsid=0ab6fab215907971532548305e73c2&ws_ab_test=searchweb0_0,searchweb201602_,searchweb201603_

1 Like