Managing an APC UPS with NUT on the host machine without passthrough to VM

Hi I just purchased an APC1500 and have it set up to my Mac mini connected by USB.

Full config is Mac mini running UTM HAOS as a VM with the UPS connected to a USB port on the Host machine and not passed through to the guest (as I want the robust integration with energy saver UPS config in the MacOS).

Question is how do I config the nut addon to see the host APCUPS connected through USB? I think with all the advice here that I can connect to the Nut addon once I can get it fully up and running, but having a lot of config issues with itā€¦does anyone else have this setup and can share a redacted config?

You can run NUT server on MacOS using homebrew. Itā€™s a little more advanced in that you have to manually edit the config files, start the service, and permit incoming network connections. With that setup, you donā€™t need the add-on; the HA integration can connect directly to the service running on the Macā€™s IP.

1 Like

Boy @peterxian do I think that Iā€™m down a slight rabbit holeā€¦I followed mass majority of all config have everything seeming to be operational on the Mac side, then try to connect the nut integration in HA and it retries the broadcast message in terminal as root@computername and says that itā€™s disconnected from the tty port (and of course the integrations fails at same time)! I feel like Iā€™m so closeā€¦almost wonder if starting homebrew nut instance with sudo command and the folder message that paths have been re-assigned to root may have something to do with this and that I should copy off my conf files and remove nut and manually remove the folder paths and start back overā€¦thoughts?

It also appears that the NUT driver takes away the integrated UPS backup driver for the MacOS integrated UPS tools built into the OS directly, does that normally happen?

The ā€œbrew servicesā€ command only uses ā€œsudoā€ to determine whether the service should be launched every reboot (before you login). Without ā€œsudoā€ the service should start, which is useful for testing, but if you reboot you have to login for the service to be started.

peter@macmini ~ % brew services ā€”help
**Usage: brew** **services** [subcommand]
Manage background services with macOS' **launchctl**(1) daemon manager or Linux's
**systemctl**(1) service manager.

If **sudo** is passed, operate on **/Library/LaunchDaemons** or
**/usr/lib/systemd/system** (started at boot). Otherwise, operate on
**~/Library/LaunchAgents** or **~/.config/systemd/user** (started at login).

I believe the only file you have to edit is /opt/homebrew/etc/nut/ups.conf (create an entry for your UPS) and possibly nut.conf to make sure MODE=netserver. You can create a username and password in upsd.users but if you donā€™t, then anyone can connect.

peter@macmini ~$ cat /opt/homebrew/etc/nut/ups.conf
...
[cyberpower_1500]
driver = usbhid-ups
pollinterval = 15
pollfreq = 15
port = auto

After starting the service, you can test whether it is working using the upsc command (in this example no username or password are required):

peter@macmini ~$ upsc cyberpower_1500@localhost
Init SSL without certificate database
battery.charge: 100
battery.charge.low: 10
battery.charge.warning: 20
battery.mfr.date: CPS
battery.runtime: 7025
battery.runtime.low: 300
battery.type: PbAcid
battery.voltage: 27.6
battery.voltage.nominal: 24
device.mfr: CPS
device.model: CP1500PFCLCDa
device.serial: CXXJV2006322
device.type: ups
driver.name: usbhid-ups
...

Assuming that works, and you are permitting external connections (which iirc you have to approve in the system settings app), you can just setup a home assistant NUT integration using the IP of your Mac. Leave the username and password blank unless you defined them in the upsd.users config file.

In this example, NUT checks the USB port every 15 seconds for status. Itā€™s possible/likely this conflicts with the OS trying to do the same thing. But you can duplicate the auto-shutdown functionality using the NUT monitoring agent, upsmon if you want the Mac to shutdown when battery remaining gets too low.

1 Like

So close, I at first was getting connection refused for upsc command - then driver not connected, have majority of everything else set up exact to yours - what is this permitting external connections in system settings?

