Skip to content

Instantly share code, notes, and snippets.

@lachiefish
Last active October 16, 2024 19:48
Show Gist options
  • Save lachiefish/4eafd778a5afe1b646a378288e73421a to your computer and use it in GitHub Desktop.
Save lachiefish/4eafd778a5afe1b646a378288e73421a to your computer and use it in GitHub Desktop.
Read and set battery charge thresholds on Linux (BAT0) - Run as root or with sudo - NOTE: Your battery may not be BAT0, run 'ls /sys/class/power_supply/' before this script to make sure.
#!/bin/bash
# Get current charge start threshold (in percent)
charge_start=$(cat /sys/class/power_supply/BAT0/charge_start_threshold)
echo "Current charge start threshold: $charge_start%"
# Get current charge end threshold (in percent)
charge_end=$(cat /sys/class/power_supply/BAT0/charge_end_threshold)
echo "Current charge end threshold: $charge_end%"
# Set new charge start threshold
echo "Enter new charge start threshold (numbers only, ie 75 to start charging at 75%):"
read new_start
echo $new_start > /sys/class/power_supply/BAT0/charge_start_threshold
# Set new charge end threshold
echo "Enter new charge end threshold (numbers only, ie 80 to stop charging at 80%):"
read new_end
echo $new_end > /sys/class/power_supply/BAT0/charge_end_threshold
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment