not working if the computer is put to sleep mode
sjv-afk1 opened this issue · 36 comments
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
Thank you for bringing up the issue. I will have a look into it.
Just to make sure that I understand,
- when the laptop is put to suspend (or shut down), the charging threshold is not set anymore upon restart,
- the persist argument does not work at all,
- when you run
bat --threshold 60
and get asked for the root password you get an authentication failure message but if you usesudo bat --threshold 60
it works?
Thank you for bringing up the issue. I will have a look into it.
Just to make sure that I understand,
- when the laptop is put to suspend (or shut down), the charging threshold is not set anymore upon restart,
- the persist argument does not work at all,
- when you run
bat --threshold 60
and get asked for the root password you get an authentication failure message but if you usesudo bat --threshold 60
it works?
- YES ( I mean sleep mode when I say suspend) So, if I resume from sleep mode, then threshold is reset to 100. ( However, in the command line it shows that threshold is 60, but I can see my laptop charging towards full capacity)
- YES
- YES
Do you get any message after running sudo bat --persist
?
Do you get any message after running
sudo bat --persist
?
no
Can you run the following command, test -f /etc/systemd/system/bat.service && echo "TRUE"
and tell me what you get out?
Can you run the following command,
test -f /etc/systemd/system/bat.service && echo "TRUE"
and tell me what you get out?
~/Binaries/bat1$ test -f /sys/class/power_supply/BAT?/charge_control_end_threshold && echo "TRUE"
TRUE
Sorry about that, just edited the comment to run a different command. Can you run this command test -f /etc/systemd/system/bat.service && echo "TRUE"
?
Sorry about that, just edited the comment to run a different command. Can you run this command
test -f /etc/systemd/system/bat.service && echo "TRUE"
?
test -f /etc/systemd/system/bat.service && echo "TRUE"
TRUE
Please check if the file has any contents by running, less /etc/systemd/system/bat.service
.
If it does, then run systemctl enable bat.service
and tell me what happens. I have a feeling on Ubuntu you might have to run this with sudo
but let me know what happens in the first instance (without sudo
) and if everything works after running these.
less /etc/systemd/system/bat.service
Please check if the file has any contents by running,
less /etc/systemd/system/bat.service
.If it does, then run
systemctl enable bat.service
and tell me what happens. I have a feeling on Ubuntu you might have to run this withsudo
but let me know what happens in the first instance (withoutsudo
) and if everything works after running these.
This is what I am getting after running first command:
[Unit]
Description=Set the battery charging threshold
After=multi-user.target
StartLimitBurst=0
[Service]
Type=oneshot
Restart=on-failure
ExecStart=/bin/bash -c 'echo 91 > /sys/class/power_supply/BAT?/charge_control_end_threshold'
[Install]
WantedBy=multi-user.target
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
(END)
and after running "systemctl enable bat.service" nothing happens. I tried using SUDO also.
Nothing happens as in there is no output after running the command or the battery threshold is still not persisting between restarts?
Can you run the following and send me the output? I might have to get Ubuntu installed to try to work this one out.
sudo bat -t 60
sudo bat -p
systemctl status bat.service
And just to make sure, you are running the latest version from the releases page right?
systemctl status bat.service
Nothing happens as in there is no output after running the command or the battery threshold is still not persisting between restarts?
Can you run the following and send me the output? I might have to get Ubuntu installed to try to work this one out.
sudo bat -t 60
sudo bat -p
systemctl status bat.service
And just to make sure, you are running the latest version from the releases page right?
Yes I am running the latest release. The following is the output:
sjv@dh1729:/Binaries/bat1$ sudo ./bat -t 60/Binaries/bat1$ sudo ./bat -p
Identified face as sjv
Charging threshold set to 60.
sjv@dh1729:
sjv@dh1729:~/Binaries/bat1$ systemctl status bat.service
● bat.service - Set the battery charging threshold
Loaded: loaded (/etc/systemd/system/bat.service; enabled; vendor preset: e>
Active: inactive (dead) since Mon 2021-03-08 15:25:59 IST; 2 days ago
Main PID: 2554 (code=exited, status=0/SUCCESS)
Mar 08 15:25:59 dh1729 systemd[1]: Starting Set the battery charging threshold.>
Mar 08 15:25:59 dh1729 systemd[1]: bat.service: Succeeded.
Mar 08 15:25:59 dh1729 systemd[1]: Finished Set the battery charging threshold.
lines 1-8/8 (END)...skipping...
● bat.service - Set the battery charging threshold
Loaded: loaded (/etc/systemd/system/bat.service; enabled; vendor preset: enabled)
Active: inactive (dead) since Mon 2021-03-08 15:25:59 IST; 2 days ago
Main PID: 2554 (code=exited, status=0/SUCCESS)
Mar 08 15:25:59 dh1729 systemd[1]: Starting Set the battery charging threshold...
Mar 08 15:25:59 dh1729 systemd[1]: bat.service: Succeeded.
Mar 08 15:25:59 dh1729 systemd[1]: Finished Set the battery charging threshold.
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
lines 1-8/8 (END)
Can you check if this fix works?
Can you check if this fix works?
Not working. Do I need to restart the computer and test it again?
I think so. Judging by your output, everything should be working. The threshold level seems to be set to 91 and it should persist between restarts and sleep/suspend but not hibernation.
The only problem seems to have been with the call to set the threshold level which on Ubuntu didn't work because the root user appears to be locked by default but that should not be a problem with this version.
As a last resort, run sudo bat --reset
, restart your computer, run sudo bat -t 60
. If that does not work, show me the output to that along with the output to cat /sys/class/power_supply/BAT?/charge_control_end_threshold
.
If that worked then, run sudo bat -p
and show me the output to cat /etc/systemd/system/bat.service
and systemctl status bat.service
.
Okay, I will post it in few hours.
cat /sys/class/power_supply/BAT?/charge_control_end_threshold
sjv@dh1729:/Binaries/bat2$ sudo ./bat -t 60/Binaries/bat2$ sudo ./bat --persist
Identified face as sjv
Charging threshold set to 60.
sjv@dh1729:
sjv@dh1729:~/Binaries/bat2$ cat /sys/class/power_supply/BAT?/charge_control_end_threshold
60
so after resuming from suspend, it is not working.
Okay. That narrows it down. Without doing anything else, when you shut it down and boot again, is it still set to 60?
Okay. That narrows it down. Without doing anything else, when you shut it down and boot again, is it still set to 60?
Yes, it shows that it is set to 60.
Let me know if this fixes the problem with the threshold not persisting after sleep/suspend. But first run sudo rm /etc/systemd/system/bat.service
.
Let me know if this fixes the problem with the threshold not persisting after sleep/suspend. But first run
sudo rm /etc/systemd/system/bat.service
.
Didn't work.
Seems to be an issue with systemd. Can you check which version is installed on your system by running systemctl --version
?
systemctl --version
systemd 245 (245.4-4ubuntu3.4)
+PAM +AUDIT +SELINUX +IMA +APPARMOR +SMACK +SYSVINIT +UTMP +LIBCRYPTSETUP +GCRYPT +GNUTLS +ACL +XZ +LZ4 +SECCOMP +BLKID +ELFUTILS +KMOD +IDN2 -IDN +PCRE2 default-hierarchy=hybrid
Curious. I’ll have to get a distribution of Ubuntu to understand exactly what is going on but it could take a while.
Hi,
I am using ubuntu20.4+kernel 5.10+systemd 245 (245.4-4ubuntu3.6).
In may case bat-h, bat-c, bat-s works as it should
bat -t or sudo bat -t exit status 1
bat -p or sudo bat -p exit status 1 and service not starting
bat - r ok after sudo password
Can You help?
Difficult to say right now. But I will look into this and post here as soon as I manage to get a distribution of Ubuntu.
I have the same problem. Looking at your previous suggestions i have run the following:
test -f /etc/systemd/system/bat.service && echo "TRUE"
Returns nothing
less /etc/systemd/system/bat.service
Returns "no such file or directory"
systemctl --version
Returns the verision of systemd as 247
Ubuntu 21.04
Cheers. I have had exams so I haven't had the time to work on a fix yet but I should be able to download Ubuntu and get to working on it in the comings weeks.
Here is a proposed fix.
Let me know if it works.
For everyone else, if you could show me the output of the following command,
test -f /sys/class/power_supply/BAT?/charge_control_end_threshold && echo "TRUE"
Ubuntu 20.04 does not seem to expose the charging threshold variable. At least when running it in a VM. But if you get an output value of TRUE
to the above command then I can look further into it.
Hi,
I think I might need a clarification on the difference between suspend and hibernate.
I tried the new bat file and it's the same as before. If i close the lid of the laptop and open it the laptop starts charging. bat -t
returns 60.
When the lid is closed the battery is stopped at 60 but when i open the lid it starts charging. Specifically after logging in. Then i have to type sudo bat -t 60
again and I did sudo bat -p
test -f /sys/class/power_supply/BAT?/charge_control_end_threshold && echo "TRUE"
This code returns TRUE for me.
Oh and when i reboot it stops at 60. The only time it stops is when the lid is closed or when i leave for too long.
To try the new bat file I deleted using sudo rm /usr/local/bin/bat
then sudo install bat /usr/local/bin
after replacing the old bat file.
Ubuntu 20.04 LTS
Suspend stores the machine's state in RAM and keeps it in low power mode whereas hibernate saves the machine's state in swap space and completely turns it off.
Hibernate is notoriously difficult to get right on Linux and might even be disabled on Ubuntu by default but with some additional configuration you could enable it.
Anyway, try the following and let me know if it fixes the problem.
Just remember to run the --reset
command first and make sure you're running this build using the --version
flag which should say 0.6-beta
.
It works great.
Thank you for all the help.
Thank you for feedback! Can you post the output of the following command so that I can finalise a release?
systemctl status bat-sleep.service
systemctl status bat-sleep.service
Output (When the charging is stopped at 60%):
● bat-sleep.service - Persist the battery charging threshold after hibernation
Loaded: loaded (/etc/systemd/system/bat-sleep.service; enabled; vendor preset: enabled)
Active: inactive (dead)
Thank you.
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!