Output from upsd:
Network UPS Tools upsd 2.8.2
fopen /opt/homebrew/var/state/ups/upsd.pid: No such file or directory
Could not find PID file ā€˜/opt/homebrew/var/state/ups/upsd.pidā€™ to see if previous upsd instance is already running!
/opt/homebrew/etc/nut/upsd.conf is world readable
setuptcp: bound to localhost as IPXX.XX.XX.XX but there seem to be further (ignored) addresses resolved for this name
listening on localhost port 3493
/opt/homebrew/var/state/ups is world readable
Canā€™t connect to UPS [ups_name] (usbhid-ups-ups_name): Permission denied
Found 1 UPS defined in ups.conf
/opt/homebrew/etc/nut/upsd.users is world readable

Output from upsc:
upsc ups_name@localhost
Error: Driver not connected

Broadcast Message from [email protected]
(no tty) at 23:16 PDTā€¦

UPS ups_name@localhost is unavailable

Output of upsdrvctl:
sudo upsdrvctl start
Network UPS Tools - UPS driver controller 2.8.2
Network UPS Tools - Generic HID driver 0.53 (2.8.2)
USB communication driver (libusb 1.0) 0.47
Duplicate driver instance detected (PID file /opt/homebrew/var/state/ups/usbhid-ups-ups_name.pid exists)! Terminating other driver!
kill: No such process
writepid: fopen /opt/homebrew/var/state/ups/usbhid-ups-ups_name.pid: Permission denied
Canā€™t claim USB device [XXXX:XXXX]@0/0/0: Access denied (insufficient permissions)
upsnotify: failed to notify about state 4: no notification tech defined, will not spam more about it
Driver failed to start (exit status=1)

The driver might be failing to connect because either the USB port is in use by another application (possibly the system energy saver) or another upsd process is still running (or both). Stop upsd by running brew services stop nut and for good measure check the process list for nut still running: ps -ef | grep ups. If you still see upsd as a running process (a process ID on the 2nd column) you can terminate it with sudo kill [pid]. Also make sure the UPS monitoring checkbox in system energy saver is unchecked for now, then start upsd with brew services start nut If you make a change to the config files while it is running, restart upsd by running brew services restart nut or run stop and start as separate commands.

1 Like

What if you use the hosts real IP address instead of localhost?

I use a similar setup (NUT installed on the Debian host, VMWare NUT integration with host IP address).

That still wouldnā€™t explain the

Which looks like there is an issue is with the driver on the hostā€¦

1 Like

Iā€™ll give both of these suggestions a try in a day or so, theyā€™re both really good and after isolating each one inseparate attempts to correct the issues - Iā€™m thinking that the solution may be a combination of both! Thanks @peterxian & @aceindy!

I tried getting these 2 approaches in place and Iā€™m getting the same errors still, hereā€™s my redacted files:
nut.conf:
MODE=netserver

ups.conf:
[ups_name]
driver = usbhid-ups
port = auto

upsd.conf:
LISTEN IP_ADDRESS 3493

upsd.users:
N/A (included but empty)

upsmon.conf:
MONITOR ups_name@IP_ADDRESS 1 primary

I then killed all services but these 2 still existed post any attempt:
0 38296 1 0 4:04PM ?? 0:00.08 /usr/libexec/ioupsd
502 38569 34199 0 4:06PM ttys000 0:00.00 grep ups

I had attempted to turn off the ups interface in energy saver but I only have access to when it turns off on % or time remaining settings but not a universal use/donā€™t use UPS setting wonder if this is hidden somewhere else in Sonoma? Any advice @peterxian or @aceindy is appreciated!

@peterxian I know that the grep is the terminal command looking for ups instancesā€¦Iā€™m not seeing a choice to turn off the ups feature in the OS as you had suggested, just to add more excitement I moved to Sequoia a couple of days ago and this may add a twist into the settings options as well. What do you think is my best option forward to fully kill all instances and are my configs about missing any key entries?