diff --git a/.config/Scripts/i3-battery-monitor b/.config/Scripts/i3-battery-monitor new file mode 100755 index 0000000..a0c17b2 --- /dev/null +++ b/.config/Scripts/i3-battery-monitor @@ -0,0 +1,61 @@ +#!/bin/sh + +# low and critical battery level. +# at low battery level, notification will be sent to inform the user. +# at critcal battery level, urgent notification will be sent and if user does not plugin within the given Backup time (mentioned below), system will perform critical level action +# range = 0 - 100 +# default: low=10, critcal=5 +low=20 +critical=15 + +# the time (in seconds) given to user to backup or plugin power, after critical level is reached +# default: backup=20 +backupTime=25 + +# time (in seconds) after which the script is called again to check battery level +# default: sleepTime=30 +sleepTime=60 + +# Select the critical Action which will be performed when battery is critical +# Values: suspend, poweroff, hibernate, hybrid-sleep +# default: criticalAction="suspend" +criticalAction="suspend" + +# variable (boolean) to check if user is notified or not. Used within the script. DO NOT CHANGE or script might malfunction +# default: notified=0 +notified=0 + +while true ; do + # get battery-level(0-100%) and state(discharging/charging) + battery=$(cat /sys/class/power_supply/BAT0/capacity) + state=$(cat /sys/class/power_supply/BAT0/status) + echo $battery + echo $state + echo $notified + if [ "$state" = "Discharging" ] ; then + # if battery discharging and below low level then send notification + if [ $battery -gt $critical ] && [ $battery -le $low ] && [ $notified -eq 0 ] ; then + notify-send 'Battery Low' 'Plugin to Recharge' --icon=/home/hate/.icons/battery-low.png + let notified=1 + # if battery discharging and below critical level then send notification and wait for user action + elif [ $battery -le $critical ] ; then + tempTime=$(( $backupTime*1000 )) + notify-send "Turning off system in $backupTime sec(s)" 'Backup Data or Plugin to Recharge' --icon=battery-low --urgency=critical --expire-time=$tempTime + sleep $backupTime + tempState=$(cat /sys/class/power_supply/BAT0/status) + # if battery still discharging, then perform critical action + if [ "$tempState" = "Discharging" ] ; then + executionCommand="systemctl $criticalAction" + eval $executionCommand + # if battery is now pluged in, then do not perform critical action + else + let notified=0 + fi + fi + else + let notified=0 + fi + sleep $sleepTime +done + +exit 0 diff --git a/.config/i3/config b/.config/i3/config index 829035d..54907f9 100644 --- a/.config/i3/config +++ b/.config/i3/config @@ -74,6 +74,8 @@ exec --no-startup-id twmnd & #exec --no-startup-id mpdscribble --no-daemon & #Wpgtk exec --no-startup-id ~/.config/wpg/wp_init.sh +#Battery notify +exec --no-startup-id ~/.config/Scripts/i3-battery-monitor #Conky #exec --no-startup-id conky -d -c ~/.config/conky/conkybg & #Picom diff --git a/.config/polybar/config b/.config/polybar/config index 395e888..74daaac 100644 --- a/.config/polybar/config +++ b/.config/polybar/config @@ -222,7 +222,7 @@ label-background = ${colors.color9} [module/temperature] type = internal/temperature thermal-zone = 6 -hwmon-path = /sys/devices/platform/coretemp.0/hwmon/hwmon6/temp1_input +hwmon-path = /sys/devices/platform/coretemp.0/hwmon/hwmon5/temp1_input warn-temperature = 65 format =