hassio-addons / addon-nut

Network UPS Tools - Home Assistant Community Add-ons
https://addons.community
MIT License
192 stars 37 forks source link

Cannot connect from HomeAssistant nor from LAN #374

Closed camedomotic-unofficial closed 3 months ago

camedomotic-unofficial commented 3 months ago

Problem/Motivation

I can't connect to my NUT instance neither from Home Assistant nor from any other laptop on my LAN. If I try to check the connectivity to the port 3493, it seems to be closed, even if the log says NUT is listening.

Expected behavior

  1. Setting up the HA integration to NUT, I would expect it to properly connect to localhost on port 3493.
  2. Trying telnet or nc on port 3493 of my HA server, I would expect to get a Port listening message.

Actual behavior

  1. The integration shows the error "Connection error: Multiple exceptions: [Errno 111] Connect call failed ('::1', 3493, 0, 0), [Errno 111] Connect call failed ('127.0.0.1', 3493)".
  2. I get a "Connection refused" error.

Steps to reproduce

Alternative:

Log

This is my NUT instance log on startup (DEBUG level):

s6-rc: info: service s6rc-oneshot-runner: starting
s6-rc: info: service s6rc-oneshot-runner successfully started
s6-rc: info: service base-addon-banner: starting

-----------------------------------------------------------
 Add-on: Network UPS Tools
 Manage battery backup (UPS) devices
-----------------------------------------------------------
 Add-on version: 0.13.1
 You are running the latest version of this add-on.
 System: Home Assistant OS 12.3  (aarch64 / yellow)
 Home Assistant Core: 2024.7.2
 Home Assistant Supervisor: 2024.06.2
-----------------------------------------------------------
 Please, share the above information when looking for help
 or support in, e.g., GitHub, forums or the Discord chat.
-----------------------------------------------------------
s6-rc: info: service base-addon-banner successfully started
s6-rc: info: service fix-attrs: starting
s6-rc: info: service base-addon-timezone: starting
s6-rc: info: service base-addon-log-level: starting
s6-rc: info: service fix-attrs successfully started
[22:15:10] INFO: Configuring timezone (Europe/Rome)...
Log level is set to DEBUG
s6-rc: info: service base-addon-log-level successfully started
s6-rc: info: service base-addon-timezone successfully started
s6-rc: info: service legacy-cont-init: starting
cont-init: info: running /etc/cont-init.d/nut.sh
[22:15:12] INFO: Setting mode to netserver...
[22:15:12] INFO: Generating /etc/nut/upsd.users...
[22:15:12] INFO: Configuring user: nutty
[22:15:13] DEBUG: Password SHA1: XXXXXXXXXXXXXXX
[22:15:13] DEBUG: Requested API resource: https://api.pwnedpasswords.com/range/DBA9A
[22:15:13] DEBUG: API HTTP Response code: 200
[22:15:13] INFO: Password is NOT in the Have I Been Pwned database! Nice!
[22:15:14] INFO: Configuring Device named xxxups...
[22:15:14] INFO: Starting the UPS drivers...
   0.000000 [D1] Starting UPS: xxxups
Using subdriver: APC HID 0.98
Network UPS Tools - Generic HID driver 0.47 (2.8.0)
USB communication driver (libusb 1.0) 0.43
Network UPS Tools - UPS driver controller 2.8.0
cont-init: info: /etc/cont-init.d/nut.sh exited 0
cont-init: info: running /etc/cont-init.d/nutclient.sh
cont-init: info: /etc/cont-init.d/nutclient.sh exited 0
s6-rc: info: service legacy-cont-init successfully started
s6-rc: info: service legacy-services: starting
services-up: info: copying legacy longrun upsd (no readiness notification)
services-up: info: copying legacy longrun upsmon (no readiness notification)
s6-rc: info: service legacy-services successfully started
[22:15:15] INFO: Starting the UPS information server...
   0.000000 fopen /run/nut/upsd.pid: No such file or directory
   0.000071 Could not find PID file '/run/nut/upsd.pid' to see if previous upsd instance is already running!

   0.000800 [D1] debug level is '1'
   0.001050 listening on 0.0.0.0 port 3493
   0.001753 Connected to UPS [xxxups]: usbhid-ups-xxxups
   0.003327 Running as foreground process, not saving a PID file
