Netgate Discussion Forum
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Search
    • Register
    • Login

    NUT Package change

    Scheduled Pinned Locked Moved pfSense Packages
    2 Posts 2 Posters 1.7k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • L
      LostInIgnorance
      last edited by

      Just looking for someone to help change the seconds of runtime to hours, minutes, and seconds.  Anyone know how to do this?

      1 Reply Last reply Reply Quote 0
      • T
        tweek
        last edited by

        You'd have to modify the status_nut.php file in /usr/local/www to take the array value $ups['battery.runtime'], convert it to hours/minutes/seconds format, then print it. I'm no PHP expert and I'm sure there are probably more elegant ways to do it but I just made the following changes:

        1. Add a new function to the /* functions */ section at the top of the file that converts seconds to an array in hms format:

        function secs2hms($secs) {
        	if ($secs<0) return false;
        	$m = (int)($secs / 60); $s = $secs % 60;
        	$h = (int)($m / 60); $m = $m % 60;
        	return array($h, "h ", $m, "m ", $s, "s ");
        }
        

        2.  Find the following line near the end of the file:

        tblrow('Runtime Remaining:', $ups['battery.runtime'], ' seconds');
        

        …and change it to the following:

        tblrow('Runtime Remaining:', implode(secs2hms($ups['battery.runtime'])));
        

        The result looks something like this:

        If anyone else has a better way to do this feel free to comment.

        1 Reply Last reply Reply Quote 0
        • First post
          Last post
        Copyright 2025 Rubicon Communications LLC (Netgate). All rights reserved.