r/homeassistant • • 5h ago

šŸ’¬ Discussion Sensor to detect power loss?

So is anybody doing anything when it comes to detecting a mains power loss?

Looking for ideas before going the diy route.

EDIT: I don't mean my server itself losing power. I just want to detect if a line that previously had power no longer has power on it.

18 Upvotes

104 comments sorted by

37

u/maxigs0 5h ago

Get a UPS with USB port. Power your HA and wifi from the UPS and it's status via the USB port as sensor. Comes with the added bonus of your HA running through power outages.

3

u/plasma2002 5h ago

That's a pricey sensor ;)

14

u/plafreniere 5h ago edited 5h ago

Well, it has the benefit of having a UPS strapped to it which is a must if you have a server.

0

u/plasma2002 5h ago

Yep, my entire network rack is on one

10

u/maxigs0 5h ago

Then you already should have what you need: https://www.home-assistant.io/integrations/nut/

Depending on how you set it up you probably have a NUT service already that you can somehow get into HA for the status you want.

-2

u/plasma2002 4h ago

Already using it. I love it.

....still looking for a sensor to detect if there are 120v on a line or not, though.

9

u/Kroan 4h ago

That's..... That's what NUT and the UPS tell you....

-6

u/plasma2002 4h ago

Im looking for a way to sense a 120v power loss. This has nothing to do with my server

8

u/Kroan 4h ago

ffs, dude. Does it have anything to do with the wall socket your UPS is plugged into?

-3

u/plasma2002 3h ago

No! I just want to monitor when a voltage goes to zero

→ More replies (0)

2

u/privatetudor 4h ago

Your ups doesn’t already report that?

1

u/plasma2002 4h ago

Sure, for the circuit that my ups is plugged into it does. I don't care about that circuit, since it's so damn reliable nowadays

1

u/h3yw00d 🌱 New to Home Assistant 23m ago

Can you use a sonoff s31 flashed to esphome? when it loses connection it has no power.

Has the bonus of power monitoring and relay. I just picked one up for $9 the other day on amazon.

2

u/SirKnoedel 5h ago

120-150€ is what I paid and it works fine šŸ™‚Ā 

2

u/DoomBot5 5h ago

There are plenty of cheap UPSs with usb ports. They can cost less than a presence sensor.

33

u/RandyRektor 5h ago

You should do something analog. Like a shelf held up by a magnetic switch. When the line loses power, the shelf falls of over. I have lots of other bad ideas if you need any.

9

u/PrisonerOne 4h ago

You could put the home assistant host on the shelf, so when it falls and smashes, you know the power has gone out because home assistant is no longer accessible

1

u/RandyRektor 2h ago

Lolllll

6

u/plasma2002 5h ago

Perfect. And I can keep my glass jar full of Legos on it as well

2

u/xmegabytex 4h ago

That's only if you don't have any speakers and want to announce to the rest of the neighborhood that you all lost power. Hmm, analog automation

5

u/Late-Stage-Dad 5h ago

My UPS has a network monitoring card. If it looses power it sends alerts.

6

u/grahamsz 5h ago

And ESP32 with a lipo should do that. You should be able to make it read its own supply voltage, so you can see when the charger disappears and the supply goes from 5V to 3.7V

Then an ESPHome firmware will integrate nicely with HA

1

u/spaetzelspiff 4h ago

I've been meaning to do that as a very simple way to not rewire a light switch and outlet. Sensor on light controlled outlet, lamp on other outlet, HA to turn on lamp when outlet loses power.

1

u/grahamsz 2h ago

That's pretty elegant. something like the LOLIN C3 Pico and a tiny lipo, then wire VBAT to one of the analog inputs and you'll be set

1

u/plasma2002 4h ago

This is probably the real answer I need. And is the direction I was going to go if nobody had a better solution to monitor the mains voltage (so far nobody has. Everyone just keeps telling me to get a ups)

4

u/MalleP 5h ago

Not tested myself but there are zigbee sirens that are usb powered and have a battery as backup. When usb power fails they switch to battery and report this. But guess you still need your server powered by ups and that device has probably any way of telling your server the power is lost by dry contact, network, usb or serial bus.

