This is an issue that I've had on Acer, Apple, and Asus notebooks over the years. I guess this isn't limited to manufacturers that start with the letter "A".
The problem is with the upower service not polling the battery often enough. If you've ever tried to compare your battery status with multiple tools, you will have likely seen discrepancies in the amount of reported power remaining and/or charging status. Unfortunately this isn't something that can be fixed with a quick trip to "Settings" or "dconf Editor", but you can work around this with a script that forces upower to refresh.
First, let's get your battery name. In Terminal, run this command:
upower -e
This should give you something like this:
/org/freedesktop/UPower/devices/line_power_AC
/org/freedesktop/UPower/devices/battery_BAT0
/org/freedesktop/UPower/devices/DisplayDevice
With this, we can see that my battery is aptly named battery_BAT0. I can manually force upower to update its status information with this busctl command:
busctl call --system org.freedesktop.UPower /org/freedesktop/UPower/devices/battery_BAT0 org.freedesktop.UPower.Device Refresh
Note: There is no output when running this command in Terminal, though your status icons might update if you have recently (dis)connected power.
To have this run at regular intervals to keep the battery icon and play a system notification sound within a semi-reasonable amount of time, wrap the busctl call from earlier into a shell script:
#!/bin/bash
while sleep 15; do
busctl call --system org.freedesktop.UPower /org/freedesktop/UPower/devices/battery_BAT0 org.freedesktop.UPower.Device Refresh
done
Be sure to replace battery_BAT0 with your actual battery name, and change 15 to an interval that you would be satisfied with. I've been running this for a couple of years now and have not seen any performance impact from the script on a 4th-gen Intel Core i5, so your Ryzen 7 should have no qualms with it, either.
To have this run in the background from startup, open "Startup Applications", click "Add", and select the script. Do not forget to make the script executable first, though:
chmod +x poke-upower.sh
Note: You'll probably want a better file name.
This is more of a hack than a complete solution, but it does work for numerous releases of Ubuntu Desktop. I have not yet found the root cause of this issue, though, and none of the Lenovo or Dell devices that I've used have ever shown this behaviour.
Hope this helps
dmesgfor any possible hint at what is delaying the expected actions. – sancho.s ReinstateMonicaCellio Feb 22 '21 at 10:12