Using UPS with Synology and Home Assistant using NUT

I have an old APC UPS. It's Back-UPS Pro 1000. It's a decent UPS with all the functionalities that I want, except for the fact that it still takes lead-acid batteries. I recently connected it to my Home Assistant using Synology and NUT. This setup enables me to monitor the power, send alerts, and take action.

We have a generator-backed backup in our apartment. This means there is a couple of minutes of downtime before the public power goes and the generator kicks on. Since we don't have a separate UPS for the home, my home server's power is cut off abruptly and shut down hard. This is not good for the server, and it happens often. Hence, I have a small UPS for the server, modems, etc., so their power remains uninterrupted before the generator kicks in. It works well.

But every so often, the generator doesn't start on time or doesn't start at all. This is when the UPS runs out of power, the server is again forced to shut down hard. Again, not a good idea. 

The best scenario would be where UPS tells the server that it is low on power, and the server proactively shuts itself down safely. Also, if my server notified me of the status change, say OL ( ONLINE AC) to OB DISCHRG ( ON BATTERY) to OL CHRG, it would be awesome.

Even though my UPS was old, fortunately, it had an RJ45 serial port for communication. A standard serial cable is incompatible with the Back-UPS; you must buy the RJ45-USB cable from APC. Since I had lost the original cable, I got a new one -> APC USB cable AP9827

Since my primary server is a Synology, docker containers run inside it. It's the one I want to protect first. I connected the USB to Synology. I then looked into Synology- Control Panel - Power - UPS. It was recognized by Synology and available for configuration.

I enabled the shutdown (safe mode) of Synology when the power became critical. In my case, it's when 3 minutes of power are left.

Synology -  Power UPS support screen
Synology - Power - UPS support screen

When the Synology Unified Controller enters Safe Mode, it stops all services and unmounts volumes in order to prevent data loss and shut down safely when the UPS device runs out of power. By default, the system enters Safe Mode when the UPS device starts running low on power. You can also specify the amount of time before the Synology Unified Controller enters Safe Mode when power failure occurs. However, if the UPS device reaches low battery before the specified time, the system enters Safe Mode immediately.

In situations when the Synology Unified Controller shuts down during Safe Mode, it will automatically turn on when power is restored if you have enabled the Restart automatically after a power failure option (located at Control Panel > Hardware & Power > General).

UPS - Synology - Home Assistant Setup

Synology also allows us to expose the UPS further in the network using the standardized NUT protocol. I enabled that to connect to this UPS from my Home Assistant for further monitoring, logging, and alerting. Synology allows up to five clients restricted by IP address to connect to it using NUT protocol. Since my Home Assistant runs on the same Synology as a docker container, it uses the docker's internal IP address when accessing the same machine's NUT. So, I found my Home Assistant Docker's internal IP address (172.17. 0.0/16 range) and added it to the allowed list on Synology.

IPs Allowed to connect to Synology NUT server

Configuring it inside the Home Assistant was easy. Network UPS Tools (NUT) configuration comes natively. Add it using the UI. Give the IP address of the Synology server on LAN, which is acting like a NUT server on port is 3493. For username and password, log into Synology using SSH and look into /usr/syno/etc/ups/upsd.users file. This file will have username and password for the NUT. Use it in Home Assistant - NUT configuration.

The configuration exposes lots of sensors. But most of them are disabled by default. Enable them if you are interested in monitoring them. I have enabled the following.

  • sensor.ups_battery_charge
  • sensor.ups_input_voltage
  • sensor.ups_load
  • sensor.ups_status
  • sensor.ups_status_data
  • sensor.ups_battery_runtime

Check this link for the meaning of above variables. I have set up an automation based on ups_battery_charge and ups_battery_runtime to send me alerts using NTFY. You can use a combination of variables to make your alerting as accurate or informative as you want.

NUT setup on Home Assistant
NUT setup on Home Assistant
You can auto restart the Synology when UPS is capable of supporting it again, after safely shutting it down.

So now my server sends me an alert when the power goes, and it's running on the battery; it also sends me an alert when the battery is critical, it shuts down safely, and it alerts if it auto restarts once the power is back. All helpful notifications to get. 

How do you manage power for your home servers? Any tips for me?

You can read this blog using RSS Feed. But if you are the person who loves getting emails, then you can join my readers by signing up.

Join 2,241 other subscribers