[SOLVED] Nut Server access from remote client

Hello all,
I have installed a Nut Server on Home Assistant using the “Network UPS Tool” addon. The UPS is connected with USB to the host (Raspberry Pi 4 with Home Assistant OS 0.118.3). The configuration of the add-on works fine and the UPS (netserver mode) is monitored correctly in HA.
I would like to access to this NUT server from remote NUT client (NAS Synology or Jeedom Nut plugin). But i still face a “connexion refused”. Thanks for your help.

Note: For specific need, the UPS MUST be on the Raspberry and not the NAS.

Note: Previously, this UPS was connected to a Nut Server on Debian and i remember i had to play with “LISTEN” option of the upsd.conf for having it available from remote clients.

Here is my configuration

configuration.yaml

# UPS
sensor:
  - platform: nut
    name: "APC Backup"
    host: a0d7b954-nut
    username: ekinox
    password: password
    resources:
      - battery.charge
      - battery.runtime
      - ups.load
      - ups.status

Network UPS Tool configuration:

users:
  - username: ekinox
    password: NCqsCbsECelMplD2AT
    instcmds:
      - all
    upsmon: master
    actions: []
devices:
  - name: apcups
    driver: usbhid-ups
    port: auto
    config:
      - vendorid = 051d*
mode: netserver
shutdown_host: 'false'
list_usb_devices: true

Addon log:

[s6-init] making user provided files available at /var/run/s6/etc...exited 0.
[s6-init] ensuring user provided files have correct perms...exited 0.
[fix-attrs.d] applying ownership & permissions fixes...
[fix-attrs.d] nut: applying... 
[fix-attrs.d] nut: exited 0.
[fix-attrs.d] done.
[cont-init.d] executing container initialization scripts...
[cont-init.d] 00-banner.sh: executing... 
-----------------------------------------------------------
 Add-on: Network UPS Tools
 Manage battery backup (UPS) devices
-----------------------------------------------------------
 Add-on version: 0.3.1
 You are running the latest version of this add-on.
 System: HassOS 4.16  (aarch64 / raspberrypi4-64)
 Home Assistant Core: 0.118.3
 Home Assistant Supervisor: 2020.11.0
-----------------------------------------------------------
 Please, share the above information when looking for help
 or support in, e.g., GitHub, forums or the Discord chat.
-----------------------------------------------------------
[cont-init.d] 00-banner.sh: exited 0.
[cont-init.d] 01-log-level.sh: executing... 
[cont-init.d] 01-log-level.sh: exited 0.
[cont-init.d] nut.sh: executing... 
[15:49:14] INFO: Setting mode to netserver...
[15:49:14] INFO: Connected USB devices:
Bus 001 Device 004: ID 051d:0002 American Power Conversion Uninterruptible Power Supply
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 005: ID 1cf1:0030 Dresden Elektronik 
Bus 001 Device 002: ID 2109:3431 VIA Labs, Inc. Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
[15:49:15] INFO: Generating /etc/nut/upsd.users...
[15:49:15] INFO: Configuring user: ekinox
[15:49:16] INFO: Password is NOT in the Have I Been Pwned database! Nice!
[15:49:18] INFO: Configuring Device named apcups...
[15:49:18] INFO: Starting the UPS drivers...
Network UPS Tools - UPS driver controller 2.7.4
Network UPS Tools - Generic HID driver 0.41 (2.7.4)
Using subdriver: APC HID 0.96
USB communication driver 0.33
[cont-init.d] nut.sh: exited 0.
[cont-init.d] nutclient.sh: executing... 
[cont-init.d] nutclient.sh: exited 0.
[cont-init.d] done.
[services.d] starting services
[services.d] done.
[15:49:28] INFO: Starting the UPS information server...
Network UPS Tools upsd 2.7.4
   0.000000	fopen /var/run/nut/upsd.pid: No such file or directory
   0.001029	listening on 0.0.0.0 port 3493
   0.002213	Connected to UPS [apcups]: usbhid-ups-apcups
   0.011846	/etc/nut/upsd.users is world readable
