{"id":44,"date":"2009-05-28T13:15:36","date_gmt":"2009-05-28T13:15:36","guid":{"rendered":"https:\/\/chroot-me.in\/newblog\/2009\/05\/44\/"},"modified":"2014-01-30T02:37:13","modified_gmt":"2014-01-30T01:37:13","slug":"lenovo-thinkpad-x300-battery-management-and-tp_smapi","status":"publish","type":"post","link":"https:\/\/chroot-me.in\/blog\/2009\/05\/lenovo-thinkpad-x300-battery-management-and-tp_smapi\/","title":{"rendered":"Lenovo Thinkpad X300 , battery management and tp_smapi"},"content":{"rendered":"<p>This article briefly presents a \u00ab\u00a0solution\u00a0\u00bb to the battery switching issue mentioned at the bottom of this <a href=\"http:\/\/chrooted-universe.org\/blog\/index.php\/blog\/26\">blog entry<\/a>.<\/p>\n<p>Indeed, while having two batteries ensures a (very) long battery life, you have to switch manually from the secondary battery to the primary, in order to prevent deep discharges that harms lithium batteries.<\/p>\n<p>Until now, I used to manage it by typing some aliases in my shell, but it is clearly not convenient nor reliable (Sometimes, I simply forget it).<\/p>\n<p>But now, one little bash script and one line in your root&rsquo;s crontable, and the job&rsquo;s done :)<\/p>\n<p>There is <span class=\"strikethrough\">battery_switch.sh<\/span> (deprecated, see <em>baswim.sh<\/em> below). It basically allows automatic switching to main battery when a given percentage level is reached by the secondary battery. Some parameters are available by editing variables values directly in the script, but only <strong>LOW_LEVEL<\/strong> is really interesting.<\/p>\n<p>The cron line I use:<\/p>\n<div class=\"cmd\">\n<pre># sudo crontab -e\r\n\r\n# m h  dom mon dow   command\r\n*\/5 *   *   *   *   \/opt\/bin\/battery_switch.sh<\/pre>\n<\/div>\n<p>Of course it is aware of your laptop&rsquo;s status. In fact, if it switched to the main battery (by forcing the main battery to discharge), and then you re-plug your laptop, it will cease to force discharge and will return to normal state.<\/p>\n<p>Since I may not be clear, do a<\/p>\n<div class=\"cmd\">\n<pre>tail -F \/var\/log\/battery_switch.log<\/pre>\n<\/div>\n<p>to get relevant information.<\/p>\n<p>I hope that will help :)<\/p>\n<p><strong>EDIT:<\/strong> please find <a href=\"https:\/\/ssl.chroot-me.in\/svn\/rboissat-foobar\/Bash\/baswim.sh\">there<\/a> <em>baswim<\/em> (<em>ba<\/em>ttery <em>sw<\/em>itching <em>im<\/em>proved) a new script that provides a *really* interesting feature: It permits to switch from one battery to another according to both <strong>remaining percentage<\/strong> and <strong>cycles count<\/strong>.<\/p>\n<p>It follows this simple scheme:<\/p>\n<div class=\"cmd\">\n<pre>1) Get batteries cycle status \r\n2) Decide which battery should discharge first based on cycles and remaining percentage\r\n(above the low_level) \r\n3) Get AC status\r\n3) If AC is unplugged, begin discharge with chosen battery\r\n4) If needed by long unplugged operation, switch to the other battery<\/pre>\n<\/div>\n<p>It basically a hack from the first script, there are some oddities (one line functions&#8230;) but hey it works (surprisingly)!<\/p>\n<p><strong>EDIT:<\/strong> A little but likely important update. This time, both scripts can handle two cases: one battery plus dvd-drive or both batteries.<\/p>\n<p><strong>EDIT:<\/strong><\/p>\n<p>If you want <strong>baswim<\/strong> to be a little more aware of acpi events,<\/p>\n<p>you can make some symbolic links in <strong>\/etc\/acpi\/battery.d<\/strong> and <strong>\/etc\/acpi\/ac.d<\/strong>.<\/p>\n<div class=\"cmd\">\n<pre>ln -s \/opt\/bin\/baswim.sh \/etc\/acpi\/battery.d\/\r\nln -s \/opt\/bin\/baswim.sh \/etc\/acpi\/ac.d\/<\/pre>\n<\/div>\n<p>Then, <em>baswim<\/em> will be executed every time you plug or unplug your AC.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This article briefly presents a \u00ab\u00a0solution\u00a0\u00bb to the battery switching issue mentioned at the bottom of this blog entry. Indeed, while having two batteries ensures a (very) long battery life, you have to switch manually from the secondary battery to the primary, in order to prevent deep discharges that harms lithium batteries. Until now, I &hellip; <a href=\"https:\/\/chroot-me.in\/blog\/2009\/05\/lenovo-thinkpad-x300-battery-management-and-tp_smapi\/\" class=\"more-link\">Continuer la lecture<span class=\"screen-reader-text\"> de &laquo;&nbsp;Lenovo Thinkpad X300 , battery management and tp_smapi&nbsp;&raquo;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7,4,2],"tags":[],"class_list":["post-44","post","type-post","status-publish","format-standard","hentry","category-english","category-geek","category-hacks"],"_links":{"self":[{"href":"https:\/\/chroot-me.in\/blog\/wp-json\/wp\/v2\/posts\/44","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/chroot-me.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/chroot-me.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/chroot-me.in\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/chroot-me.in\/blog\/wp-json\/wp\/v2\/comments?post=44"}],"version-history":[{"count":0,"href":"https:\/\/chroot-me.in\/blog\/wp-json\/wp\/v2\/posts\/44\/revisions"}],"wp:attachment":[{"href":"https:\/\/chroot-me.in\/blog\/wp-json\/wp\/v2\/media?parent=44"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/chroot-me.in\/blog\/wp-json\/wp\/v2\/categories?post=44"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/chroot-me.in\/blog\/wp-json\/wp\/v2\/tags?post=44"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}