Safe shutdown of hassio when no ping response?


This is my very first post here on the forum. Been running Hassio for quite some time now, and I’m on the whole, quite happy with my setup. But!

I live in a place out in the countryside, where power outages are quite frequent. I have my raspberry with hassio connected to an UPS backup (along with my NAS and other stuff) and it works quite well since the powerdips usually only lasts for a minute or two.

But recently we’ve had some longer outages, especially when I wasn’t home to shut down hassio properly, wich has lead to all sorts of issues… Therefore, I have a question. I’ve been searching google and the forum without sucess.

I want Hassio to regularly ping (or by other means) a network source, and when that network source no longer replies, hassio should after a delay, issue the shutdown service. So when the UPS batteries dies, the raspberry is safely shut down and ready to reboot when the power comes back online.

Has anybody done this before? or does anybody have an idea how to accomplish this?

Thanks in advance!

There are add-ons to talk to the UPS and do an orderly shutdown.