I3 battery indicator issue

I have installed endeavouros with i3 window manager today. The problem is the text beside the battery indicator in the below taskbar is going back and forth between 98% and 99% even though the charger is plugged in. When i remove the charger it shows notification ’ your battery is fully charged '. Also i plugged my charger when the battery percentage was 96% that time also it shows notification battery is fully charged.

First, you have to find out what scripts and applications are used to determine the status of the battery. If you are using i3wm, try to look inside this directory: ~/.config/i3/scripts

Is there a script called battery.sh or something? If there is, post the contents of the script.

You can also look at ~/.config/i3blocks.conf under the [battery] section. That should tell you which scripts/commands are used to display the battery info on the bar.

Below text is from the i3blocks.conf file where it shows about battery

Battery indicator

[battery]
command=~/.config/i3/scripts/battery2

for alternative battery script change to battery1

change this to battery-pinebook-pro if you are running on pinebook-pro

As per above file i am providing here the contents of battery2
#!/usr/bin/env python3

Copyright (C) 2016 James Murphy

Licensed under the GPL version 2 only

A battery indicator blocklet script for i3blocks

from subprocess import check_output
import os
import re

config = dict(os.environ)
status = check_output([β€˜acpi’], universal_newlines=True)

if not status:
# stands for no battery found
color = config.get(β€œcolor_10”, β€œred”)
fulltext = β€œ\uf00d \uf240”.format(color)
percentleft = 100
else:
# if there is more than one battery in one laptop, the percentage left is
# available for each battery separately, although state and remaining
# time for overall block is shown in the status of the first battery
batteries = status.split(β€œ\n”)
state_batteries=
commasplitstatus_batteries=
percentleft_batteries=
time = β€œβ€
for battery in batteries:
if battery!=β€˜β€™:
state_batteries.append(battery.split(β€œ: β€œ)[1].split(”, β€œ)[0])
commasplitstatus = battery.split(”, β€œ)
if not time:
time = commasplitstatus[-1].strip()
# check if it matches a time
time = re.match(r”(\d+):(\d+)”, time)
if time:
time = β€œ:”.join(time.groups())
timeleft = " ({})".format(time)
else:
timeleft = β€œβ€

        p = int(commasplitstatus[1].rstrip("%\n"))
        if p>0:
            percentleft_batteries.append(p)
        commasplitstatus_batteries.append(commasplitstatus)
state = state_batteries[0]
commasplitstatus = commasplitstatus_batteries[0]
if percentleft_batteries:
    percentleft = int(sum(percentleft_batteries)/len(percentleft_batteries))
else:
    percentleft = 0

# stands for charging
color = config.get("color_charging", "yellow")
FA_LIGHTNING = "<span color='{}'><span font='FontAwesome'>\uf0e7</span></span>".format(color)

# stands for plugged in
FA_PLUG = "<span font='FontAwesome'>\uf1e6</span>"

# stands for using battery
FA_BATTERY = "<span font='FontAwesome'>\uf240</span>"

# stands for unknown status of battery
FA_QUESTION = "<span font='FontAwesome'>\uf128</span>"


if state == "Discharging":
    fulltext = FA_BATTERY + " "
elif state == "Full":
    fulltext = FA_PLUG + " "
    timeleft = ""
elif state == "Unknown":
    fulltext = FA_QUESTION + " " + FA_BATTERY + " "
    timeleft = ""
else:
    fulltext = FA_LIGHTNING + " " + FA_PLUG + " "

def color(percent):
    if percent < 10:
        # exit code 33 will turn background red
        return config.get("color_10", "#FFFFFF")
    if percent < 20:
        return config.get("color_20", "#FF3300")
    if percent < 30:
        return config.get("color_30", "#FF6600")
    if percent < 40:
        return config.get("color_40", "#FF9900")
    if percent < 50:
        return config.get("color_50", "#FFCC00")
    if percent < 60:
        return config.get("color_60", "#FFFF00")
    if percent < 70:
        return config.get("color_70", "#FFFF33")
    if percent < 80:
        return config.get("color_80", "#FFFF66")
    return config.get("color_full", "#FFFFFF")

