diff --git a/emhttp/languages/en_US/helptext.txt b/emhttp/languages/en_US/helptext.txt index 3227592d3..7c04a7569 100644 --- a/emhttp/languages/en_US/helptext.txt +++ b/emhttp/languages/en_US/helptext.txt @@ -1958,6 +1958,10 @@ Enter the *device* which corresponds to your situation, only applicable when *UP + **modbus** - /dev/tty** :end +:apc_ups_override_ups_capacity_help: +If your device doesn't natively report Nominal Power (`NOMPOWER`) from `apcupsd`, but does report the Load Percentage (`LOADPCT`), you can manually define the UPS capacity rating in Watts (W) (this is the 'real power' value in Watts (W), not the 'apparent power' in Volt Amps (VA), and should be detailed on your UPS manual or product listing) and the plugin will dynamically calculate a virtual Nominal Power estimate (`≈`) by comparing the Override UPS Capacity (W) and the current Load Percentage. It is only an estimate, as it doesn't factor in things like the UPS' efficiency. +:end + :apc_battery_level_help: If during a power failure, the remaining battery percentage (as reported by the UPS) is below or equal to *Battery level*, apcupsd will initiate a system shutdown. :end diff --git a/emhttp/plugins/dynamix.apcupsd/UPSsettings.page b/emhttp/plugins/dynamix.apcupsd/UPSsettings.page index cdde2cf31..025e0cdf1 100644 --- a/emhttp/plugins/dynamix.apcupsd/UPSsettings.page +++ b/emhttp/plugins/dynamix.apcupsd/UPSsettings.page @@ -91,6 +91,11 @@ _(Device)_: :apc_ups_device_help: +_(Override UPS Capacity (Watts))_: +: + +:apc_ups_override_ups_capacity_help: + _(Battery level to initiate shutdown)_ (%): : diff --git a/emhttp/plugins/dynamix.apcupsd/default.cfg b/emhttp/plugins/dynamix.apcupsd/default.cfg index 8ad7bb8c1..5ea9819a9 100644 --- a/emhttp/plugins/dynamix.apcupsd/default.cfg +++ b/emhttp/plugins/dynamix.apcupsd/default.cfg @@ -3,6 +3,7 @@ UPSCABLE="usb" CUSTOMUPSCABLE="" UPSTYPE="usb" DEVICE="" +OVERRIDE_UPS_CAPACITY="" BATTERYLEVEL="10" MINUTES="10" TIMEOUT="0" diff --git a/emhttp/plugins/dynamix.apcupsd/include/UPSstatus.php b/emhttp/plugins/dynamix.apcupsd/include/UPSstatus.php index 381f70969..507131898 100644 --- a/emhttp/plugins/dynamix.apcupsd/include/UPSstatus.php +++ b/emhttp/plugins/dynamix.apcupsd/include/UPSstatus.php @@ -18,6 +18,10 @@ $docroot ??= ($_SERVER['DOCUMENT_ROOT'] ?: '/usr/local/emhttp'); $_SERVER['REQUEST_URI'] = 'settings'; require_once "$docroot/webGui/include/Translations.php"; +require_once "$docroot/webGui/include/Helpers.php"; +$cfg = parse_plugin_cfg('dynamix.apcupsd'); +$overrideUpsCapacity = (int) htmlspecialchars($cfg['OVERRIDE_UPS_CAPACITY'] ?: 0); + $state = [ 'ONLINE' => _('Online'), 'SLAVE' => '('._('slave').')', @@ -34,7 +38,8 @@ $state = [ $red = "class='red-text'"; $green = "class='green-text'"; $orange = "class='orange-text'"; -$status = array_fill(0,7,"-"); +$defaultCell = "-"; +$status = array_fill(0,7,$defaultCell); $result = []; $level = $_POST['level'] ?: 10; $runtime = $_POST['runtime'] ?: 5; @@ -89,6 +94,11 @@ if (file_exists("/var/run/apcupsd.pid")) { if ($power && isset($load)) $status[5] = ($load<90 ? "" : "").round($power*$load/100)." W (".$status[5].")"; elseif (isset($load)) $status[5] = ($load<90 ? "" : "").$status[5].""; $status[6] = isset($output) ? ((!$volt || ($minv<$output && $output<$maxv) ? "" : "").$status[6].(isset($freq) ? " ~ $freq Hz" : "")."") : $status[6]; + + if ($status[4] == $defaultCell && $overrideUpsCapacity > 0 && isset($load) && $load > 0) { + $nominalPower = round($load * 0.01 * $overrideUpsCapacity); + $status[4] = ($nominalPower > 0 ? "" : "") . "≈ $nominalPower W"; + } } if (empty($rows)) $result[] = ""._('No information available').""; diff --git a/emhttp/plugins/dynamix/nchan/ups_status b/emhttp/plugins/dynamix/nchan/ups_status index 37f414b43..9090e91a2 100755 --- a/emhttp/plugins/dynamix/nchan/ups_status +++ b/emhttp/plugins/dynamix/nchan/ups_status @@ -69,12 +69,14 @@ while (true) { update_translation($locale_init); } unset($echo,$rows,$power,$load,$freq,$output,$volt); - $echo = array_fill(0,7,"-"); + $defaultCell = "-"; + $echo = array_fill(0,7,$defaultCell); if (file_exists("/var/run/apcupsd.pid")) { // get battery-level and runtime settings $cfg = parse_plugin_cfg('dynamix.apcupsd'); $level = $cfg['BATTERYLEVEL'] ?: 10; $runtime = $cfg['MINUTES'] ?: 5; + $overrideUpsCapacity = (int) htmlspecialchars($cfg['OVERRIDE_UPS_CAPACITY'] ?: 0); exec("/sbin/apcaccess -u 2>/dev/null", $rows); foreach ($rows as $row) { [$key, $val] = array_map('trim', explode(':', $row, 2)); @@ -120,6 +122,11 @@ while (true) { if (isset($power) && isset($load)) $echo[5] = ($load<90 ? "" : "").round($power*$load/100)." W (".$echo[5].")"; elseif (isset($load)) $echo[5] = ($load<90 ? "" : "").$echo[5].""; $echo[6] = isset($output) ? ((empty($volt) || ($minv<$output && $output<$maxv) ? "" : "").$echo[6].(isset($freq) ? " ~ $freq Hz" : "")."") : $echo[6]; + + if ($echo[4] == $defaultCell && $overrideUpsCapacity > 0 && isset($load) && $load > 0) { + $nominalPower = round($load * 0.01 * $overrideUpsCapacity); + $echo[4] = ($nominalPower > 0 ? "" : "") . "≈ $nominalPower W"; + } } $echo = json_encode($echo); $md5_new = md5($echo,true);