Getting Battery full-charged notification on Manjaro Gnome

Battery low notification works fine. How do I get full-charged notification on Manjaro Gnome?

I don't think gnome has this by default. It should be pretty easy to script though.

Here is an example script:

#!/usr/bin/sh
while true
do
    export DISPLAY=:0.0
    battery_percent=$(cat /sys/class/power_supply/BAT*/capacity)
    if $(grep -q "Charged" /sys/class/power_supply/BAT*/status); then
            notify-send -i "/usr/share/icons/Adwaita/256x256/status/battery-full-charged.png" "Battery full." "Level: ${battery_percent}% "
    fi
    sleep 300 # (5 minutes)
done

Make that executable and put it into your autosrtart. You can adjust the value of sleep to make it check the state more often, and change the path to the icon to use a better one.

2 Likes

Thanks a lot.

@Chrysostomus , Can I make run this script after charging state? It isn't needed during battery discharging state.

Read the script. It checks the state every 5 minutes and should not give notifications if charging. Does it trigger also when charging?

I understand script, this script checks every 5 minutes, but this script doesn't work on me, because after battery percent become 100%, /sys/class/power_supply/BAT*/status - Charging state is changed to Discharging state, battery is plugged in though.

Okay, we can instead check if the capacity is greater than 99%?

You need to look for Discharging state of course.

I changed code as following. Is it correct?

#!/bin/bash
while true
do
    export DISPLAY=:0.0
    battery_percent=$(cat /sys/class/power_supply/BAT*/capacity)
    if  [$battery_percent -gt 99]; then
    	if $(grep -q "Discharging" /sys/class/power_supply/BAT*/status); then
            notify-send -i "~/.local/share/gnome-shell/extensions/dynamic_battery@exalm/icons/elementary-full-charged-symbolic.svg" "Battery full." "Level: ${battery_percent}% "
            sleep 1h       
    	fi
    fi
    sleep 60
done

I would omit the check for state if checking also for level. Like this:

#!/bin/bash
while true
do
    export DISPLAY=:0.0
    battery_percent=$(cat /sys/class/power_supply/BAT*/capacity)
    if  [$battery_percent -gt 99]; then
         notify-send -i "~/.local/share/gnome-shell/extensions/dynamic_battery@exalm/icons/elementary-full-charged-symbolic.svg" "Battery full." "Level: ${battery_percent}% "
    fi
    sleep 60
done

Honestly, I would change this to 94%.

I've noticed that on my laptop the hardware bounces the charger/battery anytime that the battery hits 100% to run off the battery until it hits 95% then charge again. Seems to be a hardware feature to exercise the battery. It might be similiar on his hardware. A secondary check to make sure the laptop is plugged in might be worthwhile.

#!/bin/bash
while true
do
export DISPLAY=:0.0
battery_percent=$(cat /sys/class/power_supply/BAT*/capacity)
ac_available=$(cat /sys/class/AC*/online)
if  [$battery_percent -gt 99 && $ac_available -eq 1]; then
     notify-send -i "~/.local/share/gnome-shell/extensions/dynamic_battery@exalm/icons/elementary-full-charged-symbolic.svg" "Battery full." "Level: ${battery_percent}% 
fi
sleep 60
done
2 Likes

Good idea! Fun coding with you people! :slight_smile:

I don't have this: /sys/class/AC*/online
Edit: but /sys/class/power_supply/AC*/online works .
Thaks a lot for all your answers.

Awesome. Thanks a lot. In my system the status comes as "FULL". I just made that change and it works fine!

Forum kindly sponsored by