# APC UPS Setup

##### How to set up UPS monitoring via USB, for APC UPS models.

1. Plug in the USB cable (dur)
2. Edit the UPS service in TrueNas:

    2.1: Choose USB driver with closest match to APC UPS model, and choose correct USB device (usually something like `/dev/ugenX.X`) and set UPS name to simply `ups`
    
    2.2: DO NOT check `Remote Monitor`
    
    2.3: Add Monitor user and password, copy same info into the `extra users` section in this format (note brackets!):
    ```
    [{username}]
		password = {password}
		actions = set
		actions = fsd
		instcmds = all
    ```
    2.4: Set shutdown to "UPS Reaches Low Battery", set command to: `shutdown -p +1 "System is shutting down due to low UPS battery!"`
    
    2.5: DO NOT set up email alerts! (otherwise you get two sets for each event due to system alerting!)
    
    2.6: Add `MAXAGE 25` to the "Auxilary Parameters (upsd.conf)" box (prevents occasional 'connection to UPS lost' errors)
3. Enable the service!
4. Check box to auto-start service.

##### Checking UPS status and changing parameters remotely:
1) Check status of UPS (get all stats):
   ```
   upsc ups@localhost
   ```
2) List commands that can be run from the terminal for a particular UPS:
   ```
   upscmd -u [username] -p [password] -l ups@localhost
   ```
3) Run a command on a UPS:
   ```
   upscmd -u [username] -p [password] ups@localhost command.name.here
   ```

##### Typical commands:
- `test.start.battery.quick`
- `test.start.battery.deep`
- `test.start.battery.stop`
- `beeper.disable`
- `beeper.enable`