NUT add-on configuraton problem

OK, I’ve spent many hours wrestling with this, and I’m sure I’m just missing something fundamental.
I’m having trouble monitoring my UPS after upgrading from an older installation. I’ve installed the NUT add-on and integration, and everything works fine for a while. Sensors report data, but then the connection is lost and my log shows errors about “stale” data.

I am running HA on a Raspberry Pi 3B, with a Cyberpower CP1000PFCLCD attached via a USB cable.

What worked before:
I was running HA on the same Pi with Hassbian; up through HA 0-102-3.
My server setup in /etc/nut/ups.conf:

[cyberpower1]
        driver = usbhid-ups
        port = auto
        desc = "CyberPower CP1000PFCLCD"
        pollinterval = 15

and in /etc/nut/upsd.conf:
LISTEN 127.0.0.1 3493
MAXAGE 25

and in /etc/nut/upsd.users:
‘[admin]’
’ password = admin1’
’ actions = SET’
’ instcmds = ALL’
‘[upsmon_local]’
’ password = local1’
’ upsmon master’

and in /etc/nut/nut.conf:
‘MODE=standalone’

My client setup in /etc/nut/upsmon.conf:
‘DEADTIME 25’
‘FINALDELAY 20’
‘MONITOR cyberpower1@localhost 1 upsmon_local local1 master’

This all worked for years with no problems.

Now I have upgraded from scratch with HASS-OS etc. to where I now have running on the same hardware:
Home Assistant OS 5.13
Supervisor 2021-04-0
core 2021.4.4
Network UPS Tools add-on 0.6.2

My configuration for the NUT add-on is:

Options

users:
  - username: admin
    password: xxx
    instcmds:
      - all
    actions: 
      - set
devices:
  - name: CyberPower1
    driver: usbhid-ups
    port: auto
    config: []
mode: netserver
shutdown_host: 'false'
upsd_maxage: 25
upsd_pollinterval: 15
upsmon_deadtime: 15
upsmon_pollfreq: 5
upsmon_finaldelay: 20

Network
3493

