NUT with CyberPower UPS



  • I’m running some tests with NUT and CyberPower UPS with the usbhid driver. I’m assuming NUT is not something I can just install and forget. My problem is NUT is sending the shutoff command milliseconds before the UPS powers off - not leaving enough time before the firewall can actually shut down. Also, when the UPS powers off (it’s running the firewall, PoE switch, NVR), everything shuts off. But then the UPS immediately powers back on as if it found some extra juice in the batteries. This causes everything to turn back on before losing power again a little bit later.
    My question is are their specific settings I can put in NUT settings or is this something wrong with the UPS itself. I see the documentation available but am unclear on how to properly use it.
    Any insight is appreciated.



  • I had the same issue with a CyberPower Value600E UPS. After frustrating hours of trying to send delay signals to the UPS that never worked I gave up and bought a APC UPS. Maybe its just something specific to this line of UPS models or all CyberPower UPS.

    During the time I was waiting for my APC UPS to arrive I did a GREP on the UPS battery levels and scripted a soft shutdown in CRON. Maybe this can help you.



  • just to add a little more if I remember correctly. I could delay the UPS powering off using one of the variables related to delay load power (can't remember the actual variable). But could not get the UPS to recycle power properly when wall outlet power returned.



  • @pppd
    Can you point me in the right direction in scripting something like this in pfSense? I'm not sure what to utilize, or how, in order to automate something like this in pfSense.



  • The issue is NUT is hard coded to do the shutdown on critical instead of low power, unlike APCUPSD you cannot configure a battery remaining %. One guy solved this by editing the source code but he never shared his work.

    Ironically a new windows NUT client been worked on (is independent to the NUT project itself) does support using a configured battery % as a trigger. But this is only good for clients not so much pfSense itself, unless you written a windows script to login to pfSense and send a shutdown command.

    I have just reported this on the NUT github issue page.



  • I have an APS UPS but I think this would work with any UPS connected by local USB.

    I chose 35% to leave some battery in case the power flickers on and off. I also use NUT as my network master, my NAS (synology) goes into safe mode at the same battery level.

    Screen Shot 2020-10-14 at 10.56.30.png



  • @jwj said in NUT with CyberPower UPS:

    I have an APS UPS but I think this would work with any UPS connected by local USB.

    I chose 35% to leave some battery in case the power flickers on and off. I also use NUT as my network master, my NAS (synology) goes into safe mode at the same battery level.

    Screen Shot 2020-10-14 at 10.56.30.png

    Hmm, have you confirmed this changes the behaviour, if yes then thank you this is great. but does raise questions about the guy who claimed the issue was that it was using critical instead of low battery value.

    According to the NUT docs these are recognised but in ups.conf not the driver. Not sure if pfSense uses the NUT client (for local ups), I think it just uses upsmon daemon?



  • Yes, tested. I pull the plug and when my UPS hits 35% (reported by NUT) my pfsense box shuts down. I've had it setup like this for a year+. Lots and lots of power outages without issue.

    What happens when power is restored is dependent on you UPS and the BIOS settings of your pfsense HW.

    If you can, give it a try with some bigger percentage so you don't have to wait ages. Report back here what happens.



  • I have checked as well, it does work, this is good news.

    For the benefit of others, you can test without pulling the battery, make the change as jwl described, and then click on UPS status, the value of 'battery.charge.low' does indeed change.

    I am going to edit the github issue report to ask them to fix the documentation.

    jwl I changed mine to this (the poll line was already there, to poll much more frequently), default is 10% low and 20% warning on my ups.

    pollfreq=5 -i 5
    ignorelb
    override.battery.charge.low = 20
    override.battery.charge.warning = 50
    


  • @chrcoluk said in NUT with CyberPower UPS:

    I have checked as well, it does work, this is good news.

    For the benefit of others, you can test without pulling the battery, make the change as jwl described, and then click on UPS status, the value of 'battery.charge.low' does indeed change.

    I am going to edit the github issue report to ask them to fix the documentation.

    Good news and good work!

    I can't claim any real skill on my part configuring it that way. There was some google foo involved, long enough ago that I don't recall any specifics. Maybe as a byproduct of looking for the config to get it to use the monuser that is hardwired into Synology NASs...

    I'll put that here in case it's useful to someone (change the IPs to match your setup). This is security malpractice on Synology's part!

    Screen Shot 2020-10-14 at 11.58.24.png

    Screen Shot 2020-10-14 at 12.03.03.png



  • What about the issue (could just be related to CyberPower) that when the UPS shuts off due to running out of battery (all plugged in items power down) then immediately the UPS powers back on as if it decided "no wait, I do have a LITTLE more battery left. THis causes everything to turn BACK on only to be cut from power when the UPS ACTUALLY drains it's battery. How can I avoid this?



  • @bhjitsense That's going to vary from one UPS to another. Some UPS's can be told to shut off when some battery level is reached. Of course you will have to configured things to safe/power off at a level higher than that. Some UPS's will not power on (provide power to attached devices) after power is restored until the battery level reaches some value.

    I do recall that NUT can tell a UPS to power down with some delay as the last thing before the service is stopped during a shutdown of the host machine. My recollection is fuzzy, google searching is required to nail down the specifics... I would have to pull the plug on mine to see what happens, I don't exactly remember if the UPS shuts off or just runs the battery down. Kids are home and in online class, not going to happen today...

    Some threads here on that subject. Not going to wade into that today either...



  • @bhjitsense look for one of the variables in the UPS settings displayed on the UPS service in pfSense. Run your finger down the list and look for something related to load.off.delay. (it may not be exactly this as my memory is not great nowadays). If I remember correctly it defaults to 59 seconds which Cyberpower UPS doesn't recognize as a valid number so ignores it and thus the cause of your UPS suddenly powering off. Instead set it to something like 300 (5 mins) by adding an override statement in the extra settings sections of the UPS settings which is recognized by your UPS as a valid setting. So your extra settings should look like:

    override.load.off.delay=300

    save and restart the service. Test your new settings by going to shell and entering:

    upsmon -c FSD

    this will simulate a low battery situation and call the shutdown scripts. If your settings are correct your pfSense should have enough time to shutdown gracefully. If the UPS powers off before pfSense completes its shutdown then recheck your settings. If your pfsense shutdown ungracefully you might need to first boot into single user mode and fsck -F just to do a check on your volume before proceeding further.

    Now, if your load on the UPS is greater than lets say 30% you might want to adjust the time when the UPS begins its shutdown by adding another line to the extra settings as such:

    override.battery.low=50
    ignorelb

    The ignorelb is required if you want the above settings to take effect. Again I am not sure of my variable names so you will need to check the actual variable names listed in the UPS service on pfsense.

    Like I said, the native apcsd daemon on pfsense is just much easier to use than NUT thus the reason I decided to purchase APC for my pfsense box. The Cyberpower has native drivers for Windows and Linux so I repurposed it to those boxes. You might want to consider the same.



  • @bhjitsense for your issue related to your UPS suddenly powering back up while still on battery I never solved that issue thus the reason I switched to APC.

    I believe one of the settings controls that function but I never figured it out and since my systems are in production there is the possibility in future that something else will screw up and corrupt the pfsense box. My advice to you is that NUT and cyberpower don't get along well and since there are no native FreeBSD drivers I switched to APC. APC works exactly as predicted thanks to its native driver.

    I wrote a shell script to overcome this failing and put it in CRON running every minute. I can't remember the command but I think it was upscmd -l which will list out the current settings of the UPS including battery levels. Pipe that into GREP and IF battery level < 50 call shutdown (upsmon -c FSD).



  • @bhjitsense correction: IF < 50 then poweroff



  • @bhjitsense if you really want to script the shutdown yourself something as simple as the following in CRON every minute will do the job:

    upsc | grep 'OB' && poweroff

    the above will gracefully shut down pfsense as soon as the system goes on battery.

    if you want to shutdown on low battery

    upsc | grep 'LB' && poweroff

    but you will need to shut off NUT while still being able to query the UPS status so that you don't find yourself in competition with NUT issuing the shutdown command itself



  • @bhjitsense correction:

    upsc <upsname> | grep 'OB' && shutdown

    if you want to shutdown at a certain level then:

    (( $(upsc <upsname> | grep 'battery.charge' | grep -oe '([0-9.]*)') < 60 )) && shutdown

    will shutdown your firewall when battery level drops below 60%



  • I really appreciate your help @pppd! I can't believe I didn't realize I could just get the CRON package to make stuff like this.
    I've considered switching to APC. Now that I know it has a native driver, i'll probably be pulling that trigger.



  • @bhjitsense smart move with getting APC for pfsense (or freebsd for that matter). NUT is great and has hundreds of options but it needs to be correctly configured to work properly. Repurpose your cyberpower to Linux or Windows boxes which have native drivers.



  • @bhjitsense I notice a wrong bracket in the command...correction:

    (( $(upsc <upsname> | grep 'battery.charge' | grep -oe '([0-9.]*') < 60 )) && shutdown

    where <upsname> is the name of the UPS you entered in the UPS settings.



  • All this seems a bit overkill? jwj has a non hacky solution already with adding the flags to the driver section in the UI which he has personally tested to work.

    My cyberpower UPS auto shuts itself down to protect its battery according to the documentation so shouldnt need a command to tell it to turn off, or have I misunderstood something?



  • @chrcoluk the solution is a stop/gap measure to deal with the cyberpower UPS suddenly coming back online while still on battery.

    If you know all the commands of the cyberpower UPS please publish them so we don't have to use these hack methods.



  • I dont know any :(

    Since none of my devices auto power on when power is restored I think I will be ok luckily.


Log in to reply