its maybe an old topic but i got a simple solution using UPS without NUT if someone is interested.
my UPS got a simple USB connection, when its connected to my PC i receive events to EventGhost each time the UPS goes into battery mode when there is an outage and back to line when its back.
then i can communicate with hassio via API or MQTT to update it and do what ever i want.
hope it helps.
What EventGhost action or plugin makes that possible?
Thanks in advance.
no plugin what so ever.
my UPS is connected to my PC via USB, I have a software called UPSilon 2000 which i monitor the UPS voltage with, I don’t know if the events EventGhost picks up are coming from the UPS is self via the USB or maybe from that software.
If your UPS got a USB-B output, Connect it to your PC and try to force event by pulling out the power cable for example to simulate power outage. Monitor EventGhost to see if some event is fired, If not then you probably need that UPSilon software which i hope support you UPS.
Good luck!
I’ve decided to make a small Arduino program that sends MQTT message each time is booting up and used it in an ESP8266 I had laying around.
Seems adequate for now as I only wanted to know when the power was coming back to turn off some stupid smart bulbs that didn’t retain their previous status.
I love the simplicity of this power outage sensor.
Would you mind sharing:
- What script you use to power down your RaPi
- How do you restart the RaPi when power is restored and do you handle power bounces or brownouts in the process?
Thank you in advance.
I have this one, but I haven’t tested it yet.
1-channel mains voltage detector 240VAC
Power supply 3-5V
I’m considering connecting to a nodemcu
The apartment I live in has a generator. And the longest outage lasts 12 seconds. Never had a reason to power down the rpi. By the way I’ve started using esp32 in place of the rpi now. And it also works perfectly.
I struggled with this as well (lights turning on automatically after power outage) and after 2 years… I just came up with another idea.
Use that “light” as a canary to let me know it turned on by power outage. The light is linked to a motion sensor so if light=on, motion=off… it means power outage.
I mean in its simplest form, use a smart lightbulb that “turns on after power outage”, plug it in and in hassio “turn if off”. Leave forever plugged in. You now have your “canary” to know if a power outage occured.
alias: HA recovers after power outage - turn off all lights
trigger:
- event: start
platform: homeassistant
condition:
- condition: device
type: is_on
device_id: cf7c4d4d314c804993374fc3ccee214f
entity_id: light.was_1
domain: light
- type: is_no_motion
condition: device
device_id: 22da8868fdeb302b3dfa134a8262efa8
entity_id: binary_sensor.was_motion_sensor
domain: binary_sensor
action:
- delay: '00:02:30'
- service: light.turn_off
data:
entity_id: light.all
- service: notify.telegram
data:
title: Home Assistant started
message: Home Assistant started after unexpected shutdown.
mode: single
The original delay of 2.30 min was because this is how long the Ikea Hub took before being ready to turn off. In my system this is now irrelevant since I ditched the Ikea Hub for a Conbee II stick.
Another solution, is to buffer the internal 5 V of a Sonoff POW (that you may have anyways you’re system) so the Sensor will continue monitoring the Outside Voltage and switch not off.
This way you have a permanent reading also on Power „out“.
My problem was, that sometimes the Power drops to a critical low level. This way I also detect this problem and can notify or switch critical hardware off.
The rest is software within HA.
@sendorm When you posted that relay, I suddenly felt really stupid. I have a bunch of that same relay lying around, and I can’t even count how many 5V power bricks I have kicking about. Of course you can use that to detect a power outage!
Thanks for posting that and pointing me in the right direction, 10 minutes later, and I have a binary sensor, a lovelace alert card, and a push notification all working properly!
Glad to be of help here
Hello, is it possible to have a drawing of this configuration please ? I’m really not good at electrical wiring and not familiar with relay.
Thanks a lot
Regards
All the details are in Post 17 above.
You literally just take a 5V power supply (any usb supply will do), cut off the end and connect the 2 power wires to the relay, the negative wire connects to both the GND and IN pins, while the positive wire connects to the VCC pin. Then on the other side of the relay you connect the NO pin to the input pin on your Pi and the COM pin to one of the 3.3v pins on the Pi (in his example he uses pin 12 for the input pin, and pin 17 for 3.3v power)
Then you add the binary_sensor configuration as shown in his post.
Any time the power supply stops putting out power (i.e. a power outage) the relay will open and the binary_sensor will toggle to show that power was lost.
Thanks a lot for your fast answer, i will try !
Best regards
Hello, i just made it, works perfectly !!
I love it, thanks a lot
I use a dry contact sensor that detects a 5v from a cheap usb charger. Some might have an input for this, but the two sensors I use did not, so I added a reed relay in one and a transistor in the other (just 2 ways it can be done) to act as a switch in place of the reed magnetic contact in the sensor. These components are powered by a USB cable (end cut off and soldered to components inside sensor). Installation of the sensor just requires you plugging in the battery powered sensor into a USB port that will lose power during an outage.
Given my home assistant is powered on via a UPS for a short while after a power outage, it is able to receive the status change from the battery powered dry contact monitoring power. With this solution you can monitor for outages in more than one location (I had GFCI/AFCI breakers tripping in the house… turned out to be leakage current from the UPS s themselves and a few other things) but only if the sensor can communicate directly with the controller (hard wired repeaters would be offline during outage).
I had a 12hr power outage resolved at 03.30 last night so today I will be implementing the automation to turn stuff on and off as appropriate. Hopefully this will lessen the torture as most of my power outages are restored in the middle of the night.
I have an old Android phone permanently on charge. It’s running Llamalab Automate, which texts me whenever the power goes off.
https://llamalab.com/automate/
No connection with HA in this particular case, but the HA app is also running on the phone and any notifications directed to that device also get converted into texts, which makes it quite versatile.
I stumble on this automation by accident because I’m working on slightly different but it applies to you guys.
Instead of using a Pi/ESP or a light bulb, I am using this zigbee relay. Each times it comes back with power, it sends its status.
In case you wonder why such a device instead of a light bulb. We have dual energy (electricity/gas) and when temperature are below -12C, 24V comes out of the meter to inform heating system of using gas instead of the electricity. When temperature goes above -12C, power is applied and zigbee sends message. But when there’s no more power applied to the device it goes offline. I’m using zigbee2mqtt and the “down device” notification takes forever to come. That’s not good for me, so …
I’m aiming to toggle every 5m on one of the 2 relays. IF the last mod state time doesn’t change, it means device is down. I’m still learning how to “code” this , feel free to ping me directly if you have ideas but don’t reply here … I don’t want to hijack the thread.
Now that rpi_gpio is no more supported, can you please share info on how to achieve the same now, with MQTT or other add-ons ?
Yeah I have long changed this setup to a esphome one. The same thing actually.