[22:15:15] INFO: Starting the UPS monitor and shutdown controller...
   0.000000 fopen /run/nut/upsmon.pid: No such file or directory
   0.000069 Could not find PID file to see if previous upsmon instance is already running!

   0.000482 Using power down flag file /etc/killpower
   0.000733 UPS: xxxups@localhost (primary) (power value 1)
   0.000774 [D1] debug level is '1'
   0.000857 [D1] debug level is '1'
   0.000871 Warning: running as one big root process by request (upsmon -p)
   0.001050 [D1] Saving PID 467 into /run/nut/upsmon.pid
Init SSL without certificate database
   0.005755 [D1] Trying to connect to UPS [xxxups@localhost]
   0.023287 User upsmonmaster@127.0.0.1 logged into UPS [xxxups]
   0.007513 [D1] Logged into UPS xxxups@localhost
{"message":"Event nut.ups_event fired."}Network UPS Tools upsmon 2.8.0
camedomotic-unofficial commented 3 months ago

I noticed that, instead of leaving blank (default value) the Network section of the add-on configuration page, if I set manually the port value to a specific number (e.g. 3493), then the server becomes discoverable and the issue is addressed.

Even if this workaround fixed the issue to me, I would recommend to fix the default port management (when the port number is left to its default, blank, value in the configuration) so that it actually works.

camedomotic-unofficial commented 3 months ago

This fixes the issue:

image
tjorim commented 3 months ago

Note: The host a0d7b954-nut can be used to allow Home Assistant to communicate directly with the addon.

Does this host not work when setting up the HA integration without exposing the port?

sinclairpaul commented 3 months ago

Closing this, it's documented and if you want external access to the addon it is within the UI, which the addon itself cannot influence.

bcutter commented 3 months ago

I'm facing the very same issue. With the slight difference, that setting the network port to 3493 still makes no difference:

grafik

grafik

So... what's wrong with the addon? How to locally check if the addon actually runs on the specified port? --> netstat | grep 3493 on the host (HA OS) gives nothing.

Do I need to open another issue or... can we re-open this one and clarify the situation?

sinclairpaul commented 3 months ago

As per the documentation https://github.com/hassio-addons/addon-nut/blob/main/nut/DOCS.md#home-assistant-community-add-on-network-ups-tools

Note: The host a0d7b954-nut can be used to allow Home Assistant to communicate directly with the addon

So use a0d7b954-nut as the host not localhost

This assumes that the NUT server is running and there are no errors in the logs.

bcutter commented 3 months ago

Thanks for pointing to that important information.

Unfortunately that makes zero difference:

image

The addon is running, latest addon log excerpt:

67013.663674    [D1] mainloop: UPS [eaton_3s] is now connected as FD -1
67015.664853    [D1] mainloop: UPS [eaton_3s] is not currently connected
67015.665073    [D1] mainloop: UPS [eaton_3s] is now connected as FD -1
67017.667154    [D1] mainloop: UPS [eaton_3s] is not currently connected
67017.667376    [D1] mainloop: UPS [eaton_3s] is now connected as FD -1
67018.640692    67018.663924    [D1] mainloop: UPS [eaton_3s] is not currently connected
Poll UPS [eaton_3s@localhost] failed - Driver not connected
67018.664140    [D1] mainloop: UPS [eaton_3s] is now connected as FD -1
67020.664715    [D1] mainloop: UPS [eaton_3s] is not currently connected
67020.665189    [D1] mainloop: UPS [eaton_3s] is now connected as FD -1

I have no idea what's wrong with the addon. Help highly appreciated. I'm trying for hours over several months to finally get this running.

Tested different usernames/passwords (maybe the password is not allowed to have certain special characters?), tried completely without authentication (leave front door open option), tested with network port configured/not configured, tried "localhost", "a0d7b954-nut", "a0d7b954_nut", ... NOTHING works. Debug log needed? I could not spot any suspicious in there.