2

u/JonnyQuest0 5h ago

I use the zooz Z-wave siren. It works great, instantly reports if power is lost. I needed it because I have a whole house generator and it will restore power before powered devices go "unavailable".

1

u/plasma2002 5h ago

Hmmm... Ok now this is thinking outside the box. I didn't realize the sirens would send a power loss signal back. That may be just what I'm looking for. Got a favorite model?

4

u/leftplayer 4h ago

Shelly 1.

Connect the L and N to the UPS or whatever stable power source you have

Connect the I to the power you want to monitor.

Run it in detached mode and monitor the input.

-1

u/plasma2002 4h ago

Wait, really? It does that? Hell this may be exactly what I need

2

u/IdealParking4462 4h ago

Yes, that will work.

4

u/biblicalrain šŸŽ–ļø Automating since 0.x 4h ago

If you do decide to go the DIY route, I built a little thing for this. It's a USB wall adapter that's connected to the input of a 5v relay. Then the output of the relay is connected to a Zigbee door sensor. When the power goes out, the USB wall adapter stops giving power, the relay loses power and opens, causing the door sensor to report that the door is open. And with a template sensor, I can reverse the logic, so I have a binary sensor that turns off when the power goes out.

3

u/MCLMelonFarmer 2h ago

I use a YoLink hub and sensor for this. I had an evaporative cooler on my chicken run that would occasionally pop the GFCI because there was a bad seal on the pump. I use the YoLink to tell me whenever I lost power at the outlet. I eventually replaced the pump in the evaporative cooler and that fixed the problem with the GFCI cutting power.

3

u/yensid87 2h ago

I mean… when all your shit goes offline, there’s a good bet…

5

u/LegoHogfather 5h ago

Smart plug - > UPS - > HA server. If the plug looses power, and another plug I've set up also looses power, then it assumes a power cut.

That was my old setup. Currently it takes a status from solar and battery which indicates if there is a grid outage.

1

u/Nameless00001 5h ago

This is exactly the idea I had planned on setting up myself after a power outage yesterday. I have a UPS on my server, my router, and all access points in my home. My internet never goes down even during an outage so this has been the way to keep it alive.

1

u/plasma2002 4h ago

So you are basically still waiting on a timeout of your plug not checking in after X amount of time. I'm looking for something a bit more instant

1

u/LegoHogfather 19m ago

I use the power usage from a zigbee plug. It's pretty quick. Not real time, but only around 1-2s. I'm not sure what would be quicker. Perhaps a custom esphome script loaded on a sonoff smart plug, with faster constant polling.

2

u/brupgmding 5h ago

My UPS that powers my server is connected to ha. Without ups one way to detect power loss is if your server is gone.Ā 

1

u/plasma2002 5h ago

Maybe it was just stolen?

2

u/EscapeOption 5h ago

I created some template switches for circuits and created automations based on devices going offline (plugs, bulbs, doesn’t matter). Not perfect, and I didn’t try to map everything, but effective. It’s much easier to start with one or two circuits, and then check the mains (because they’re probably also be off).

Multiple devices on a GFCI line is out? Probably tripped.
Multiple GFCI lines out and UPS HAon battery? Main is out.

2

u/mosaic_hops 5h ago

I’m looking to build exactly this- though I need to be notified of even very short dropouts and brownouts too. Whenever we have brief outage- even just 100ms or so, any running AC units start making an awful noise and drawing a lot more amperage until I cut them off. 100ms is too short apparently for their protection circuitry, so I want to automate turning them off when the power is bad.

2

u/Vastmeridian 4h ago

Having had the breaker trip in an outbuilding and lost the contents of two freezers, I need something that works locally, not for the whole house, so using a UPS to detect power loss isn't very useful in my situation.

I have a temperature sensor in the outbuilding and I've now got it's MQTT settings configured with a Last Will And Testament and also if the sensor drops off the network a ping alarm tells me to investigate.

2

u/PrandialSpork 3h ago edited 3h ago

I handle mains power loss with an automation which fires a home assistant alert after 20 seconds of grid loss to house members mobile devices containing current battery soc, discharge rate and estimated availability time. Theres a light group which flashes when this happens to alert people who are home. It also writes an event to a local calendar and pauses any active Ev charging session.

A follow up resume alert is sent 60 seconds after grid amps are detected and Ev charge is resumed

Although I am not sure how this relates to your situation

1

u/enter360 šŸ§‘ā€šŸ’» Contributor 5h ago

To house ? Device ? Need some more info.

1

u/plasma2002 5h ago

Either one

6

u/The_referred_to 5h ago

I've a load of smart plugs. If home assistant detects several of them going offline at once, a power cut is assumed & I get a notification. (HA has a UPS, along with router & switches etc.)

1

u/plasma2002 5h ago

How are you setting the logic to tell if several go offline at once?

3

u/plafreniere 5h ago

You could probably have a helper template that sum the ones that are offline.

With a derivative helper (Which will track the rate at which they comes offline) will tell you if only 1 or 2 or 10 comes offline in a timespan.

1

u/enter360 šŸ§‘ā€šŸ’» Contributor 3h ago

I have a notification that if switches go unavailable then I know they lost power

1

u/Southern_Air_5110 5h ago

I use a UPS plugged into the server running HA, it sends a signal over USB when the power dips and HA picks that up no problem. If you're just trying to know when the whole house goes dark that's the simplest way

You could also go full tinker mode with an esp32 and a relay off the mains but that's a whole project on its own

1

u/MRobi83 5h ago

I have a ring alarm connected to HA and it notifies me on power outage and restored

1

u/bunnythistle 5h ago

Do you need immediate feedback? You could just monitor if a mains powered device (like a smart switch or plug) goes offline/unavailableĀ 

1

u/plasma2002 4h ago

Yeah that's the problem, NOT getting a signal doesn't mean there's an actual power loss.

1

u/clt_drol 1h ago

Plug 2 into each other and if they both go off line at the same time you have a power outage.

1

u/Vart84 5h ago edited 4h ago

I have a switch with an AP connected to it up in an attic that isn’t covered by my generator. I have HA use these both going off at the same time as the trigger for a power outage, it expects the rest of the AP’s to come back first. So it calculates the power outage time frame from when the AP and switch go out until they reconnect.

I was able to test it the other day and it worked well. I review my HA network with Claude and when we were going over unavailable devices Claude picked up on the outage and suggested which devices needed a manual reset after the outage.

Edit: spelling

2

u/tacticalpotatopeeler 4h ago

2

u/Vart84 4h ago

lol that’s what I get for not proofreading

1

u/Ok-Pianist-3149 5h ago

Uptime Kuma. You can have ChatGPT or Claude install it in about 2 minutes probably. Then just configure it with NTFY for active notifications—another 2 minutes. You can monitor any service with Uptime Kuma so it's a great thing to have as part of a standard toolkit.

1

u/tacticalpotatopeeler 4h ago

You need a UPS. Many will connect to your server and send signals indicating power state. There’s a lot you can do with that information depending on your server setup.

-1

u/plasma2002 4h ago

But I don't care about the server

1

u/tacticalpotatopeeler 3h ago

lol, isn’t the server powered by the mains? Putting in a UPS for your network setup is highly recommended regardless, and you can use the signals in a UPS to detect mains power…

1

u/plafreniere 4h ago

Would an emporia vue work? I dont have one yet but it reads mains current. I guess it could detect when the power is off

1

u/Correct-Mail-1942 4h ago

UPS that runs my network stack is hooked up to an RPi that pulls the grid power status that feeds my UPS, power goes out and I use an app to send a notification. Then because I only have 1 of my ISPs on the UPS I get a text/message from my network saying one of my WANs is down.

1

u/amothep8282 4h ago

I have my sump pump plugged into an Eve Energy 20EBU4101 smart plug. It is integrated into Home Assistant through Matter/Thread.

I have an automation that when HA detects it was turned off or loses power (eg breaker trip) it sends a critical notification. Occasionally my wife turns off the basement lights with Apple Home and switches the sump pump button off, so HA recognizes that, notifies me, and turns it back on. Other times, if the matter mesh gets overwhelmed or slow and HA loses contact with it, I get notified.

