Is your feature request related to a problem? Please describe.
When I'm using my USB-PD PowerBank I'd like to stay in the battery configuration and perhaps also stop charging the internal battery altogether. Unfortunately the PowerBank doesn't show up differently when looking at the udevadm monitor or lsusb output, but perhaps there are other power banks that share a USB identifier before negotiation the power delivery.
Describe the solution you'd like
A clear and concise description of:
When I'm connected to an external power bank
I'd like to stay in power-save mode
And disable charging of the internal battery
Describe alternatives you've considered
An alternative would be a way to send tlp a message to switch to a certain configuration, perhaps via udevadm trigger or dbus?
Alternative is to just run sudo tlp bat to switch to the battery mode and setting the charge settings with tlp or /sys/class/power_supply/BAT0/charge_control_end_threshold manually.
Alternative workaround for now. Run powerbank before or when connecting to a USB powerbank.
disables charging (except if you're really low on battery)
sets tlp to manual bat mode with tlp bat
listens with udev-monitor for the charger to disconnect
restores charging limits to previous mode
restores tlp to auto mode tlp start
Script uses sudo for when sudo is needed, alternatively remove sudo altogether and start the script with sudo itself
#!/usr/bin/env bash
set -ueo pipefail
bat="/sys/class/power_supply/BAT0/"
start="$(cat "${bat}/charge_control_start_threshold")"
end="$(cat "${bat}/charge_control_end_threshold")"
echo "0" | sudo tee "${bat}/charge_control_start_threshold"
echo "5" | sudo tee "${bat}/charge_control_end_threshold"
sudo tlp bat
UPOWER_AC_DEVICE='/org/freedesktop/UPower/devices/line_power_AC'
# props https://github.com/alba4k/.dotfiles/blob/e723af501e033e1e440a043f13616a301d72f675/.config/hypr/ac_detect.sh#L6
_ac_connected() {
dbus-monitor --system "type='signal',
sender='org.freedesktop.UPower',
path='$UPOWER_AC_DEVICE',
interface='org.freedesktop.DBus.Properties',member='PropertiesChanged'" \
|& grep --line-buffered -oP 'boolean \K.*$'
}
while read -r connected; do
if [ "${connected}" == "false" ]; then
echo "AC disconnected"
break
elif [ "${connected}" == "true" ]; then
echo "AC connected"
continue
else
echo "AC unknown"
break
fi
done < <(_ac_connected) # break in while does not work if you pipe into `read -r`
echo "Restore previous tlp"
echo "${start}" | sudo tee "${bat}/charge_control_start_threshold"
echo "${end}" | sudo tee "${bat}/charge_control_end_threshold"
sudo tlp start
Is your feature request related to a problem? Please describe.
When I'm using my USB-PD PowerBank I'd like to stay in the battery configuration and perhaps also stop charging the internal battery altogether. Unfortunately the PowerBank doesn't show up differently when looking at the
udevadm monitor
orlsusb
output, but perhaps there are other power banks that share a USB identifier before negotiation the power delivery.Describe the solution you'd like
A clear and concise description of:
Describe alternatives you've considered
An alternative would be a way to send tlp a message to switch to a certain configuration, perhaps via udevadm trigger or dbus?
Alternative is to just run
sudo tlp bat
to switch to the battery mode and setting the charge settings withtlp
or/sys/class/power_supply/BAT0/charge_control_end_threshold
manually.Alternative workaround for now. Run
powerbank
before or when connecting to a USB powerbank.bat
mode withtlp bat
udev-monitor
for the charger to disconnecttlp start