Skip to content

Instantly share code, notes, and snippets.

@saimonn
Created May 17, 2022 18:07
Show Gist options
  • Save saimonn/3a4be5f4dabb8ba94d4918cb58844aa7 to your computer and use it in GitHub Desktop.
Save saimonn/3a4be5f4dabb8ba94d4918cb58844aa7 to your computer and use it in GitHub Desktop.
# This simple systemd unit sets battery thresholds to preserve battery life on Lenovo Thinkpad
# (works on T470 but might work for others models)
#
# use this command to create the unit file:
#
# systemctl edit --force --full battery_thresholds.service
#
# to enable the service and start it now, type:
#
# systemctl enable battery_thresholds.service --now
#
[Unit]
Description=Set battery thresholds to preserve battery life on Lenovo Thinkpad
After=network.target
RequiresMountsFor=/sys
[Service]
Type=oneshot
ExecStart=sh -c 'echo 85 > /sys/class/power_supply/BAT0/charge_control_end_threshold'
ExecStart=sh -c 'echo 85 > /sys/class/power_supply/BAT1/charge_control_end_threshold'
ExecStart=sh -c 'echo 30 > /sys/class/power_supply/BAT0/charge_control_start_threshold'
ExecStart=sh -c 'echo 30 > /sys/class/power_supply/BAT1/charge_control_start_threshold'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment