Simple way to recognize a power outage

I want a notification in case I had a power outage.

The idea is to monitor internet connection and assume it takes more than a minute to recover from a power outage. So in the end after restart there should be missing internet until it is reconnected.

Restart HA (due to power outage - or crash)
check internet - if false power outage probable
check internet - if true power outage very probable

Any easy way to do this by ping google or something like that? I only need that for about five minutes after restart to check for that.

I use APC UPS with NUT for power detection.

Well, we have rarely a power outage, but it is nice to know.

I found a sensor template:

binary_sensor:
  - platform: ping
    host: 8.8.8.8
    count: 2
    scan_interval: 10
    name: Internet

Is it possible to deactivate this sensor after it is online? I don’t want to always ping in this frequency.

What about an uptime sensor?

Yes, but this will also include restarts and crashes.

How are you powering your HA instance during a power outage?

I am not. I just want to know. :slightly_smiling_face:

So your first step needs to be installing an UPS, because no amount of automation is going to work when your HA instance isn’t on. Beside detecting power outages, I would highly recommend you put your HA on a UPS. From what I’ve seen, HA doesn’t do well in an uncontrolled shutdown (power pulled)

When looking at a UPS, make sure it’s compatible with NUT.

With a compatible UPS and NUT and then some simple automation your problem is solved, and your HA instance is protected a little better.

But if there is nothing to control what is the benefit of that? Many devices require power. Is it only to protect HA from crashing?

Only mains powered devices that are not UPS supported. I have many battery powered, alarm system and cameras that are all UPS supported. The NUT integration is for server protection, notification & automation. I know exactly what the power situation is at all times.

but I digress…

I think your logic is a bit flawed in your original post, as you can not do anything (as in you have no options) if your HA instance is off, so why bother?

Well, I just want to know it. Even if I can‘t do anything about it.

It works with the online monitoring at startup.

Here’s a use case I’m working to solve for: My HA and UDM Pro are on a UPS that doesn’t support NUT. I want to use HA to detect a power outage, and send a shutdown signal to my UDM Pro so I don’t have to reinstall the firmware every time the power goes out…which happens too frequently, corrupting the UDM Pro every single time.

a month later, i’ve got the same issue. did you ever solve this?

You could use a system like healthchecks.io that you would call every X seconds, so that when the power is out healthchecks.io to send you an email or telegram notification. That would mean something has gone wrong.