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?
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.
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:
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.
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.
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.
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.
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
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 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.