HEX
Server: Apache/2.4.63 (Unix)
System: Linux TOMS-220NAS 4.4.302+ #86009 SMP Wed Nov 26 18:19:17 CST 2025 x86_64
User: flavio87 (1026)
PHP: 8.3.27
Disabled: NONE
Upload Files
File: //usr/syno/bin/synoups_battery_notify.sh
#!/bin/sh

. /usr/syno/bin/synoupscommon

if [ "$UpsMode" == "usb" -o "$UpsMode" == "snmp" ];then
	UPSC_CMD="$BIN_FILE_UPSC ups@localhost"
else
	SERVER_IP=`synogetkeyvalue $SYNOUPS_CONF upsslave_server`
	UPSC_CMD="$BIN_FILE_UPSC ups@$SERVER_IP"
fi

RUNTIME_CNT=`$UPSC_CMD | grep -c "battery.runtime"`
if [ $RUNTIME_CNT -ge 1 ];then
	RUNTIME_RESULT=`$UPSC_CMD | grep "battery.runtime" | head -1 | cut -d":" -f2`
	RUNTIME_RESULT=`expr ${RUNTIME_RESULT/\.*} / 60`
	if [ $RUNTIME_RESULT -gt 1 ];then
		TIME_UNIT_STRING="dsm:common:time_minutes"
	else
		TIME_UNIT_STRING="dsm:common:time_minute"
	fi
	$BIN_SYNONOTIFY UPSOnBattery "{\"%BATTERY_STRING%\":\"dsm:ups:battery_notification\", \"%REMAIN_TIME%\":\"${RUNTIME_RESULT}\", \"%REMAIN_TIME_UNIT%\":\"${TIME_UNIT_STRING}\"}"
else
	$BIN_SYNONOTIFY UPSOnBattery "{\"%BATTERY_STRING%\":\" \"}"
fi