Front page

Automatically muting APC UPS alarms

Most UPSs feature audible alarms to alert users of problems like power outtages or battery issues. But if you monitor your devices thoroughly, these alarms can seem unnecessary or annoying. They can be muted through software, but it seems that on certain UPS models the alarm setting is cleared whenever the unit is powered off. This means the alarms have to be manually "re-disabled" every time after an extended power outtage or other interruption in the use of the unit.

The only way to permanently disable these alarms is to physically remove the speaker element from inside the unit, but this is a very dangerous operation due to the high voltages potentially present inside a UPS. The next best solution is to automatically mute the alarms with a script when a computer connected to the unit is booted up. The best option is a server that is always powered on with the UPS, but a desktop system can also work. Just keep in mind that the alarms will stay enabled until the computer is booted up and the configuration script is executed.

This page only looks at configuring APC (American Power Conversion) UPSs on free operating systems. We'll use the apctest configuration utility, which is included in the apcupsd package. The utility is intended to be run by a user in an interactive shell, but the program doesn't actually care whether it receives commands from a keyboard or from a script. That means we can write a script that pipes commands into apctest, and this script can then be scheduled to run at system startup.

Install the apcupsd package on your system and open its configuration file (usually /etc/apcupsd/apcupsd.conf) in a text editor and set the UPSCABLE, UPSTYPE and DEVICE options. The package comes with a system service that handles various power events, like shutting down the system in case of an extended power cut. If you don't need or want this functionality, you can disable this system service.

The command sequence

First you have to identify the sequence of apctest commands that will disable the alarm on your particular UPS. In this example, the alarm is configured on an APC Back-UPS 1400 over USB. Your device may have different options or the options may be numbered differently, so make sure you use the commands specific to your device.

Stop the apcupsd daemon if it is running, and then run the apctest command as root:
$ sudo apctest

...

Please select the function you want to perform.

1)  Test kill UPS power
2)  Perform self-test
3)  Read last self-test result
4)  View/Change battery date
5)  View manufacturing date
6)  View/Change alarm behavior
7)  View/Change sensitivity
8)  View/Change low transfer voltage
9)  View/Change high transfer voltage
10) Perform battery calibration
11) Test alarm
12) View/Change self-test interval
 Q) Quit

Select function number: █
To configure alarm behaviour, select option 6.
Current alarm setting: ENABLED
Press...
 E to Enable alarms
 D to Disable alarms
 Q to Quit with no changes
Your choice: Select function: █
Select option D to disable alarms.
New alarm setting: DISABLED

1)  Test kill UPS power
2)  Perform self-test
3)  Read last self-test result
4)  View/Change battery date
5)  View manufacturing date
6)  View/Change alarm behavior
7)  View/Change sensitivity
8)  View/Change low transfer voltage
9)  View/Change high transfer voltage
10) Perform battery calibration
11) Test alarm
12) View/Change self-test interval
 Q) Quit

Select function number: █
All alarms have now been disabled. Finally, exit the program by selecting option Q. Thus, in this example, the command sequence we end up with is 6 > D > Q.

Writing the script

Open a text editor as root and paste in the script from below. The last line of the script shows the printf program being used to feed commands into apctest. The script also features a timeout mechanism that kills the script if apctest fails to exit. The timeout is set to 20 seconds, but it can be increased if necessary. The timeout should have enough headroom to allow for the successful execution of all commands.

The script shows in yellow the command example, 6 > D > Q. Replace it with your own from the previous step. The proper formatting of the command sequence is also shown by the example: commands must appear on a single line, each followed by a newline escape sequence, all inside the single quotes. No spaces or other characters are allowed.
#!/bin/sh

( sleep 20 ; pkill apctest ) &

cd /tmp
printf '6\nD\nQ\n' | apctest > /dev/null
Save the script as /usr/local/sbin/mute-ups-alarm, then make it executable with this command:
$ sudo chmod 755 /usr/local/sbin/mute-ups-alarm

Running at boot

On Linux (and maybe on the BSDs too) using cron

The easiest way to run the script at boot is to add it to your crontab. Append the following line to /etc/crontab:
@reboot	root	mute-ups-alarm
Most (if not all) crontabs include /usr/local/sbin in their PATH variable, so there's no need to type in the script's full path. If /usr/local/sbin is not included in your PATH variable, you'll have to type in the full path.

This works on Linux, and it also probably works on the various BSD systems as well. I haven't tested though.

On pfSense

To run the script at boot, the Shellcmd package is used. Install it through the web interface's package manager, then go to Services > Shellcmd. Click on Add. Type in the full path to the script in the Command field, and set Shellcmd Type to earlyshellcmd. The Description field is optional. Click on Save.

The script may have to be modified slightly to quarantee functionality. Full paths to executables seem to sometimes be required on pfSense. Use the which command to find the full paths for sleep, pkill, printf and apctest, and modify the script accordingly.

Also note that the script is not included in pfSense's backup system. In case of a system restore, you'll have to re-create the script.

Warning!

The solution presented here is a bit of a hack. As mentioned earlier, the apctest program is intended to be run by a user in an interactive shell, so blindly feeding hard-coded commands into the program comes with some risks. Mainly, an update in apctest could change the way the program behaves, leading to possible unintended configuration changes. The apcupsd project appears to be abandoned however, so breaking changes seem unlikely.
© kontunen.fi