[15:49:29] INFO: Starting the UPS monitor and shutdown controller...
Network UPS Tools upsmon 2.7.4
   0.000000	fopen /var/run/upsmon.pid: No such file or directory
   0.000848	Using power down flag file /etc/killpower
   0.001354	UPS: apcups@localhost (master) (power value 1)
   0.001813	debug level is '1'
   0.002056	Warning: running as one big root process by request (upsmon -p)
   0.003186	Trying to connect to UPS [apcups@localhost]
   0.504884	User [email protected] logged into UPS [apcups]
   0.004466	Logged into UPS apcups@localhost
2 Likes

Hello guys, any suggestions for me ? Thank ouy.

No answer or help during 2 months. Let me know what’s wrong with my message in order to improve the next one…

In case that might help someone else, here is the solution.
The port 3493 (default NUT port) has to be exposed in the add-on:

  • Supervisor / Network UPS Tools / Configuration
  • In the Network part (bottom of the screen), set 3493 to the “host”.
    This way the Nut server can be accessed from external machine using the IP of the host (IP of Home Assistant on your network) and default Nut port.
19 Likes

thanks guy! You are not answered because many do not know it themselves. common story here

For my Synology to connect as a client, I had to make the user ‘monuser’ and the name ‘ups’ … Synology expects that when choosing the “Network UPS Type” as “Synology UPS Server” . If I set the Network part to 3493, the add-on fails to start for me so I just leave it disabled and everything works. I have my UnRAID server connecting as a client to this as well.

Anyone try to access from a WD My Cloud EX2 Ultra? I enter my HA IP Address but it just says it can not find the server. there is no way to enter the port number either.

1 Like

Hi Ekinox09,

I faced your same problem.
I am trying to connect to NUT on my Home Assistant, running on a Raspberry Pi 3B+.
I installed the “Network UPS Tools” add-on version 0.9.0 to Home Assistant.
I am using WinNUT version 2.0.7722.30975 downloaded from here: GitHub - gawindx/WinNUT-Client: This is a NUT windows client for monitoring your ups hooked up to your favorite linux server.

The program always returns me the error “the host refused the connection”.

This reminded me of something I read about add-ons: they run in a some sort of virtual machine, so they are isolated from the rest of the system, and I thought, also from the network.

If you go on the add-on configuration options, you should see a “Network” options group, and an empty field with the “Disabled” label inside. Just type there the standard port: 3493, save, reload the add-on, and voilà! You are able to connect from an external host!!!

This worked for me, I hope it can be useful to you too.

4 Likes

I had my UPS connected to another Raspberry Pi and the daemon was only listening on localhost.
I had to modify /etc/nut/upsd.conf to allow it to listen on all interfaces (LISTEN 0.0.0.0 3493). Since you have to set up authentication anyway and I use iptables to allow access between home assistant and the PI, I feel fine with it.

I followed this article on the Raspberry Pi to start with: How to Monitor UPS with Raspberry Pi - How to Raspberry

1 Like

Thank you! I was getting crazy trying to configure NUT.

Well this just fixed my issue! Thanks for this post!

Thanks a lot for posting the answer. It fixed my problem.

I have a question about this: My Homeasasaistant runs on a MiniPC.

If I configure NUT, it will fail if I enter its IP address and port.

Maybe the Mini PC does not recognize the occupied USB port from the UPS?

What do I have to do?

Greeting

Luz

Thank you for this, I was trying to connect an app to the server without success. This solved it.

This was the solution for me!
You can check from a terminal that running this command returns nothing before setting the port in the add-on configuration.

nestat -nltp | grep 3493

After setting it in the config, it will return 2 lines showing that it is listening on ipv4 and ipv6. I finally could add the integration successfully!

Just a big thanks for this post… obvious when I thought about it - but lots of googling and playing around and this one was the key ‘moment’ for me :slight_smile:

I had a Synology NAS as the ups master (APC ups plugged into it via USB port) and another Synology NAS slaving from it, and three Pi’s with NUT installed also slaving from the master NAS.

Problem was when I wanted to add a couple more PI’s, the NAS doesn’t support more than 5 clients (arbitrary thing in Synology implementation) - so time to move the master.

Moved it to a PI, created a ups called ‘ups’ with user ‘monuser’ and password ‘secret’ (as per this post) and hey presto the Synology’s all see it as another Synology UPS server, and the rest of the sensible NUT/Pi/HA Nut Integration world can be configured as slaves easily to that as well. Problem solved.

I was doing the ‘right’ thing and setting up a proper name for the UPS and a proper username and password combination - and failing to get the Synology’s to recognise it… silly me…

1 Like