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.
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.
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?
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.
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.
I use an Automation triggered by the Start Event to send a notification.
If it wasn’t me doing the restart then the notification most likely means a restart after a power outage.
I have a Aotec ZWave Gen 5 Dongle via ZWave-JS that sometimes needs persuasion (unplug/replug) for the USB port (ttyACM0 /dev/serial/by-id/usb-0658_0200-if00) to show up correctly on the Raspberry Pi 4.
So when I get the notification I can ask someone at home to unplug/replug and I can monitor the plugin start up remotely!
Not ideal but at least I get a notification
alias: Notify me when home assistant starts
description: ""
trigger:
- event: start
platform: homeassistant
condition: []
action:
- service: notify.mobile_app_pixel_8
data:
message: Home Assistant Has Started
title: Restart
mode: single
In my setup it is very likely (99%+) that if HA and my Router did restart within 5 min. than I had a power outage.
This is the automation to detect it.
You can add a 3rd or 4th sensor to get even more confidence. Like Wifi Speaker, Smart Device of any kind that is powered. If 2, 3 or 4 device are in a reboot/restart/up&running state of a 5 min. or 10 min. Time window, you are quite sure that there was a power outage (and not that only the HomeAssistant/Raspberry, Router) etc. was restarted.
I did this exact thing today. I took a zbminir2 with default value off. once a minute HA polls its status. if it is off, it knows that there was a power outage, and sets the switch to on. then it continues to do some chores I need to perform whenever there is a power outage in my area. note that the zbminir2 is not connected to anything except for power (i.e. it does not control anything and nothing except for HA can change its status)