When I start the add-on, the log shows:
[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.6.2
 You are running the latest version of this add-on.
 System: Home Assistant OS 5.13  (aarch64 / raspberrypi3-64)
 Home Assistant Core: 2021.4.4
 Home Assistant Supervisor: 2021.04.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... 
[14:28:43] INFO: Setting mode to netserver...
[14:28:43] INFO: Generating /etc/nut/upsd.users...
[14:28:43] INFO: Configuring user: admin
[14:28:44] INFO: Password is NOT in the Have I Been Pwned database! Nice!
[14:28:44] INFO: Configuring Device named CyberPower1...
[14:28:45] INFO: Starting the UPS drivers...
Using subdriver: CyberPower HID 0.4
Network UPS Tools - Generic HID driver 0.41 (2.7.4)
USB communication driver 0.33
Network UPS Tools - UPS driver controller 2.7.4
[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.
[14:28:45] INFO: Starting the UPS information server...
   0.000000	fopen /var/run/nut/upsd.pid: No such file or directory
   0.002598	listening on 0.0.0.0 port 3493
   0.004456	Connected to UPS [CyberPower1]: usbhid-ups-CyberPower1
[14:28:46] INFO: Starting the UPS monitor and shutdown controller...
   0.000000	fopen /var/run/nut/upsmon.pid: No such file or directory
   0.001118	Using power down flag file /etc/killpower
   0.001809	UPS: CyberPower1@localhost (master) (power value 1)
   0.002153	debug level is '1'
   0.002209	Warning: running as one big root process by request (upsmon -p)
   0.007045	Init SSL without certificate database
   0.059998	Trying to connect to UPS [CyberPower1@localhost]
   0.564963	User [email protected] logged into UPS [CyberPower1]
   0.066834	Logged into UPS CyberPower1@localhost


so all looks good, and my UPS sensors all work just fine.

But after a while (sometimes minutes, sometimes an hour or so), the UPS is disconnected and the NUT log shows:

794.703949 Data for UPS [CyberPower1] is stale - check driver
795.201832 Poll UPS [CyberPower1@localhost] failed - Data stale
{“message”: “Event nut.ups_event fired.”}Network UPS Tools upsmon 2.7.4
800.204371 Poll UPS [CyberPower1@localhost] failed - Data stale
805.205435 Poll UPS [CyberPower1@localhost] failed - Data stale
810.206516 Poll UPS [CyberPower1@localhost] failed - Data stale
815.207432 Poll UPS [CyberPower1@localhost] failed - Data stale
820.208219 Poll UPS [CyberPower1@localhost] failed - Data stale
825.209106 Poll UPS [CyberPower1@localhost] failed - Data stale
830.209986 Poll UPS [CyberPower1@localhost] failed - Data stale
835.210801 Poll UPS [CyberPower1@localhost] failed - Data stale
840.211556 Poll UPS [CyberPower1@localhost] failed - Data stale
845.212471 Poll UPS [CyberPower1@localhost] failed - Data stale
850.213402 Poll UPS [CyberPower1@localhost] failed - Data stale
855.214360 Poll UPS [CyberPower1@localhost] failed - Data stale
860.221365 Poll UPS [CyberPower1@localhost] failed - Data stale

I’ve been hunting all over the place, and found out this problem seems to be common with many CyberPower products, which reset the USB interface if a driver has not connected for 20 seconds; and NUT is set to consider an UPS “stale” after 15 seconds by default.

The solutions I’ve seen posted all seem to point to possibly some combination of values for maxage, pollinterval, deadtime, and pollfreq; but so far I’ve gotten nowhere. Some combinations seem to fail within several minutes, others take a half hour or so, but all fail. I’ve also seen suggestions of setting a cron job to restart the driver, but that seems like a duct-tape fix.

Has anybody run across this problem (and solved it)?

Thanks!

Please edit your post as per item 11 here.

Hi! Did you solved it? I’ve same problem and already changed deadtime and maxage parameter with no success…

When stale data message appears, restart NUT docker is the only way to get working again

I got this problem starting with hassio 2021.xx but no problem with previous versions 0.118.xx

Sounds like USB subsystem driver…
Hermes

Hermes - I think I may have solved it. At least I’ve gone a couple of days with no disconnects or stale data messages; fingers crossed. In the interim I’ve been trying to figure out how to format posts so I don’t get spanked, but no joy on that front. Anyway, the solution had possibly two parts. First, here’s my configuration, note the pollinterval line (could not find this documented anywhere in regard to the add-on):

In the Network UPS Tools add-on config,
under “Options”:

users:
  - username: admin
    password: <my password>
    instcmds:
      - all
    actions:
      - set
devices:
  - name: CyberPower1
    driver: usbhid-ups
    port: auto
    config:
      - pollinterval = 15
mode: netserver
shutdown_host: 'false'
upsd_maxage: 25
upsmon_deadtime: 25

and under "Network":
3493

This alone might have fixed the problem, but I noticed another oddity that I addressed; it may or may not matter. In the UI Configuration screen, under Devices, I found two different entries for “Cyberpower1”.
The first had the correct manufacturer and model info, but the second just had these listed as unknown.

To get rid of this second entry, I had to dig through the .storage folder, and in core.device_registry I
found two sections for the name “Cyberpower1”, one with “null” entries for manufacturer and model. I deleted that whole section from the file.

Then in core.entity_registry I found sections for two extraneous duplicate sensors sensor.cyberpower1_status_2 and sensor.cyberpower1_status_data_2, and I deleted these as well.

Finally, I did a full “reboot host” from the Supervisor System panel.

As I said, so far, so good, at least for a couple of days. Hope this helps!

1 Like

Chris,
thanks for your answer and sorry for my late one :slight_smile:
I had some trouble, but now I’ve configured the suggested parameters

I already used upsd_maxage and upsmon_deadtime with no useful results
BUT pollinterval = 15 was new for me so I’ve configured right now

let’s cross fingers!!

I’ll give a feedback in few days (if it works), or before if it crashes again :wink:

qh

Where can I find the nut config? Is it a yaml file?

No, although I’ve added comments in my YAML file for the UPS to help me remember the settings. Personal quirk. The settings are in the configuration section of the NUT add-on.

I’m running an older core (core-2021.8.8) at the moment; so might not look exactly the same on current core, but try
Supervisor ==> Installed add-ons (“Network UPS Tools”) ==> Options tab

December 2022 - and I’m finally restoring the NUT add-on to my Home Assistant system. For the benefit of other CyberPower UPS users, the following is my NUT add-on configuration YAML:

- config: []
  driver: usbhid-ups
  name: cyberpower1500
  port: auto
  mode: netserver
  upsd_maxage: 25
  upsd_pollinterval: 15
  upsd_pollonly: "enabled"

Now waiting the prescribed 20 or 30 minutes to see if this finally resolves the stale data issue. THANK YOU for all the information in this thread and on Github.

Over an hour later - nope. :frowning:

[14:30:06] INFO: Starting the UPS information server...
   0.000000	fopen /run/nut/upsd.pid: No such file or directory
   0.000413	listening on 0.0.0.0 port 3493
   0.000721	Connected to UPS [cyberpower1500]: usbhid-ups-cyberpower1500
[14:30:06] INFO: Starting the UPS monitor and shutdown controller...
   0.000000	fopen /run/nut/upsmon.pid: No such file or directory
   0.000406	Using power down flag file /etc/killpower
   0.000716	UPS: cyberpower1500@localhost (master) (power value 1)
   0.000831	debug level is '1'
   0.000853	Warning: running as one big root process by request (upsmon -p)
   0.001290	Init SSL without certificate database
   0.004325	Trying to connect to UPS [cyberpower1500@localhost]
   0.517955	User [email protected] logged into UPS [cyberpower1500]
   0.006360	Logged into UPS cyberpower1500@localhost
8341.368234	Data for UPS [cyberpower1500] is stale - check driver
8345.856941	Poll UPS [cyberpower1500@localhost] failed - Data stale
{"message":"Event nut.ups_event fired."}Network UPS Tools upsmon 2.7.4
8350.858162	Poll UPS [cyberpower1500@localhost] failed - Data stale
8355.858794	Poll UPS [cyberpower1500@localhost] failed - Data stale
8360.859357	Poll UPS [cyberpower1500@localhost] failed - Data stale

added the YAML line

  pollonly: "enabled"

and restarted - let’s see what happens . . . a day later, and pollonly: enabled made it work properly! :grinning:

Nope, the NUT add-on seems to have a problem, causing the NUT integration to fail.

{"message":"Event nut.ups_event fired."}Network UPS Tools upsmon 2.7.4
165754.694779	Trying to connect to UPS [cyberpower1500@localhost]
165884.862506	UPS [cyberpower1500@localhost]: connect failed: Connection failure: Cannot assign requested address

Well, fudge. :frowning:

1 Like

Don’t know if it will help at all, but here’s my setup that is working:

I am running HA on a Raspberry Pi 3B, with a Cyberpower CP1000PFCLCD attached via a USB cable.
Add-on version: 0.11.0
System: Home Assistant OS 9.3 (aarch64 / raspberrypi3-64)
Home Assistant Core: 2022.11.2
Home Assistant Supervisor: 2022.11.2

While I tend to do pretty much everything in YAML, this aspect is all done through the UI.

Add-on Configuration page:

Network UPS Tools
Options
devices

- name: CyberPower1
  driver: usbhid-ups
  port: auto
  config:
    - pollinterval = 15

mode
X netserver
shutdown_host (ON)
upsd_maxage
25
upsmon_deadtime
25
users

- username: ******
  password: ******
  instcmds:
    - all
  actions:
    - set

Network
3493 3493/tcp

Integration configuration page:
Scan Interval (seconds) 60

1 Like

I eventually found an HA automation here, where someone checks the status of the constantly-failing NUT add-on, and restarts it. Something in NUT keeps killing the server, and restarting it after a minute restores the integration.

  alias: Auto-restart NUT add-on
  description: Auto-restart NUT add-on
  trigger:
  - platform: state
    entity_id:
    - sensor.cyberpower1500_status_2
    to: unavailable
    for:
      hours: 0
      minutes: 1
      seconds: 0
  condition: []
  action:
  - service: hassio.addon_restart
    data:
      addon: a0d7b954_nut
  mode: single
1 Like

Thank you for this - I had changed my HA setup to be in a VirtualBox on a PC and was having the “stale” problem, but this seems to have fixed it!

Thnx for this solution. I also have this problem on a RPI4.
I made the automation, i hope that it helps.
I will let you know !

@FredTheFrog Thank you so much! I was just about to write this and I thought “I’ll google this and see if anyone else has the same issue” and found your automation which saved all the typing but updating the entity_id :slight_smile:

@mljenkins Definitely NOT my automation, all credit and praise goes to the original author buried in another thread somewhere. They saved my bacon, and I’m just sharing their wonderful work-around.