form =  '<span color="{}">{}%</span>'
fulltext += form.format(color(percentleft), percentleft)
#fulltext += timeleft

print(fulltext)
print(fulltext)
if percentleft < 10:
exit(33)

Please use proper formatting. Place all code snippets in between ```

1 Like

The script uses acpi to read the battery status. Charge the battery up to 99%. Then, in your terminal run:

$ acpi

After that, unplug your battery. Run the same command again.

What is the output of the command for each case?

Command run when plugged in :
[althaf@budgie ~]$ acpi
Battery 0: Charging, 98%, charging at zero rate - will never fully charge.

command run when unplugged :
[althaf@budgie ~]$ acpi
Battery 0: Discharging, 98%, discharging at zero rate - will never fully discharge.

How old is the battery? What does acpi -iV say in both cases?

Battery is only one year old

results of acpi -iv
When charging :
[althaf@budgie ~]$ acpi -iV
Battery 0: Charging, 90%, charging at zero rate - will never fully charge.
Battery 0: design capacity 2876 mAh, last full capacity 2876 mAh = 100%
Adapter 0: on-line
Thermal 0: ok, 49.0 degrees C
Thermal 0: trip point 0 switches to mode critical at temperature 255.0 degrees C
Thermal 0: trip point 1 switches to mode hot at temperature 100.0 degrees C
Thermal 0: trip point 2 switches to mode passive at temperature 98.0 degrees C
Cooling 0: Processor 0 of 3
Cooling 1: Processor 0 of 3
Cooling 2: Processor 0 of 3
Cooling 3: Processor 0 of 3
Cooling 4: Processor 0 of 3
Cooling 5: Processor 0 of 3
Cooling 6: Processor 0 of 3
Cooling 7: Processor 0 of 3
Cooling 8: Processor 0 of 3
Cooling 9: Processor 0 of 3
Cooling 10: Processor 0 of 3
Cooling 11: Processor 0 of 3
Cooling 12: Processor 0 of 3
Cooling 13: Processor 0 of 3
Cooling 14: Processor 0 of 3
Cooling 15: Processor 0 of 3

When not charging : [althaf@budgie ~]$ acpi -iV
Battery 0: Discharging, 90%, discharging at zero rate - will never fully discharge.
Battery 0: design capacity 2967 mAh, last full capacity 2967 mAh = 100%
Adapter 0: off-line
Thermal 0: ok, 48.0 degrees C
Thermal 0: trip point 0 switches to mode critical at temperature 255.0 degrees C
Thermal 0: trip point 1 switches to mode hot at temperature 100.0 degrees C
Thermal 0: trip point 2 switches to mode passive at temperature 98.0 degrees C
Cooling 0: Processor 0 of 3
Cooling 1: Processor 0 of 3
Cooling 2: Processor 0 of 3
Cooling 3: Processor 0 of 3
Cooling 4: Processor 0 of 3
Cooling 5: Processor 0 of 3
Cooling 6: Processor 0 of 3
Cooling 7: Processor 0 of 3
Cooling 8: Processor 0 of 3
Cooling 9: Processor 0 of 3
Cooling 10: Processor 0 of 3
Cooling 11: Processor 0 of 3
Cooling 12: Processor 0 of 3
Cooling 13: Processor 0 of 3
Cooling 14: Processor 0 of 3
Cooling 15: Processor 0 of 3

I can only think of two possibilities here:

  1. Hardware issue. In other words, something might be wrong with the battery. This is quite easy to check, actually. Just boot into a live environment and test the battery. If the same behavior is observed even in a live environment, it is probably the battery.
  2. Software issue. You may have set the charging threshold to a number below 100. To verify this, run:
$ cat /sys/class/power_supply/BAT0

The command should return a number.