tshakalekholoane / bat Goto Github PK
View Code? Open in Web Editor NEWBattery management utility for Linux laptops.
Home Page: https://tshaka.dev/x/bat
License: MIT License
Battery management utility for Linux laptops.
Home Page: https://tshaka.dev/x/bat
License: MIT License
The charging seems to not stop at the intended threshold despite correct output from the program (I did not receive an error, like on an older laptop that probably just does not support the feature)
I am using KDE, and I am not really sure if it hibernates or suspends when I close the lid (the settings only have one option: "sleep"). I am also judging only by bat -c
and the display in in the KDE System Tray, maybe this is just a display issue.
OS: Fedora 35 KDE Linux x86_64
Host: VivoBook Flip 14 (J412U)
Kernel: 5.14.9-200.fc34.x86_64
systemctl 248
0.8.3 (Latest)
What I did:
bat -t 65
bat -p
bat -t
>> 65
what I've tried after looking at #3
test -f /etc/systemd/system/bat.service && echo "TRUE"
returns nothing
test -f /sys/class/power_supply/BAT?/charge_control_end_threshold && echo "TRUE"
returns TRUE
systemctl status bat.service
returns Unit bat.service could not be found.
systemctl status bat-sleep.service
returns:
bat-sleep.service - Persist the battery charging threshold after sleep
Loaded: loaded (/etc/systemd/system/bat-sleep.service; enabled; vendor preset: disabled)
Active: inactive (dead)
Oct 05 15:25:31 fedora systemd[1]: Finished Persist the battery charging threshold after sleep.
Oct 05 15:57:43 fedora systemd[1]: Starting Persist the battery charging threshold after sleep...
Oct 05 15:57:43 fedora systemd[1]: bat-sleep.service: Deactivated successfully.
Oct 05 15:57:43 fedora systemd[1]: Finished Persist the battery charging threshold after sleep.
Oct 05 15:59:14 fedora systemd[1]: Starting Persist the battery charging threshold after sleep...
Oct 05 15:59:14 fedora systemd[1]: bat-sleep.service: Deactivated successfully.
Oct 05 15:59:14 fedora systemd[1]: Finished Persist the battery charging threshold after sleep.
Oct 05 16:02:51 fedora systemd[1]: Starting Persist the battery charging threshold after sleep...
Oct 05 16:02:51 fedora systemd[1]: bat-sleep.service: Deactivated successfully.
Oct 05 16:02:51 fedora systemd[1]: Finished Persist the battery charging threshold after sleep.
charging should stop at the threshold both when the lid is closed and when the device is running.
Both with closed lid or running system, the charging continues beyond the set limit. Shutdown and restart also did not have an effect on this. bat -t
still reports the threshold I set correctly after restart.
I am clueless when it comes to systemd but judging by the output above it seems that
issue: 目前本人用thinkpad t15g gen1 移动工作站,以后可能换dell precision,请贵编以后加强下dell
For example,
OS: debian
Host: ZenBook UX425EA_UX425EA 1.0
Kernel: 5.13.8-1-MANJARO
0.12 (Latest)
No response
No response
No response
Originally posted by igor-frolikov July 25, 2021
bat 0.7
works fine after restart and return from suspend, but fails after return from hibernate. Resumes working fine after restart.
I tried install from github prebuilt images and from aur via pamac - no any difference.
OS: Manjaro Linux [x86_64]
Host: VivoBook_ASUSLaptop X513IA_M513IA 1.0
Kernel: 5.10.52-1-MANJARO
Packages: 1277 (pacman)[stable]
Shell: bash 5.1.8
DE: KDE Plasma 5.22.3
WM: KWin (X11)
CPU: AMD Ryzen 5 4500U with Radeon Graphics (6) @ 2.375GHz
GPU: AMD ATI Renoir
Memory: 1720MiB / 15484MiB (11%)
Disk (/): 12GB / 100GB (12%)
Battery: 90% [Not charging]
PS.
Thank you very much for your efforts!
Hello! First of all, nice tiny package!
I want to issue something:
When i run bat -t 70
, it asks for my root password but authentication fails every time.
If i then run sudo bat -t 70
, no issue and setting is correctly set.
I run sudo bat -p
multiple times but the threshold value at every restart is back at 100.
What can i do to make it persistent?
I'm using elementaryOS:
catta@catta-pc:~$ uname -a
Linux catta-pc 5.4.0-70-generic #78~18.04.1-Ubuntu SMP Sat Mar 20 14:10:07 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
Hi,
This app is working nicely on an Asus M15 laptop running Fedora 34.
I have set the upper charge threshold at 60% and am wondering at what point charging will resume. One battery manager uses a low 30% figure for resuming charging and another uses 58%. Is there a way to adjust the resume charging level using bat?
BTW, the Fedora charging indicator correctly shows "Not Charging" when battery is above 60% charge.
Thanks.
Create convenience targets to install and reinstall the application where the latter removes the systemd unit files before pulling the latest changes by running bat reset
if the application already exists.
The former should pull the changes i.e., git pull --rebase
, build the application, and install it to /usr/local/bin
.
See the following discussion for details : #73 (comment).
Is your feature request related to a problem? Please describe.
Currently, the project relies on the Bash shell for executing certain commands. While Bash is a powerful and versatile shell, it may not be available or the default shell on all systems. To ensure cross-platform compatibility and accessibility for a wider range of users, replacing Bash with the system's default POSIX-compliant shell, typically found at /bin/sh
should be considered.
Describe the solution you'd like
Modify the systemd unit template to use the expanded battery variable path and hardcode the the shell path. See the following discussion for more details #65 (comment).
Contributions
Contributions and suggestions on how to implement this change are welcome. If you have experience with shell scripting and cross-platform compatibility, please feel free to provide your insights and expertise.
Charge threshold persistence not working after sleep
OS: Ubuntu 23.10 (mantic)
Host: Asus TUF A15 FA506IH
Kernel: 6.5.0-13-generic
0.14 (Latest)
The persisted threshold should work
The charge threshold is not working at all unless set again
After running sudo bat -p
the threshold value after restart is back at 100.
I checked a related issue #5. My version is greater than 244 you mentioned in there.
> systemctl --version
systemd 245 (245.4-4ubuntu3.11)
+PAM +AUDIT +SELINUX +IMA +APPARMOR +SMACK +SYSVINIT +UTMP +LIBCRYPTSETUP +GCRYPT +GNUTLS +ACL +XZ +LZ4 +SECCOMP +BLKID +ELFUTILS +KMOD +IDN2 -IDN +PCRE2 default-hierarchy=hybrid
When I look at the generated file I see that there is a question mark after the BAT (BAT?) instead of it saying 0 (BAT0) and the location of bash is not correct (/usr/bin/bash instead of /bin/bash):
> more /etc/systemd/system/bat-boot.service
[Unit]
Description=Persist the battery charging threshold after boot
After=multi-user.target
StartLimitBurst=0
[Service]
Type=oneshot
Restart=on-failure
ExecStart=/usr/bin/bash -c 'echo 60 > /sys/class/power_supply/BAT?/charge_control_end_threshold'
[Install]
WantedBy=multi-user.target
Th following file works for me if I run sudo systemctl restart bat-boot.service
:
[Unit]
Description=Persist the battery charging threshold after boot
After=multi-user.target
StartLimitBurst=0
[Service]
Type=oneshot
Restart=on-failure
ExecStart=/bin/bash -c 'echo 60 > /sys/class/power_supply/BAT0/charge_control_end_threshold'
[Install]
WantedBy=multi-user.target
Hi
I tested this tool on ASUS ROG GL552-VW and this message printed while setting the threshold:
$ sudo ./bat -t 80
This program is most likely not compatible with your system. See
https://github.com/leveson/bat#disclaimer.
Other commands like -c
or -s
work correctly.
I have ubuntu 20.10 and here is the output of uname -a
:
Linux mojighahar 5.8.0-55-generic #62-Ubuntu SMP Tue Jun 1 08:21:18 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
Please inform me if any other data required for clearing this issue. (output of lshw
, ...)
When I execute the command below it returns "Authentication failure.":
./bat --threshold 60
The problem happens using root or sudo.
Not working. After connect charger battery charging.
┌──(root㉿kali-[/sys/class/power_supply]
└─# ls
ACAD BAT1
┌──(root㉿kali-[/sys/class/power_supply]
└─# ls -l
загалом 0
lrwxrwxrwx 1 root root 0 чер 25 16:08 ACAD -> ../../devices/LNXSYSTM:00/LNXSYBUS:00/ACPI0003:00/power_supply/ACAD
lrwxrwxrwx 1 root root 0 чер 25 16:06 BAT1 -> ../../devices/LNXSYSTM:00/LNXSYBUS:00/PNP0C0A:00/power_supply/BAT1
┌──(root㉿kali-[/sys/class/power_supply]
└─# ls -l
загалом 0
lrwxrwxrwx 1 root root 0 чер 25 16:08 ACAD -> ../../devices/LNXSYSTM:00/LNXSYBUS:00/ACPI0003:00/power_supply/ACAD
lrwxrwxrwx 1 root root 0 чер 25 16:06 BAT1 -> ../../devices/LNXSYSTM:00/LNXSYBUS:00/PNP0C0A:00/power_supply/BAT1
┌──(root㉿kali-[/sys/class/power_supply]
└─# cd /sys/class/power_supply/BAT1
┌──(root㉿kali-[/sys/class/power_supply/BAT1]
└─# ls -a
. capacity charge_full current_now hwmon1 power status type voltage_now
.. capacity_level charge_full_design cycle_count manufacturer present subsystem uevent
alarm charge_control_end_threshold charge_now device model_name serial_number technology voltage_min_design
┌──(root㉿kali-[/sys/class/power_supply/BAT1]
└─# ls -l
загалом 0
-rw-r--r-- 1 root root 4096 чер 26 08:52 alarm
-r--r--r-- 1 root root 4096 чер 25 16:08 capacity
-r--r--r-- 1 root root 4096 чер 26 08:52 capacity_level
-rw-r--r-- 1 root root 4096 чер 26 08:34 charge_control_end_threshold
-r--r--r-- 1 root root 4096 чер 25 16:08 charge_full
-r--r--r-- 1 root root 4096 чер 25 16:08 charge_full_design
-r--r--r-- 1 root root 4096 чер 25 16:08 charge_now
-r--r--r-- 1 root root 4096 чер 25 16:08 current_now
-r--r--r-- 1 root root 4096 чер 25 16:08 cycle_count
lrwxrwxrwx 1 root root 0 чер 26 00:27 device -> ../../../PNP0C0A:00
drwxr-xr-x 3 root root 0 чер 25 19:06 hwmon1
-r--r--r-- 1 root root 4096 чер 25 16:08 manufacturer
-r--r--r-- 1 root root 4096 чер 25 16:08 model_name
drwxr-xr-x 2 root root 0 чер 26 08:52 power
-r--r--r-- 1 root root 4096 чер 25 16:08 present
-r--r--r-- 1 root root 4096 чер 25 16:08 serial_number
-r--r--r-- 1 root root 4096 чер 25 16:08 status
lrwxrwxrwx 1 root root 0 чер 25 16:06 subsystem -> ../../../../../../class/power_supply
-r--r--r-- 1 root root 4096 чер 25 16:08 technology
-r--r--r-- 1 root root 4096 чер 25 16:08 type
-rw-r--r-- 1 root root 4096 чер 25 17:14 uevent
-r--r--r-- 1 root root 4096 чер 25 16:08 voltage_min_design
-r--r--r-- 1 root root 4096 чер 25 16:08 voltage_now
┌──(root㉿kali-[/sys/class/power_supply/BAT1]
└─# cat /sys/class/power_supply/BAT1/status
Charging
┌──(root㉿kali-[/sys/class/power_supply/BAT1]
└─# cat /sys/class/power_supply/BAT1/capacity
76
┌──(root㉿kali-[/sys/class/power_supply/BAT1]
└─# cat /sys/class/power_supply/BAT1/charge_control_end_threshold
50
┌──(root㉿kali-[/sys/class/power_supply/BAT1]
└─# echo 60 > /sys/class/power_supply/BAT1/charge_control_end_threshold
┌──(root㉿kali-[/sys/class/power_supply/BAT1]
└─# cat /sys/class/power_supply/BAT1/status
Unknown
If i take this command charging stopped
OS: Kali GNU/Linux Rolling x86_64
Host: ASUS TUF Gaming F17 FX706HE_FX706HE 1.0
Kernel: Linux 11 5.17.0-kali3-amd64 #1 SMP PREEMPT Debian 5.17.11-1kali1 (2022-05-30) x86_64 GNU/Linux
└─# bat -v
bat 0.9.1
0.9.1 (Latest)
No response
No response
No response
Hi, I've downloaded and used the bat file from the Release page, version 0.13, following your instruction to the letter but the setting doesn't persist after restarting.
After running the bat, this is the services I see in systemctl:
When I run the following command in the Terminal after restarting:
systemctl --state=active --type=service
I do not see [email protected]
running.
However, when I check for all services:
systemctl --type=service
I see that there's the service [email protected]
, but not activated
The service file is identical to that in your source code.
OS: Ubuntu 22.04.3 LTS x86_64
Host: ZenBook UX425EA_UX425EA 1.0
Kernel: 6.2.0-32-generic
Shell: bash 5.1.16
Resolution: 1920x1080
DE: Unity 7.6.0
WM: Compiz
Terminal: gnome-terminal
0.13 (Latest)
Download and run the bat file as per instructions, then restart/shutdown the laptop.
After restart/turn on, the service should automatically be activated by the systemd and the systemctl.
Running bat threshold
should return the pre-determined value.
The service isn't run, not after restarting. Running bat threshold
returns the default value (100).
Hi Leveson,
I just bought an Ideapad to replace my T420 Thinkpad because I accidentally cracked the screen. I saw your answer on askubuntu I think and clicked to get here.
Does this work for Lenovo Ideapads?
I followed the instructions, but it doesn't seem to work. My laptop is Asus tuf A17 (fa706ih-au054t). I am getting this following message : "exit status 1". This is displayed for any command I run.
Bat is easy to install and works fine in ubuntu/asus: how to uninstall it?
OS: Ubuntu 22.04 Linux x86_64
Host: ZenBook
Kernel: 5.15.0-27-generic
0.8.4 (Latest)
No response
No response
No response
go build ./cmd/bat/
results in
build tshaka.co/bat/cmd/bat: cannot load embed: malformed module path "embed": missing dot in first path element
Steps to reproduce on Ubuntu 20.04:
cd ~/dev
git clone https://github.com/tshakalekholoane/bat.git
cd bat
sudo apt install golang-go
time go build ./cmd/bat/
output:
~/GS/dev/bat$ time go build ./cmd/bat/
build tshaka.co/bat/cmd/bat: cannot load embed: malformed module path "embed": missing dot in first path element
And a slightly different attempt (seems to have resolved the error above, but now results in a new one):
~/GS/dev/bat$ time go build cmd/bat/
can't load package: package cmd/bat: package cmd/bat is not in GOROOT (/usr/lib/go-1.13/src/cmd/bat)
Create individual jobs for the tasks in CI workflow file.
First, thanks for writing this and giving it to the community. I appreciate it. I just bought a new battery for my N750JV, but already it lasts only 60 minutes max... :-/ So, I was happy to come across your utility. However, when I enter
sudo ./bat --threshold 80
the utility tells me "This program is most likely not compatible with your system."
I have an ASUS N750JV with the latest BIOS upgrade and Linux kernel 5.4.0-70-generic. Could you explain what could be wrong?
Best regards, OmeCor
Hi! First of all i would like to Thank you for this great app. Working extremely well on my VivoBook_ASUSLaptop X415JA 1.0 running Linux Mint 21.1 x86_64 using kernel 5.15.0-58-generic with DE of Xfce 4.16
Unfortunately, i could not update this app. Downloading the latest version and applying the required permission and then substituting it to the older version does not work for me. Giving a guide or way how to update is much appreciated. I am currently running bat 0.10.1-0-gc5871eb-dirty version by the way.
After resuming from suspend-then-hibernate, if battery level is above charge threshold (80), it shouldn't be charging.
The battery is charging despite that battery level is above threshold (80) after resuming from suspend-then-hibernate.
bat -t
correctly shows the threshold I configured. Manually setting charge threshold again makes it work properly.
sudo bat -t 80
sudo bat -p
.HibernateDelaySec
(like 20 for testing) in /etc/systemd/sleep.conf
.bat -s
.sudo systemctl suspend-then-hibernate
and wait for it to enter hibernate mode.bat -s
and it says it's charging.sudo bat -t 80
then check battery status. This time the threshold works and battery isn't charging.With both suspend and hibernate the threshold works properly.
I tried both 0.8
and 0.8.1
, neither works.
OS: Manjaro Linux x86_64
Host: ZenBook UX425EA_UX425EA 1.0
Kernel: 5.13.8-1-MANJARO
Packages: 1373 (pacman), 5 (flatpak), 10 (snap)
Shell: zsh 5.8
Resolution: 1920x1080
DE: Plasma 5.22.4
WM: KWin
CPU: 11th Gen Intel i5-1135G7 (8) @ 4.200GHz
GPU: Intel TigerLake-LP GT2 [Iris Xe Graphics]
Memory: 2203MiB / 15701MiB
[igor@nixos:~]$ sudo bat -t 80
Charging threshold set.
Use sudo bat --persist
to persist the setting between restarts.
[igor@nixos:~]$ sudo bat -p
Could not find Bash on your system.
NixOS uses Bash as default shell. Please, check your shell calls. Setting threshold works fine.
OS: NixOS 22.05 (Quokka) x86_64
Host: ASUSTeK COMPUTER INC. X513IA
Kernel: 5.15.43
0.9 (Latest)
No response
No response
No response
There should be a command to check battery health which is the maximum storage capacity in percentage.
Eg.
OS: Ubuntu 22.04 Linux x86_64
Host: Asus TUF A15 FA506IH
Kernel: 5.19.0-45-generic
0.12 (Latest)
Its not working, it keep charging full.
OS: Ubuntu 23.04
Host: ZenBook UX425EA
Replace the following with a system call.
Lines 199 to 206 in 9dc3af6
Just wanted to add that the T14 Gen2 Intel version also works with this.
For example,
OS: Manjaro Linux x86_64
Host: 20W0003KUS ThinkPad T14 Gen 2i
Kernel: 5.15.12-1-MANJARO
CPU: Intel i5-1135G7 11th Gen
0.8.4 (Latest)
No response
No response
No response
Hi Leveson,
This works for my TUF series laptop but after I set to a value say 60, the status shows "unknown" instead of showing "Not charging". When I unplug, it shows as "Discharging".
My battery type is BAT1
Also, on Manjaro, I get some to start errors during startup. Please, let me know if there's anything to tinker with.
Hi.
I have an Asus laptop but I get an error:
This program is most likely not compatible with your system. See
https://github.com/leveson/bat#disclaimer.
model: zenbook flip ux46fl.
thanks.
Getting this error on NixOS when trying to make batter settings persist.
Running the command:
sudo /opt/asus-bat-manager/bin/bat persist --debug
gives this output.
open /etc/systemd/system/bat-hibernate.service: read-only file system
goroutine 1 [running]:
runtime/debug.Stack()
/nix/store/ws97rhhdzacbl58y8crpvg517zqnbsll-go-1.21.5/share/go/src/runtime/debug/stack.go:24 +0x5e
main.main.func1()
/home/kingbain/bat/main_linux.go:156 +0x55
panic({0x52f700?, 0xc00011ca50?})
/nix/store/ws97rhhdzacbl58y8crpvg517zqnbsll-go-1.21.5/share/go/src/runtime/panic.go:920 +0x270
main.main()
/home/kingbain/bat/main_linux.go:222 +0x1230
Any chance you could create a nixos package ?
If the laptop is put to suspend, then this feature doesn't work. Also, the persist function doesn't work.
And for example if I use the following command : ./bat --threshold 60, I get asked for root password, but I always get authentication failure. So, I need to use SUDO with it.
This program only works temporarily( During the session). If subjected to suspend or restart, then it fails.
I am using asus tuf a17 FA-706IH
operating system: ubuntu 20.04
kernel: 5.8.0-44-generic
Latest AUR package of 0.9.1-1 is unable to build. Package manager returned the package as unable to build because one or more files did not pass validity check.
Pamac log:
Building bat-asus-battery-bin...
==> Making package: bat-asus-battery-bin 0.9.1-1
==> Checking runtime dependencies...
==> Checking buildtime dependencies...
==> Retrieving sources...
-> Found bat.zip
==> Validating source files with sha256sums...
bat.zip ... FAILED
==> ERROR: One or more files did not pass the validity check!
Failed to build bat-asus-battery-bin
Please confirm and push a fix. Thank you.
OS: Manjaro Linux x86_64
Kernel: 5.15.41-1-MANJARO
Shell: zsh 5.9
DE: GNOME 42.2
0.9.1 (Latest)
Build in Pamac from AUR package.
Successful build.
Unable to build
There is no --threshold option. Run bat --help
to see a list of available options.
.............
..,;:ccc,. -------------------
......''';lxO. OS: Kali GNU/Linux Rolling x
.....''''..........,:ld;
.';;;:::;,,.x, Kernel: 5.18.0-kali7-amd64
..'''. 0Xxoc:,. ... Uptime: 42 mins
.... ,ONkc;,;cokOdc',. Packages: 5479 (dpkg), 15 (s
. OMo ':ddo. Shell: zsh 5.9
dMc :OO; Resolution: 1366x768
0M. .:o. DE: GNOME 43.0
;Wd WM: Mutter
;XO, WM Theme: Kali-Dark
,d0Odlc;,.. Theme: adw-gtk3-dark [GTK2/3
..',;:cdOOd::,. Icons: Flat-Remix-Blue-Dark
.:d;.':;. Terminal: gnome-terminal
'd, .'
;l ..
.o
c
0.10.1 (Latest)
No response
No response
No response
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.