You are not logged in.

#1 2025-09-08 01:43:14

Stez827
Member
Registered: 2025-09-08
Posts: 2

Battery Charge Limit

Hey everyone,

I am currently having the issue of having to set my battery charge limit manually every time I boot. I am using hyprland and my current solution is a keybind which gives me a popup to input my sudo password (is that the right terminology? sorry if it's not). the command I'm using to set my battery charge limit is this "echo '80' | pkexec tee /sys/class/power_supply/BAT0/charge_control_end_threshold"

I would like to not have to do anything and have it just set the charge limit when I boot.

Does anyone have any better solutions?

Offline

#2 2025-09-08 02:04:23

killertofus
Member
Registered: 2025-02-10
Posts: 182

Re: Battery Charge Limit

you could create a systemd service that runs at boot that does that


I Have Linux Perl Can i Download Gnome???

Online

#3 2025-09-08 06:25:53

Head_on_a_Stick
Member
From: The Wirral
Registered: 2014-02-20
Posts: 9,003
Website

Re: Battery Charge Limit

Or use tmpfiles.d(5), which only needs a single line in a file rather than a complete systemd unit.


Jin, Jîyan, Azadî

Offline

#4 2025-09-08 22:11:48

Stez827
Member
Registered: 2025-09-08
Posts: 2

Re: Battery Charge Limit

I ended up using a systemd service but it doesn't seem to do anything after enabling then rebooting

this is my service
                             
[Unit]
Description=Battery Charge Limit

[Service]
ExecStart=echo '80' | tee /sys/class/power_supply/BAT0/charge_control_end_threshold

[Install]
WantedBy=multi-user.target


what did I do wrong

Offline

#5 2025-09-08 23:17:03

WorMzy
Administrator
From: Scotland
Registered: 2010-06-16
Posts: 13,468
Website

Re: Battery Charge Limit

Systemd services do not run in a shell, so your pipe doesn't work.

You should probably use tmpfiles.d for this anyway: https://wiki.archlinux.org/title/System … rary_files

Alternatively wrap your ExecStart command in a shell, or write a script with a shebang to run the shell and run that with ExecStart instead.


Sakura:-
Mobo: MSI MAG X570S TORPEDO MAX // Processor: AMD Ryzen 9 5950X @4.9GHz // GFX: AMD Radeon RX 5700 XT // RAM: 32GB (4x 8GB) Corsair DDR4 (@ 3000MHz) // Storage: 1x 3TB HDD, 6x 1TB SSD, 2x 120GB SSD, 1x 275GB M2 SSD

Making lemonade from lemons since 2015.

Offline

#6 2025-09-09 06:02:32

Head_on_a_Stick
Member
From: The Wirral
Registered: 2014-02-20
Posts: 9,003
Website

Re: Battery Charge Limit

And if you do use a unit file with a shell drop the useless use of echo:

ExecStart=/usr/bin/bash -c 'tee /sys/class/power_supply/BAT0/charge_control_end_threshold <<< "80"'

https://mywiki.wooledge.org/HereDocument

Or if you prefer

ExecStart=/usr/bin/bash -c 'echo 80 > /sys/class/power_supply/BAT0/charge_control_end_threshold'

Last edited by Head_on_a_Stick (2025-09-09 06:03:41)


Jin, Jîyan, Azadî

Offline

Board footer

Powered by FluxBB