You are not logged in.

#1 2016-03-23 07:12:18

louiek
Member
Registered: 2016-03-22
Posts: 1

T61 ultrabay battery discharge behaviour

Hi everyone,

First time poster and recent converter to linux. As the title states, I have a T61 thinkpad with an ultrabay battery. I wish to change the batteries' discharging behaviour. The default setting is to discharge the smaller ultrabay battery first before draining the main larger battery. Furthermore, the main battery is charged first while the ultrabay battery (after being completely drained) will recharge afterwards. This results in increased wear of the ultrabay battery, which has been documented on other forums.

My goal is to always drain the main battery first and reserve the ultrabay battery as a backup to maintain charge while swapping out the main battery. This is similar to more current thinkpad battery bridge system behaviour.

Therefore, I wrote (with my beginner bash skills) a script and systemd unit to achieve this goal. I am writing this post to 1) share my script so that other people may benefit from it; and 2) to see if anyone more experienced can improve or even suggest a better way to achieve the same outcome.

This script was tested on a T61 running linux 4.4.5-1 kernel and tp_smapi 0.41-81. The script is based on using tp_smapi's forced discharge setting to force the main battery to discharge.

my /usr/local/sbin/script

#!/bin/bash
STATE=$(cat /sys/devices/platform/smapi/ac_connected)
BAT0=$(cat /sys/devices/platform/smapi/BAT0/remaining_percent)
BAT1=$(cat /sys/devices/platform/smapi/BAT1/remaining_percent)
BAT0F=$(cat /sys/devices/platform/smapi/BAT0/force_discharge)
if [ $STATE  == 0 ]; then
    if [ $BAT0 -gt 15 ]; then
        echo 1 > /sys/devices/platform/smapi/BAT0/force_discharge
    else
        echo 0 > /sys/devices/platform/smapi/BAT0/force_discharge
        if [ $BAT1 -le 15 ]; then
            echo "warning low batteries; find the nearest power outlet and charge me or fucking poweroff"
        fi
    fi
else
    if [ $BAT0F == 1 ]; then
        echo 0 > /sys/devices/platform/smapi/BAT0/force_discharge
    fi
fi

This script is activated by this /etc/systemd/system/*.service

[Unit]
Description=regulates the discharging behaviour of batteries

[Service]
Type=oneshot
ExecStart=/usr/local/sbin/ultrabay-battery-discharge-regulation

This .service file is triggered by a /etc/systemd/system/*.timer every 30 seconds

[Unit]
Description=regulates the discharging behaviour of batteries

[Timer]
OnBootSec=0min
OnCalendar=*:*:0/30

[Install]
WantedBy=multi-user.target

My only gripe with this setup is that it consumes ~1-2W (powertop estimate) as it is continuously running the script every 30 seconds. I originally intended to use a .path unit instead by checking tp_smapi's /sys/devices/platform/smapi/ac_connected file. I thought that a PathModified .path file would be able to check for this file to determine AC connection, and if changed will invoke the .service file which in turns activates the bash script.

If anyone has any suggestions on improving or providing a much better approach, I would really appreciate it. I note that there is a script written on the thinkwiki page on how to use ultrabay batteries, but I would rather not use both batteries continuously.

Anyways, thanks for reading and I really appreciate this forum for all the insights and things I borrowed thus far.

Last edited by louiek (2016-03-23 07:22:09)

Offline

Board footer

Powered by FluxBB