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.
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.
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.
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.
404
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 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.
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