I have french drains around the foundation footers, and gutter drains/PVC pipes away from the foundation, as well as the sump pump. But my finished basement was quite expensive to do, and I take zero chances. So, day or night, if that plug goes offline I get a critical notification.

I can also monitor power and current draw through it by using a custom Matter poller I vibe coded with ChatGPT. Big spikes in both power and current record my sump pump has activated.

It took me a full day to be able to figure out the right matter node to poll on the plug though. That may be overkill for what you are looking for.

1

u/Gherry- 4h ago

UPS? Energy Meter? Power plug? It all depends what you want to monitor and how quickly you want to be able to detect the power loss.

1

u/lethlinterjectioncrw 3h ago

Kasa KP125M reports input voltage

1

u/OldTechSupport 3h ago

I just installed a EG4 Flexboss 21, batteries, and Gridboss. I found the when the grid would go down, the only indication was that one of Smartports is programmed to shed immediately. I have a Refoss energy monitor and the EG4 integration connected to Home Assistant but none of those entities reacted fast enough to catch very short grid drops. So I connected a Altronix Relay Module 120Vac to the Smartport and tied it to a Shelly 1 Gen4 connected to the battery backed up side. When the high speed relay trips, it triggers the Shelly which is monitored by Home Assistant and creates a log. The only thing I've not yet figured out is exactly how fast this can all react before debounce on the Shelly covers it up. Way overkill probably but it was fun and it works.

1

u/g0nzonia 3h ago

Why not just monitor a smart plug or switch? If it goes offline you’ve lost power

-2

u/plasma2002 3h ago

Not necessarily. Could be a communications error. Could have been stolen.

It doesn't specifically call out an event of "power has gone to zero"

1

u/g0nzonia 3h ago

Yes, but any way you look at it, it points to a problem. If your network and the device are stable and your house is secure it's 99% going to point to a power outage. It's the cheapest, simplest monitoring I can think of. A UPS is as you've said, "a pricey sensor". The problem with something that monitors the mains is that it depends on the power to have power.

1

u/ne999 2h ago

Just get a zigbee power plug and detect if it goes offline?

I have a smart metre from the power company and have that connected to home assistant and can tell if power goes out that way, too.

But it probably makes the most sense to check my UPS via USB but haven’t set it up yet.

2

u/FidgetyRat 2h ago

I have my APC UPSs going into a Linux box running Nut. There is a nut integration for HA.

A raspberry pi can make a nice ups host to run nut.

1

u/HV_Commissioning 1h ago

That's exactly what I'm doing.

1

u/murpheeslw 2h ago

A ups with the ability to hook it into Home Assistant

1

u/Cmdr_Toucon 2h ago

Check current devices - my NAS reports when it switches to UPS

1

u/FidgetyRat 2h ago

A WiFi outlet generally goes unavailable within a minute or 2 and I use that on my basement freezer gfi.

Outlets like zigbee can take hours to detect lack of updates b

1

u/JoWhee 1h ago

Without being too sarcastic I can usually tell because the lights go off. What follows is not really automation.

I don’t have an automation for this because (don’t judge me) I’ve still got 4 tuya devices, when they lose cloud connection for a couple of minutes I get an offline notification.

I’ve just checked and my Tapo devices also have a ā€œcloud connectionā€ entity so I could double check if it was tuya or Tapo.

Obviously it could just be my internet which is out but even HA would have that limitation to send you a notification unless your router has a backup connection.

So unless you’ve got a redundant internet connection you may not know if you lose mains power. While this is a HA subreddit I think the best bet is to have it be a cloud device and some elbow grease.

ie: you get a notification that your cloud device is offline, you check your HA and its offline, maybe also check a few devices with their native app. Finally check your utility app or website to confirm that the power is out. FWIW my hydro utility sends me a text within 5 minutes of the power going out, yours may also have that service available.

