# Configure UPS (Eaton 5E) in Debian bullseye

This is the configuration for my `bananapi` with Debian `bullseye` and an `Eaton 5E` UPS connected via USB cable.

## Configure USB

First, connect the UPS to the USB port and check if it is recognized by the system.
```bash
lsusb
```

The output should be something like this:
```text
Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 001 Device 003: ID 0463:ffff MGE UPS Systems UPS
Bus 001 Device 002: ID 1a40:0101 Terminus Technology Inc. Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
````

Note the `0463:ffff` part, this is the `vendor:product` ID of the UPS.

## Install packages

```bash
apt install nut
```

## Configure NUT

Edit the file `/etc/nut/nut.conf` and add the following lines:
```text
MODE=standalone
```

Edit the file `/etc/nut/ups.conf` and add the following lines:
```text
xretry = 5
pollinterval = 5

[eaton5e]
    driver = usbhid-ups
    port = auto
    desc = "Eaton 5E"
    vendorid = 0463
    pollfreq = 30
```

Edit the file `/etc/nut/upsd.conf` and add the following lines:
```text
LISTEN 127.0.0.1 3493
LISTEN 192.168.1.2 3493
```
Note, that I have added the IP address of my `bananapi` to the `LISTEN` line.
This is because I want to monitor the UPS from my `home assistant` instance running on a different machine.

Edit the file `/etc/nut/upsd.users` and add the following lines:
```text
[username]
  password = SuperSecretPassword
  actions = SET
  instcmds = ALL
  upsmon master
```

You should edit the `username` and `password` to your liking.

## Start NUT

```bash
sudo upsdrvctl start
sudo upsd -c reload  # in case you have changed the config () 
```

```bash
systemctl restart nut-server
systemctl enable nut-server   # run the service at boot
```


## Check UPS status
One way to check the UPS status is to use the `upsc` command.
```bash
sudo upsc eaton5e
```

The output should be something like this:
```text
Init SSL without certificate database
battery.charge: 53
battery.runtime: 428
battery.type: PbAc
device.mfr: EATON
device.model: 5E 850i
device.type: ups
driver.name: usbhid-ups
driver.parameter.pollfreq: 30
driver.parameter.pollinterval: 5
driver.parameter.port: auto
driver.parameter.synchronous: no
driver.parameter.vendorid: 0463
driver.version: 2.7.4
driver.version.data: MGE HID 1.40
driver.version.internal: 0.41
input.voltage: 240.0
outlet.1.status: on
outlet.desc: Main Outlet
outlet.id: 1
outlet.switchable: no
output.frequency: 49.9
output.frequency.nominal: 50
output.voltage: 236.0
output.voltage.nominal: 230
ups.beeper.status: enabled
ups.delay.shutdown: 20
ups.firmware: 03.08.0018
ups.load: 31
ups.mfr: EATON
ups.model: 5E 850i
ups.power.nominal: 850
ups.productid: ffff
ups.start.battery: yes
ups.status: OL
ups.timer.shutdown: -1
ups.vendorid: 0463
```

## Configure Home Assistant

There is a `nut` integration for `home assistant` that can be used to monitor the UPS.
You can simply find it and configure it via the `integrations` page in `home assistant`.
You need to provide the IP address of the machine running `nut` and the `username` and `password` you have configured in the `upsd.users` file.

## References
* https://mic22.medium.com/basic-nut-configuration-for-green-cell-ups-and-home-assistant-integration-e08affcc54f