Skip to content

Instantly share code, notes, and snippets.

@kunicmarko20
Last active June 5, 2024 09:53
Show Gist options
  • Save kunicmarko20/c59118872821a8e9695d95f1a1cdda6a to your computer and use it in GitHub Desktop.
Save kunicmarko20/c59118872821a8e9695d95f1a1cdda6a to your computer and use it in GitHub Desktop.
ThinkPad keeps turning off because temprature is too high when charging

Thinkpad (Lenovo ThinkPad X1 Carbon Gen 9) Overheating resolved

This laptop overheats a lot, which makes it turn off a lot. As soon as I connect it to the charger, and it's in balanced power mode, the CPU temp goes over 100.

This is an adaptation of https://kobusvs.co.za/blog/power-profile-switching/

Solutions

1. Based on charging (battery-goes-brrrrrrrrrrrr.sh)

Charger increases battery temp a lot, combined with doing something heavy it skyrockets the CPU temp over 85 easily, meaning as soon as it is over 90 there is a 90% chance it will turn off soon.

This script switches the laptop into power-saving mode as soon as the charger is connected.

2. Based on CPU temperature (temp-goes-brrrrrrrrrrrr.sh)

This script takes CPU temperature into account, meaning as soon as the CPU is constantly (for 10s) over 75 degrees, it will switch into power mode and check again in 5 minutes if it can go into balanced mode again.

3. Based on CPU temperature (Simplified) (simple-temp-goes-brrrrrrrrrrrr.sh)

This script takes CPU temperature into account, meaning as soon as the CPU is over 80 degrees, it will switch into power mode and check again in 5 minutes if it can go into balanced mode again.

Enabling the service

store service: ~/.config/systemd/user/battery-goes-brrrrrrrrrrrr.service

enable service: systemctl --user enable --now battery-goes-brrrrrrrrrrrr.service check status of the service: systemctl --user status battery-goes-brrrrrrrrrrrr.service

[Service]
Environment=STARTUP_WAIT=30s
ExecStart=/home/YOUR_USER_GOES_HERE/bin/battery-goes-brrrrrrrrrrrr.sh
[Install]
WantedBy=default.target
#! /bin/bash
BAT=$(echo /sys/class/power_supply/BAT*)
BAT_STATUS="$BAT/status"
BAT_CAP="$BAT/capacity"
PROFILE_BALANCED="balanced"
PROFILE_POWER_SAVER="power-saver"
# wait a while if needed
[[ -z $STARTUP_WAIT ]] || sleep "$STARTUP_WAIT"
# start the monitor loop
prev=0
while true; do
# read the current state
if [[ $(cat "$BAT_STATUS") == "Charging" ]]; then
profile=$PROFILE_POWER_SAVER
else
profile=$PROFILE_BALANCED
fi
# set the new profile
if [[ $prev != "$profile" ]]; then
powerprofilesctl set $profile
prev=$profile
fi
# wait for the next power change event
inotifywait -qq "$BAT_STATUS" "$BAT_CAP"
done
[Service]
Environment=STARTUP_WAIT=30s
ExecStart=/home/YOUR_USER_GOES_HERE/bin/simple-temp-goes-brrrrrrrrrrrr.sh
[Install]
WantedBy=default.target
#! /bin/bash
CPU=$(echo /sys/class/thermal/thermal_zone7)
CPU_TEMPERATURE="$CPU/temp"
while true; do
if [[ $(cat "$CPU_TEMPERATURE" | grep -Po "^..") > 80 ]]; then
powerprofilesctl set "power-saver"
notify-send "Temperature over 80°C" "Switched to power-saver mode."
sleep 300
else
powerprofilesctl set "balanced"
sleep 30
fi
done
[Service]
Environment=STARTUP_WAIT=30s
ExecStart=/home/YOUR_USER_GOES_HERE/bin/temp-goes-brrrrrrrrrrrr.sh
[Install]
WantedBy=default.target
#! /bin/bash
CPU=$(echo /sys/class/thermal/thermal_zone7)
CPU_TEMPERATURE="$CPU/temp"
PROFILE_BALANCED="balanced"
PROFILE_POWER_SAVER="power-saver"
PREVIOUS_PROFILE=0
CURRENT_PROFILE=0
CURRENT_STATE=0
while true; do
if (( CURRENT_STATE < 0 )); then
CURRENT_STATE=0
fi
if [[ $(cat "$CPU_TEMPERATURE" | grep -Po "^..") > 75 ]]; then
((CURRENT_STATE+=1))
else
((CURRENT_STATE-=1))
fi
if (( CURRENT_STATE >= 3 )); then
CURRENT_PROFILE=$PROFILE_POWER_SAVER
fi
if (( CURRENT_STATE < 2 )); then
CURRENT_PROFILE=$PROFILE_BALANCED
fi
if [[ $PREVIOUS_PROFILE != "$CURRENT_PROFILE" ]]; then
powerprofilesctl set $CURRENT_PROFILE
PREVIOUS_PROFILE=$CURRENT_PROFILE
if [[ $CURRENT_PROFILE == $PROFILE_POWER_SAVER ]]; then
sleep 300
fi
fi
sleep 3
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment