Giter Club home page Giter Club logo

Comments (19)

pepa65 avatar pepa65 commented on May 25, 2024 3

Try putting this in /usr/lib/systemd/system-sleep/bat:

#!/bin/sh
test "x$1" = "xpost" &&
  /usr/bin/echo 60 >/sys/class/power_supply/BAT1/charge_control_end_threshold
exit 0

And make it executable: sudo chmod +x /usr/lib/systemd/system-sleep/bat

from bat.

HarshDobariya79 avatar HarshDobariya79 commented on May 25, 2024 3

Try putting this in /usr/lib/systemd/system-sleep/bat:

#!/bin/sh
test "x$1" = "xpost" &&
  /usr/bin/echo 60 >/sys/class/power_supply/BAT1/charge_control_end_threshold
exit 0

And make it executable: sudo chmod +x /usr/lib/systemd/system-sleep/bat

Worked! Thank you very much 😄

from bat.

pepa65 avatar pepa65 commented on May 25, 2024 2

I have added it as an additional way to persist the threshold, just write that file on Persist and delete it on Reset.

from bat.

HarshDobariya79 avatar HarshDobariya79 commented on May 25, 2024 1

/etc/systemd/system/bat-hybrid-sleep.service

[Unit]
Description=Persist the battery charging threshold after hybrid-sleep
After=hybrid-sleep.target
StartLimitBurst=0

[Service]
Type=oneshot
ExecStart=/usr/bin/sh -c 'echo 60 > /sys/class/power_supply/BAT1/charge_control_end_threshold'
Restart=on-failure
RemainAfterExit=true

[Install]
WantedBy=hybrid-sleep.target

/etc/systemd/system/hybrid-sleep.target.wants/chargelimit-hybrid-sleep.service

[Unit]
Description=Persist the battery charge limit after hybrid-sleep
After=hybrid-sleep.target
StartLimitBurst=0

[Service]
Type=oneshot
ExecStart=/usr/bin/sh -c 'echo 60 >/sys/class/power_supply/BAT1/charge_control_end_threshold'
Restart=on-failure
RemainAfterExit=true

[Install]
WantedBy=hybrid-sleep.target

No trace of battery persistent in syslog after waking up.

from bat.

HarshDobariya79 avatar HarshDobariya79 commented on May 25, 2024 1

The chargelimit-suspend.service became active after these steps. Still the same issue after wake up from sleep.

chargelimit-suspend.service

● chargelimit-suspend.service - Persist the battery charge limit after suspend
     Loaded: loaded (/etc/systemd/system/chargelimit-suspend.service; enabled; preset: enabled)
     Active: active (exited) since Mon 2023-11-27 20:58:04 IST; 40s ago
   Main PID: 9972 (code=exited, status=0/SUCCESS)
        CPU: 2ms

Nov 27 20:58:04 23.10 systemd[1]: Starting chargelimit-suspend.service - Persist the battery charge limit after suspend...
Nov 27 20:58:04 23.10 systemd[1]: Finished chargelimit-suspend.service - Persist the battery charge limit after suspend.

output of ./bat

[BAT1]
Level: 87%
Limit: 60%
Health: 77%
Status: Charging
Persist: yes

from bat.

pepa65 avatar pepa65 commented on May 25, 2024

How do you "send the host machine to sleep"?

In any case, I think it might be because sleep is not used in the persist settings. To test if this is the case, do wget good4.eu/bat; chmod +x bat; sudo ./bat persist and see if that fixes the issue.

from bat.

HarshDobariya79 avatar HarshDobariya79 commented on May 25, 2024

I've tried fn+F11 which is the shortcut for sleep as well as suspend option from GUI. In both cases it is failing. I've also tried wget good4.eu/bat; chmod +x bat; sudo ./bat persist that also doesn't work.

from bat.

HarshDobariya79 avatar HarshDobariya79 commented on May 25, 2024

Also the threshold works fine while the machine is in sleep and stops working as soon as the machine wakes up.

from bat.

pepa65 avatar pepa65 commented on May 25, 2024

Reloading the driver resets the threshold value. The unit files /etc/systemd/system/bat-* together with /etc/systemd/system/*.wants/bat-* should take care of that.

What does /var/log/system look like right after coming back from sleep. What are the lines after the line System returned from sleep state., do you have Starting Persist the battery charging threshold after suspend...?

from bat.

pepa65 avatar pepa65 commented on May 25, 2024

So in /var/log/syslog after the line System returned from sleep state. you must have soon after that: Reached target Suspend.. On my system I have right after that Starting Persist the battery charging threshold after suspend....

What does sudo systemctl status bat-suspend.service give?

from bat.

HarshDobariya79 avatar HarshDobariya79 commented on May 25, 2024

There is no trace of Starting Persist the battery charging threshold after suspend..., I also tried to search in the logs file. The bat-suspend.service is active.

/var/log/syslog

2023-11-27T15:01:03.013980+05:30 23 systemd[1]: Reached target suspend.target - Suspend.
2023-11-27T15:01:03.015894+05:30 23 ModemManager[1297]: <info>  [sleep-monitor-systemd] system is resuming
2023-11-27T15:01:03.046468+05:30 23 kernel: [15215.439762] Generic FE-GE Realtek PHY r8169-0-200:00: attached PHY driver (mii_bus:phy_addr=r8169-0-200:00, irq=MAC)
2023-11-27T15:01:03.062648+05:30 23 NetworkManager[1089]: <info>  [1701077463.0155] manager: sleep: wake requested (sleeping: yes  enabled: yes)
2023-11-27T15:01:03.063293+05:30 23 NetworkManager[1089]: <info>  [1701077463.0158] device (enp2s0): state change: unmanaged -> unavailable (reason 'managed', sys-iface-state: 'external')
2023-11-27T15:01:03.063529+05:30 23 systemd[1]: Starting grub-common.service - Record successful boot for GRUB...
2023-11-27T15:01:03.067127+05:30 23 systemd[1]: Starting nvidia-resume.service - NVIDIA system resume actions...
2023-11-27T15:01:03.071577+05:30 23 suspend: nvidia-resume.service
2023-11-27T15:01:03.071714+05:30 23 logger[88302]: <13>Nov 27 15:01:03 suspend: nvidia-resume.service
2023-11-27T15:01:03.074870+05:30 23 systemd[1]: Stopped target suspend.target - Suspend.
2023-11-27T15:01:03.080368+05:30 23 systemd[1]: nvidia-resume.service: Deactivated successfully.
2023-11-27T15:01:03.081143+05:30 23 systemd[1]: Finished nvidia-resume.service - NVIDIA system resume actions.
2023-11-27T15:01:03.087695+05:30 23 systemd[1]: grub-common.service: Deactivated successfully.
2023-11-27T15:01:03.088092+05:30 23 systemd[1]: Finished grub-common.service - Record successful boot for GRUB.
2023-11-27T15:01:03.091526+05:30 23 systemd[1]: Starting grub-initrd-fallback.service - GRUB failed boot detection...
2023-11-27T15:01:03.102964+05:30 23 systemd[1]: grub-initrd-fallback.service: Deactivated successfully.
2023-11-27T15:01:03.103600+05:30 23 systemd[1]: Finished grub-initrd-fallback.service - GRUB failed boot detection.
2023-11-27T15:01:03.187569+05:30 23 gnome-shell[3264]: Window manager warning: Overwriting existing binding of keysym 35 with keysym 35 (keycode e).
2023-11-27T15:01:03.187764+05:30 23 gnome-shell[3264]: Window manager warning: Overwriting existing binding of keysym 31 with keysym 31 (keycode a).
2023-11-27T15:01:03.187816+05:30 23 gnome-shell[3264]: Window manager warning: Overwriting existing binding of keysym 32 with keysym 32 (keycode b).
2023-11-27T15:01:03.187877+05:30 23 gnome-shell[3264]: Window manager warning: Overwriting existing binding of keysym 33 with keysym 33 (keycode c).
2023-11-27T15:01:03.187922+05:30 23 gnome-shell[3264]: Window manager warning: Overwriting existing binding of keysym 34 with keysym 34 (keycode d).

bat-suspend.service

● bat-suspend.service - Persist the battery charging threshold after suspend
     Loaded: loaded (/etc/systemd/system/bat-suspend.service; enabled; preset: enabled)
     Active: active (exited) since Mon 2023-11-27 09:23:54 IST; 5h 45min ago
   Main PID: 4447 (code=exited, status=0/SUCCESS)
        CPU: 5ms

Nov 27 09:23:54 23.10 systemd[1]: Starting bat-suspend.service - Persist the battery charging threshold after suspend...
Nov 27 09:23:54 23.10 systemd[1]: Finished bat-suspend.service - Persist the battery charging threshold after suspend.

from bat.

pepa65 avatar pepa65 commented on May 25, 2024

All this would not be necessary if the driver would just accept a parameter to set the charge limit...

We need a systemd expert to get this to work I guess. Side note, I am on 22.04, you seem to be on 23.10, so the systemd version is different.

from bat.

HarshDobariya79 avatar HarshDobariya79 commented on May 25, 2024

All this would not be necessary if the driver would just accept a parameter to set the charge limit...

We need a systemd expert to get this to work I guess. Side note, I am on 22.04, you seem to be on 23.10, so the systemd version is different.

Yes. I was also using it on 22.04 Jammy and it was working perfectly fine.

from bat.

HarshDobariya79 avatar HarshDobariya79 commented on May 25, 2024

I found this service inactive, but I can't enable it.

○ chargelimit-suspend.service - Persist the battery charge limit after suspend
     Loaded: loaded (/etc/systemd/system/chargelimit-suspend.service; enabled; preset: enabled)
     Active: inactive (dead)

from bat.

pepa65 avatar pepa65 commented on May 25, 2024

I found this service inactive, but I can't enable it.

What you can try is bat reset (with the installed binary) and then sudo ./bat remove (with the downloaded binary) followed by sudo ./bat persist. Then see what the output is of ./bat.

from bat.

pepa65 avatar pepa65 commented on May 25, 2024

There must be something in the requirements for the systemd unit files that changed so they no longer work in the 23.10 version...

Edit: strange that it's charging past the set limit too.

from bat.

HarshDobariya79 avatar HarshDobariya79 commented on May 25, 2024

There must be something in the requirements for the systemd unit files that changed so they no longer work in the 23.10 version...

Yes, most likely.

from bat.

tshakalekholoane avatar tshakalekholoane commented on May 25, 2024

@pepa65 do you think this is a more robust way to set the threshold after sleep or is it enough of an edge case to leave things as is?

from bat.

tshakalekholoane avatar tshakalekholoane commented on May 25, 2024

I’ll mark this issue as resolved and if more people have the same problem maybe we’ll go with that too.

from bat.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.