Episode: 3536
Title: HPR3536: Laptop power problems
Source: https://hub.hackerpublicradio.org/ccdn.php?filename=/eps/hpr3536/hpr3536.mp3
Transcribed: 2025-10-25 01:06:29

---

This is Haka Public Radio episode 3536 for Monday the 21st of February 2022.
Today's show is entitled Laptop Power Problems.
It is hosted by Andrew Conway and is about 23 minutes long and carries a clean flag.
The summary is, this is a story of a laptop with two power problems.
Hello Haka Public Radio people, this is McNallu here, also known as Andrew, and I'm going
to tell you a little bit about my adventures with a laptop that doesn't know whether
it is plugged in to the mains or not.
Specifically, it thinks it's always plugged in even when it isn't.
I don't know when this started, but it probably had been going on for quite a while, and I hadn't
noticed because I have it plugged in almost all the time, so it's not a bad default assumption.
And of course I noticed this when I, on the rear occasion, when I had left it,
not plugged into the mains, and it came to my attention a few times that my laptop had
been mysteriously completely shut down and I didn't know why, and eventually I was sat at it
when this happened, and at the corner of my eye I noticed that the battery indicator was very low,
and I was rushing over to collect my mains cable, and then that's when it quit.
So I knew something was up, and then when I looked at it more closely, yeah,
indeed the problem was, the laptop thought it was plugged into the mains all of the time,
and occasionally would also give me a message along the lines of,
um, your laptop is plugged in, but it's still discharging, your power supply is insufficient,
isn't that kind of thing? I was using Slackware current at the time, and I was KDE that was
a little widget in the bottom right of the screen on the taskbar that was telling me that.
Now also, another problem I had with the laptop is sometimes it would just stop charging
the battery. Again, I didn't notice this because I have it on mains power most of the time.
I mean, that may be the problem, maybe I should, you know, I think it's good practice to
let batteries discharge and charge up again rather than sitting there plugged into the mains the
whole time. So yeah, it could be my fault. So I actually ordered a new battery, um, but
bit annoying the way that happened is that the company was the only one that said they could get
a battery to me within the week, so I took that, and the rest were all low. It must come from China,
I suppose, so it was going to take over a month. And of course, the one that said they could
live within a week couldn't. So I gave up and then cancelled the order, and then the very next day
that battery arrived, but by that time I'd already ordered one from China, and I presume it's from China,
I don't really know. And anyway, mysteriously that did arrive two weeks later, so I ended up with two
batteries. Anyway, so I swapped the battery and thinking, hoping that that would solve my issues,
but alas, it didn't. It seemed that whatever the issue was, it was the charging circuit, not the
battery. I mean, the battery was not in great condition anyway, it could only charge up to
something like 64% of its factory rated capacity, so the battery did have that problem, but the other
problems I was experiencing, I think are related to either the power connector or some electronics
on the motherboard. Now I had ruled out the operating system because I started up other OSs
on the same laptop, and they all reported the same symptoms, including Windows, a radically
different OS from Linux, so I was quite certain that this was a hardware issue on my laptop.
Okay, so now I accept that the laptop has a hardware issue. What could be done? Well,
well, the first solution was that I noticed that I could get it to start charging again,
say if it got stuck at 34% or something like that, or more wordingly a few times it got stuck at 0%,
so you know, it's definitely just jostling of the mains cable because it's quite immediately,
couldn't charge the battery at all. So the solution to that was it's an ASUS EP,
certainly not EPC, an ASUS ZenBook, like the UX 550, something or other, there's some letters after
that as well. I don't think that's so crucial, but with this series of ASUS ZenBooks anyway,
what you can do is there's a power button, which is actually looks like a key in the keyboard,
if that is a key in the keyboard in the top right, which is very annoying because, you know,
obviously you could jab at my mistake, that should be recessed and put out in the corner like
most laptops. But anyway, that great beside what you need to do is shut down the, well, I think
you have to shut it down, plug it into the mains and hold that power button for a long time. Now,
I think there may be two time lengths that are crucial here, there may be a five second,
maybe a 10 second, I think maybe also there's a 40 second. Anyway, I don't know,
I don't know which one it is, but certainly if I held that power button down for 40 seconds or
slightly more, then when the laptop wakes up again, it seems to have wiped all its battery knowledge,
I reconfigures itself and then it will allow itself to charge the battery again. That's why,
so the battery charging problem I can get around by doing that and it happens only rarely,
it's not common I need to do that, you know, and since I don't often restart my laptop,
that's probably why it's not common. So, there's that. Now, the more serious problem is that
because the battery thinks it's plugged in, sorry, the laptop thinks it's plugged in all of the time,
it never warns me or takes that it's running low in the battery and it never takes any power
saving measures either. Now, I can do, you know, I can manually intervene, you know, by when I'm working
at it on battery, keep an eye on the battery indicator, but that doesn't really work because I'm sure
like many of you hackers over there, I get quite engrossed to what I'm doing and I'm not looking at
the battery indicator, I really need it to sort of slap me in the face and say, look, look, I'm at
10%, you better plug me in right now, or you're, I'm going to quit the hard way.
So, and that's not good, let's face, it's not good to quit the hard way, it may have been a factor
in the fact that this laptop, it's previous drive, which I think I did another APR episode about,
it failed, it may have been a factor in that quitting mid-right or something, I don't know how
these SSD works, all these SSDs work these days, in detail, but I can't imagine it's a good thing
to be, you just have the power cut from the battery at hardware level because it's run out of juice.
Anyway, so I need to do something about this, well, I started poking around and when you look at
the stuff that KDE tells me about the battery, it seems to be just coming from
the information that you will find under, let me just quickly look up the,
let's see, so let me see, I'm typing cat slash cis slash I think it's power underscore supply,
no it's not, it's slash cis slash class slash power underscore supply, and then you could
have a choice of two directives, AC zero or bad zero, so I'm going to go for bad zero, and then
I think, yeah, I'll go for status, yeah, so there's a pseudo file, it's not really a file, it's a
file that's in CISFS, the laptop has, sorry, the Linux kernel is created for me, and the status file
has got one word inside it, and it's charging, and that's, at the moment, it's correct, the laptop
is in fact charging, now the problem is, if I disconnect the power cable, that file status should
contain discharging, but it doesn't, it contains the word charging always, no matter whether
the cable is plugged in or not, whether it's charging or discharging in reality, and various other
numbers that I see in there, when I look at the big beneath the immediate UI of KDE, going to
deeper energy settings, well it's still in a UI, but just deeper down, it seems to be pretty much
reading what's in under that slash cis slash class, slash power supply, slash bad zero, slash
in all those files, so I scratched my head for a while, now those files are not real files are
created by the Linux kernel, allowing you to see what's going on in other applications, so I
thought, well, maybe I can fool KDE into seeing other routines, so what I did, my first attempt was,
I used an an overlay file system, and I mounted that bad zero subfolder, or sub directory,
under that slash cis, just there, and if I write, for example, to the status file, and put the word
discharging in it, then anyone that tries to look at that file will then see the overlay version
of the file, not the actual file underneath, now you have to be careful because you don't want to,
I think maybe you could destabilize your system by spoofing entries there, but here I'm
making sure that I only just alter a few select files in the bad zero, and files which I know
are giving in correct information, so I didn't think that, as long as I'm careful, I don't go
scrubbing other directories, an overlaying, willy nilly, all over the place, then I should be okay,
now just the details of how I do that, so what I did was, use the overlay, I used just a mount
command, so it's mount minus T overlay, then overlay again, I'm not sure why it says overlay twice,
minus O, lower der, and then that is the path to the bad zero folder, and then upper der,
that is a path to another folder which contains my spoof versions of the files, and then it has to
be another option, comma work der equals, and then that's just some space anywhere in your system,
where it can do working for this, and then I think the final argument is as normal with
where you want it mounted, and I want it mounted over the top of that bad zero folder, so what I'm
really saying is there's a real directory on the bottom which is that bad zero directory,
then there's my directory which overlays it which can contain a few files, which spoof
the files that are really there, and then I'm telling the mount command that I want this to go over
the top of the existing bad zero directory, so it's a bit, it's a little bit confusing, I don't
even quite remember how, why that command structured the way it is, but if you read the documentation,
you'll get it working, so yeah, I mean I think hopefully you get the idea of an overlay,
so I did this, and I would say I got partial success, sometimes it would take notice of
the fact that I'd spoofed the status file, and sometimes it wouldn't, and when I say it, I mean
the KDE widget, but the power widget in KDE, now I suspect the reason it wasn't working consistently
is because it doesn't pull that file, it doesn't go to that file, that file, and say what is your
value, instead, it maybe looks at that file sometimes, maybe it started up when KDE starting up
or something, and so there's a smoke alarm, just made a noise there, I think it's a smoke alarm.
I think the way the KDE power widget on the desktop works is that it's probably
tuned into events to do with power from somewhere, now I did a lot of reading KDE and the
Linux kernel, and I filmed lots of confusing information, I didn't find a way for me to be able
to intercept those events or spoof them for that matter, and I felt like that's a, after I
spent maybe a good hour on that, I decided that that was a rabbit hole that I was going to reverse
out of, so instead my second solution, which I had in mind as well, is some way less elegant
in that I have to stop using that KDE widget, other than as a battery meter, it will tell me
correctly how much power is left in the battery, how much charge is left in the battery, but it
won't tell me whether it's charging or discharging or not to find me if the battery is getting low,
so instead what I did was I went and created a script, now I did this first as
root, just as a, as a test, now what I do here is also in that slash sys slash class slash power
slash slash band zero directory, there's another file, um, called energy, uh, now, um, and what I did,
and there's also power now, so energy now basically telling you how much charge is left in the battery,
and, um, and power on the score now, so energy on the score now and power on the score now,
power on the score now, tells you, I think it's really telling you how much current is drawn
from the battery or it could be power in what's, I haven't really, um, noted which number it is,
but what's crucial is if that number was greater than zero, the battery was being drained,
it's that it's like the current, it's some major of current or power being drawn from the battery,
so I could use that, I thought, uh, to detect whether the battery is in fact, um, being discharged,
and if it's discharged, it's not plugged into the mains, and if that's the case, then I can then
monitor energy on the score now, and when that gets, um, below a certain level, I can take some
action, now actually did try that, and, uh, it wasn't successful, it worked sometimes,
and then it didn't work other times, and the reason it didn't always work consistently,
is I couldn't rely on power on the score now to tell me whether the battery was in fact discharging,
so it seems that whatever problem has afflicted this laptop seems to have infected power on the
score now, or power on the score now isn't reliably updated, sometimes it's non-zero,
when the battery is being drained and sometimes not, I don't know, it's unreliable, it's the bottom line,
um, however, um, there is still another alternative route, and so what I did now was I wrote a little
bar script, and the bar script reads, actually uses the read command that's available to you in the
command line, so I would read energy one, energy one is available, less than sign, and then slash
this slash slash class, slash power supply and score supply, slash bat zero slash energy now,
then sleep one, so it sleeps for a second, and then reads, does the same thing again, but now reads
it into a variable code energy two, and by looking at the difference between energy two and energy one,
I can now tell, without any problem, without any cause of a potential misleading
problems occurring, whether the battery is being drained or not, if energy two is less energy one,
the battery is being drained, over a second it's bound to have decreased if the battery is not
plugged in, so and then also I discovered that in that bat zero folder there was another
file called capacity, which gives you just a percentage, it gives you a number between zero and a
hundred, and so I can use that actually to quite nicely decide when I want to take some action,
so what my script did initially is that when I got down to a low value, I've currently got
set it 20%, which is a bit conservative I know, but basically it suspends the laptop when it gets
to 20%, when the laptop gets less than 30%, it starts to let me know that it's about to suspend,
now at that point I can do a number of things, now I see it lets me know, well it was supposed
to let me know, but what I discovered was that I was using a command called notify send, which you
can issue that in the command line, and it will display a pop-up window to your user that I think
lasts for about five seconds by the fold, with a little text message, so my text message says
warning battery at whatever percent will suspend 20%, and then about a second before it does
the suspension, it will say about suspend, and then it says delete the file slash time, slash the
to stop me from suspending, so you can see how this is working, it's looking at the file slash temp,
slash suspend, as this flag to say, I'm going to suspend if you don't delete this file, now
this is the final version of my script, earlier a version of my script had
it was unknown that time, yeah, so confusing myself, yeah, so what I did here is as root, I tried
to do that, but the problem was notify hyphen send doesn't work, because if you issue it as root,
root doesn't have a next window display or a graphical display, so it just doesn't do anything,
and I tried all kinds of things to try and tell at which display to send the message to,
and pseudo's, and S use, and all that, I tried everything I can to make it actually,
get it to display on my regular user account, when it wouldn't work, I just could not get to work,
so the solution to this was this script itself doesn't need to be run by root, nothing that it does
requires root privileges, so I run the script as my regular user, and then it all works,
when I say it works, if I type the command in the command line, you know, I issue it manually,
the command to run the whole script, it works perfectly, then of course I don't want to be running
this command manual the time, so I put it in a cron job, and then in the cron job, it all works,
except it won't suspend the laptop, and the reason is, when running through a cron job,
for some reason I don't quite understand, the user loses the ability to suspend the system,
only root can do that, so that is where this whole slash temp slash suspend file came, so what
it does, when it wants to, when it's time suspend, it writes that file, just as a regular user,
temp is written by anyone, and then another script that's run by my root user, it's a very simple
script, all it does is it looks to see if there's that file slash temp slash suspend exists,
if it does, then it waits for one second, I can't remember why it waits for one second,
there's a good reason for that, I think if there's something to give it, run to a log file,
just give it extra time, and then it issues the command log in CTL suspend, and then that will suspend
my laptop, so that's that's how it worked, now the first time I wrote this script,
I, the laptop was well, with no well below 20%, and then I plugged it in,
and it was all working fine, and then one minute later, it shut down again,
you know, I don't know why it's done that, and then so I started it up again, but it's suspended,
so I took it out of its suspense, and another one minute later, don't it went again,
I went back into the suspended, it's been suspended, and I thought why is this happening,
but of course nothing removes that file slash temp slash suspend, now in my hey, then I started
up again, but at this point I completely forgotten where this file was, I know it actually does
notify me, but I think maybe at that time it didn't notify me that I could delete that file,
so I just completely forgotten where this file was, and then I had one minute to start up the
laptop on the command line, go and find my script, find where I put that file, then go and delete the
file, now that doesn't sound like you should take a minute, but somehow I don't know, it did,
and so I had this ridiculous kind of like the ridiculous groundhog day thing, when my laptop
was to suspend itself, come back to life, and then I would have this short time to find this
file and delete it so it wouldn't do it again, and yeah, it was quite amusing, it was a bit like
one of the stories you might get in Doctor Who, where you're stuck in a time loop anyway, so that's
why now the script that root runs, the first thing it does, when it finds that file slash temp such a
spend, it deletes it, so that if you do wake the laptop up again, then and you've plugged it in,
and that file doesn't get recreated, it won't immediately go back to sleep again, yeah, so it might
have been that I had less than a minute programmed in as well, at first I don't recall, but anyway,
it was, it was quite funny for a while, somewhat frustrating, so, so the push comes to shove,
it's now working really nicely, my laptop can get down to whatever percent I like, it will start
to notify me that it's getting low, and then it'll get down to another percentage and it'll just
suspend, so if I've wandered off and I'm on a phone call or I've been distracted and left my
laptop in battery, I'm pretty confident it will shut itself down, and of course as this is done
by a cron job, it's nothing to do with KDE or anything, it's quite a, you know, a low-ish level
solution, it doesn't matter, I could have it running in just a shell, you know, with no
graph, you know, no X windows or whatever, and this would still work just fine, I'm not relying
on anything else, so yeah, so it's not ideal, you know, and I've lost all the ability to
use KDE's power facilities on this laptop, but I don't really care, I didn't lose many of them
anyway, so that's my little story, so over to you, is there a better way to think I could do this,
can I intercept events and get KDE system working again? Do you know, can you tell me how I can
intercept those events that KDE's listening out for? If you know that, please do tell me or
record an HPR, show a belt to to ensure that people might find that interesting, thanks very much
for listening, bye-bye!
You've been listening to Hacker Public Radio at HackerPublicRadio.org. Today's show was
contributed by an HPR listener like yourself, if you ever thought of recording a podcast,
then click on our contribute link to find out how easy it really is. Hosting for HPR is kindly
provided by an honesthost.com, the internet archive, and our sync.net, unless otherwise stated,
today's show is released under a creative commons, attribution, share a like, please leave us
