Battery charge limit reset after reboot

Hi. This does not work anymore. Fedora Asahi 42 KDE plasma.
Anyone have a solution?
Thanks!

echo ‘SUBSYSTEM==“power_supply”, KERNEL==“macsmc-battery”, ATTR{charge_control_end_threshold}=“80”’ | sudo tee /etc/udev/rules.d/10-battery.rules

1 Like

echo 80 | sudo tee /sys/class/power_supply/macsmc-battery/charge_control_end_threshold

This works, but is not persistent.

1 Like

Also having this problem on my system. Haven’t found anything that works yet

Not much help in here :wink:

Yeah, I agree. Most people usually ask in the Matrix channel, so this can sometimes feel a little empty.

That said, I don’t think you need the udev rule anymore. If you’re using Plasma, you can simply adjust it via system settings (Gnome should work too, haven’t tried)

Power Management > Advanced Power Settings > Charge Limit

Thanks for the reply!

In plasma, the settings is not persistent. Reset after reboot.

Not sure if this helps but do you have a file in /etc/udev/macsmc-battery.conf?

Mine has a charge threshold set there and it’s the last thing in my shell history, so maybe that’s what fixed it.

CHARGE_CONTROL_END_THRESHOLD=80

is what I have setup there

Just tested on a fresh install on my M2, I’m not exactly sure which of those worked, but I got it to work with the following:

KERNEL=="macsmc-battery", SUBSYSTEM=="power_supply", ATTR{charge_control_end_threshold}="80", ATTR{charge_control_start_threshold}="70"
| sudo tee /etc/udev/rules.d/99-asahi-battery.rules

I then ran

CHARGE_CONTROL_END_THRESHOLD=80 | sudo tee /etc/udev/macsmc-battery.conf

paired with

sudo semanage fcontext -a -t udev_rules_t '/etc/udev/macsmc-battery.conf'
and

sudo restorecon -v '/etc/udev/macsmc-battery.conf'

after a reboot, the charge limit was successfully set to 80%.

Again, not sure if you need all those bits but things should work. The first bit seems to be mandatory

The commands above do persist across reboots but they aren’t limiting the charge in asahi.

From my own testing, it seems that changing the values in KDE changes the following files:

  • /sys/class/power_supply/macsmc-battery/charge_control_end_threshold
  • /sys/class/power_supply/macsmc-battery/charge_control_start_threshold

which both reset to 100 after a restart

EDIT: I also tried ACTION=="add", SUBSYSTEM=="power_supply", KERNEL=="macsmc-battery", RUN+="/bin/sh -c 'echo 80 | tee /sys/class/power_supply/macsmc-battery/charge_control_end_threshold'" in udev rules and still get 100 in /sys/class/power_supply/charge_control_end_threshold

EDIT 2: I was able to get it working by writing a systemd service:
[Unit]
ConditionPathExists=/sys/class/power_supply/macsmc-battery/charge_control_end_threshold
[Service]
Type=oneshot
ExecStart=/bin/bash -c "echo 90 > /sys/class/power_supply/macsmc-battery/charge_control_end_threshold && echo 85 > /
sys/class/power_supply/macsmc-battery/charge_control_start_threshold"
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target

Excellent. Please explain to a newbie. Where do I put this config file and execute it?

Absolutely.

  • Create the service using:
sudo bash -c 'cat > /etc/systemd/system/battery-charge-limit.service << "EOF"
[Unit]
ConditionPathExists=/sys/class/power_supply/macsmc-battery/charge_control_end_threshold

[Service]
Type=oneshot
ExecStart=/bin/bash -c "echo 85 > /sys/class/power_supply/macsmc-battery/charge_control_end_threshold && echo 80 > /sys/class/power_supply/macsmc-battery/charge_control_start_threshold"
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target
EOF'

(this will make it charge to 85 max, and then discharge to 80 before charging again. Change the numbers to the limits you want)

  • Enable the service:
sudo systemctl enable battery-charge-limit.service
  • Start the service:
sudo systemctl start battery-charge-limit.service

it should now work on reboot

1 Like

Thank you very much!! :slight_smile:

1 Like

Dumb question: Are you leaving your computer plugged in between reboots in these instances where the limit default is changed in Plasma?

I’ve tried setting it with power plugged in and just battery and it still resets.

This issue might have been because of “consequence of a firmware change that Apple introduced this summer” according to this issue on Github

(one person mentioned the charge limit thing there)
So follow that thread to see updates and fixes to this issue

1 Like

Nice find!

Also explains why mine was working fine because I haven’t touched MacOS since last year lol

1 Like