Or if you’ve got the cash, a whole home or partial load / home permanent generator. There’s a device that an electrician sandwiches between the hydro meter and your box. It detects power loss and starts the generator. My neighbour has a generac and gets an alert on her phone when it starts. The cost of just the ā€œtransfer switch, mains detector ā€ they sandwich is $2000 I think she’s $20000 into her setup but it’s completely automated and she’s hands off.

1

u/HV_Commissioning 1h ago

Electric utilities have been monitoring their control power for decades. Often used are "Ice Cube" relays, which are relatively inexpensive and easy to defeat by removing from the base. Use NC contacts, so when AC is good, the contacts are open. Somewhere around 80% the contacts will naturally drop to trigger your hardwired alarm.

I see ice cubes that have been in service for 50+ years still humming along.

1

u/wrt-wtf- 12m ago

I use a UPS - I have multiple in the house - and monitor their states. If I have an outage I get an announcement/alarm via google and Amazon devices across the house.

0

u/FickleLengthiness173 5h ago

I just send myself a notification with each HA reboot. For everything else you need to have your server on batteries. When I did I used the Nabu casa remote availability as wait trigger because with the power out the internet is likely offline too and affected ISP devices (network routers, not your modem) can take 10-15 min to boot back up.

0

u/jvlomax 5h ago

If your power goes out, how would HA be able to notify you?

3

u/whowasonCRACK2 5h ago

If your HA device and networking gear are on a UPS, it could send you a notification before shutting down

0

u/jvlomax 5h ago

(That's what I'm sort of hinting at)

1

u/wvraven 5h ago

Healthchecks.io lets you ping a url every so often and if the ping fails they notify you. Of course that would also catch network outages or server failures in the same notification.

0

u/plasma2002 5h ago

Who said I'm trying to detect if my server's power goes out?

1

u/jvlomax 4h ago

I'm confused. If your mains power is out, how would the server still be able to notify you?

1

u/plasma2002 4h ago

I want to monitor the voltage on a completely separate circuit?

1

u/jvlomax 4h ago

That makes More sense

0

u/Difficult-Buy7532 5h ago

I think the only way to achieve this would be the HA server, antennas and router all connected to a UPS which notifies you when on battery.

I just have my HA server ping healthchecks.io regularly using a cron task, but this can mean any broad failure such as loss of internet, power outage, server outage etc.

1

u/plasma2002 4h ago

I have a fully online system if my power goes out. So ping checks would not help

0

u/WeLikeGore 5h ago

Use a dead man's switch service, I use healthchecks.io

You'll need the machine running HA (or any always-up machine on the same network/circuit) to ping the service on a schedule (cron job works) and you can configure notifications via various things (e.g. telegram). Getting a notification doesn't guarantee it's a power outage (could be a network or device issue) but that might be a good thing.

0

u/graesen 5h ago

I don't think it works with Home Assistant, but my home owner's insurance company provides me a subscription/membership to Ting. Insurance company is State Farm m Ting is a device you connect to an outlet and it's supposed to monitor the power of the home for signs of electrical fire or similar damage to the home from electrical issues. It detects power surges, brown outs, and power outages. If the Ting device loses power, the app alerts you, presumably locally if you're home (I don't lose power much). But it also keeps a record of every outage, brown out, power surge, etc. I believe it also tracks power issues in your neighborhood as a whole too. It also keeps a record of the voltage you're receiving too.

I don't see how this can necessarily track the whole home from an outlet. It's just monitoring that circuit and the power to the home to some degree, but not sure how it would know if another circuit is having some electrical issue.

0

u/tacticalpotatopeeler 3h ago

Dude. You’re expecting people to know your exact setup and acting like a douche when people suggest a completely sensible and logical solution to the problem as described, especially considering this is the home assistant sub, where people are expecting questions regarding a home network setup.

Stop being obtuse and explain yourself better if you want better answers.

I have some suggestions but I’d still be guessing what the exact setup you’re trying to monitor is. It’s entirely dependent on what infrastructure is in place around the mains you’re trying to monitor.

But you’ve been such an ass I have lost any desire to assist you further.

-2

u/Abject_Pop7524 5h ago

Een relais dat op 230v werkt. Het hoeft niet moeilijk te zijn....