Program to disable charging

Discussion in 'Mac Programming' started by spt, Nov 5, 2013.

  1. spt, Nov 5, 2013
    Last edited: Nov 5, 2013

    spt macrumors member

    Joined:
    Oct 27, 2009
    #1
    I would like to make a program that gives the user the option to stop charging at a battery level of 80% (or any other configurable percentage).

    I was under the impression that I could do this by setting the power management ChargeInhibit flag to 1 using IOPMAssertionCreateWithName (from the IOKit library). Setting this flag is no problem (pmset shows that it is enabled by my test application), but the system seems to simply ignore this and still continues charging to the full 100%...

    The part in my code that is related to my question is as follows.
    Code:
    #define kIOPMAssertionTypeInhibitCharging       CFSTR("ChargeInhibit")
    #define kIOPMChargeInhibitAssertion             kIOPMAssertionTypeInhibitCharging
    
    IOPMAssertionID assertionID;
    
    IOPMAssertionCreateWithName(kIOPMChargeInhibitAssertion, kIOPMAssertionLevelOn, kIOPMAssertionTypeInhibitCharging, &assertionID);
    So any ideas on how this can be done?


    The reason for doing this is that battery wearing will be reduced to a very low level if you always keep it charged somewhere between 40 and 80% while at the same time discharging and charging it a bit every day to keep the electrons moving. I mostly use my system on battery power while commuting, and at home for a few hours now and then, but I think if I could automate not charging beyond 80% I would almost always keep an optimal charge at no cost at all. If, on the other hand, your Li-ion batteries are at a 100% charge a large part of the time, they will slowly deplete over time even when you never deep discharge it. Particularly as I quite often use my computer for statistical analyses: it is bad for Li-ion batteries to get hot when fully charged.
     
  2. robvas macrumors 68020

    Joined:
    Mar 29, 2009
    Location:
    USA
    #2
    I know this doesn't answer your question, but Apple already has this figured out. For example, your battery may stop charging at 97% and indicate that it's 'full' when obviously it is not at 100%.

    http://www.apple.com/batteries/notebooks.html
     
  3. spt thread starter macrumors member

    Joined:
    Oct 27, 2009
    #3
    I've already read a lot of information about Li-ion batteries (also from scientific research), so I'm quite sure that a program like a I proposed would substantially reduce wearing.

    My new rMBP seems to always start charing, unless it has lost only a few mAh's of charge and is still at 100%. The problem is basically that the batteries will generally be 100% charged when working on AC power, which is actually not optimal and causes the battery capacity to slowly degrade.

    I have more or less given up the idea, however, because I don't think I'm going to get a technical answer to my question. It would be fun though if this would keep battery health close to the factory condition for extended periods of time.
     
  4. robvas, Nov 6, 2013
    Last edited: Nov 6, 2013

    robvas macrumors 68020

    Joined:
    Mar 29, 2009
    Location:
    USA
    #4
    I understand where you are coming from because Lenovo has a similar feature on their Thinkpads. Apple recommends you go unplugged at least once a month (and recommends setting up a reminder to do so) and they also recommend you don't use the machine plugged in 100% of the time.

    Here's my problem with only charging to 80% by default: Assuming I will shut down when I reach 5%, I now only have 75% of my battery to use when I unplug. So for an 8-hour battery I'm down to just 6 hours!

    I have to then change software settings and wait another 60 minutes for my battery to finish charging to 100%. That's very inconvenient.

    In the end I don't care if I'm charging the battery more than I should be - I want full use of my laptop when I am unplugged. If the battery is damaged or shows severe wear while I am under warranty I trust Apple to replace it. I've also been using my Macs in that way with no manual interaction when it comes to charging for 4 years and never had any issues.
     
  5. spt, Nov 6, 2013
    Last edited: Nov 6, 2013

    spt thread starter macrumors member

    Joined:
    Oct 27, 2009
    #5
    Yes, but the problem is that after a few years you will be down to 6 hours permanently. On normal days, it doesn't matter that much for me whether a have to get up from the couch to get the charger at 19:30, or at 21:00. I have to get up and plug it in at some time and it's therefore just a small inconvenience that we have anyway. However, once or twice a month I'm somewhere for a day where I can't recharge and in those occasions I would really like to get the maximum out of it. The problem with my previous MBP was that it still functioned perfectly (4 hours on the battery) after 3 years or so and therefore I didn't replace it yet, but when these 4 hours weren't enough I was forced to spend several hours watching through windows while doing nothing...

    Also, I don't agree that clicking on something in the status menu to enable charging to 100% would be that inconvenient. What's inconvenient is having had a working day from 7:00 to 20:00 (well, including dinner :) ), and then when you are finally on your way home you find out that you have to spend the 2 hour trip back home boring yourself to death rather than reading an ebook, watching a movie, browse the internet (or perhaps do more work).
     
  6. Giuly macrumors 68040

    Giuly

    #6
    You should do some observations, because real-world degradation is a mere 1-2% per year on AC for a MacBook.
     
  7. spt thread starter macrumors member

    Joined:
    Oct 27, 2009
    #7
    Not to offend anyone, but it's really sad that this thread seems to be used by people expressing their (mostly uninformed) opinions on whether the program I would like to make is useful or not.

    If anyone has anything technical to say, I would be very grateful as I don't think I can solve this myself.
     
  8. Giuly, Nov 6, 2013
    Last edited: Nov 6, 2013

    Giuly macrumors 68040

    Giuly

    #8
    I'm expressing the empirical results that I obtained with CoconutBattery, which boil down to a 1-2% decrease in capacity per year on a MacBook Pro that runs exclusively on AC.

    But:
    [​IMG]
     
  9. ArtOfWarfare macrumors 604

    ArtOfWarfare

    Joined:
    Nov 26, 2007
    #9
    Battery Status actually mines a lot of information that it never presents to the user, but instead it keeps to send to me (the developer) for diagnostic purposes. I rarely see any batteries that have degraded to no longer be capable of holding at least 90% of their charge.

    Apple already stops charging automatically - with no indication given to the user - when they hit 100% and they let the computer run on battery power until it hits 80% or so. Then it resumes charging. During this time it says that the battery is at 100%, fully charged, and leaves the green LED on the charging wire turned on. There's no way for the user to realize they aren't at 100%, unless they use an app that uses APIs that calculate the value for themselves. Most users don't know about the problem with not exercising their battery, and fewer know that Apple's laptops already exercise it for them, and so most users would be alarmed if they saw their charge percentage fluctuating like that while they're plugged in.
     
  10. spt thread starter macrumors member

    Joined:
    Oct 27, 2009
    #10
    This is really interesting information. So you say that the percentage that is shown in the status bar does not reflect the actual battery status. That percentage is based on the current capacity which can be retrieved by programs like pmset (pmset -g rawlog), Coconut battery and is also shown in System Report -> Power. The percentage is exactly equal to floor('current charge' / 'factory specified max charge' * 100). But if these values are extrapolated, that would indeed explain why the system shows the status as 'charging' while that may actually be wrong.

    You say there is an API to use the true percentage: do you have more information on that or perhaps know where to find it? That would be very helpful for me.
     
  11. robvas macrumors 68020

    Joined:
    Mar 29, 2009
    Location:
    USA
    #11
    Well, we've been approached by someone who thinks they know better than Apple's engineers when it comes to battery charging ;)
     
  12. falcn macrumors member

    falcn

    Joined:
    Aug 6, 2011
    #12
    There is a hardware solution involving a piece of electrical tape
    http://apple.stackexchange.com/a/132332/50825
     
  13. ArtOfWarfare macrumors 604

    ArtOfWarfare

    Joined:
    Nov 26, 2007
    #13
    Placing and removing a piece of tape in the exact right spot seems like it would be a major PITA.

    Plus, as I understand, the OP wants the program to automatically inhibit charging when the battery is at a certain percentage, which it may reach when the user isn't paying attention.
     
  14. falcn macrumors member

    falcn

    Joined:
    Aug 6, 2011
    #14
    The solution is not perfect, but it works. I'm sitting at 45% of a battery charge for a whole week now.

    Applying/removing the tape is 5 seconds at most.
    I had used a piece of tape on my connector to dim the LED light for the past six years anyway. Since discovering the mid pin trick I just made myself a new patch with a 1mm wide strip hanging from it's side.

    The funny thing is that it improves the flawed Magsafe 2 as a side effect.
    With the tape running across the connector it sits in it's place sturdier, and no longer disconnects under the weight of the wire when moving laptop across the room.
     
  15. TerjeOseberg, Sep 3, 2014
    Last edited: Sep 3, 2014

    TerjeOseberg macrumors newbie

    Joined:
    Sep 3, 2014
    #15
    I followed your link and Apple says this:

    "Store it half-charged when you store it long term."

    And this:

    "Do not fully charge or fully discharge your device’s battery — charge it to around 50%. If you store a device when its battery is fully discharged, the battery could fall into a deep discharge state, which renders it incapable of holding a charge. Conversely, if you store it fully charged for an extended period of time, the battery may lose some capacity, leading to shorter battery life."

    This agrees with what everyone who knows about Lipo batteries says about them.

    http://batteryuniversity.com/learn/article/how_to_prolong_lithium_based_batteries

    It might be true or might not be that the OP knows more or less about Lipo batteries than the Apple engineers. But, regardless, I'm pretty sure that the first priority of the Apple engineers is that any time you unplug from the wall, you'll be able to use your laptop for as long as possible without having to take any special actions or spend any time waiting before you do so.

    Their second priority would be how long the batteries maintain their full capacity.

    The OP appears to have a different priority than the Apple engineers and therefor would rather keep his batteries at the 50% charge recommended on the page you linked to by the Apple engineers.

    What I've read is that if you keep a Lipo battery 100% charged and at room temperature it will lose 20% of it's capacity per year while if you keep it charged 50% it will lose 2% capacity per year. I'm pretty sure that the Apple engineers know this as well, since this is common knowledge for anyone who cares to look it up. That's probably why I found that quote above. Why would Apple say this if it were not true?

    I really hope that you guys who are arguing about the usefulness of a tool that allows the user to configure the charge at which the battery will stop charging and rather work on figuring out how to build such a tool as I would like a tool like this for myself.

    I found this, which looks very interesting, but doesn't help with programming the MacBook Pro, but rather helps with reprogramming the battery. I'd prefer a tool that runs on the laptop rather than the battery. I believe it would be a lot simpler to install.

    https://media.blackhat.com/bh-us-11/Miller/BH_US_11_Miller_Battery_Firmware_Public_WP.pdf
     
  16. dubaaron macrumors newbie

    dubaaron

    Joined:
    Mar 31, 2016
    Location:
    Albuquerque, NM
    #16
    I agree that such a tool would be incredibly useful and helpful; I don't know why Apple hasn't included something like this already, since it seems like it would be a simple thing. Some sort of toggle, on the menubar and/or in preferences, to select between 'battery time maximization' and 'battery lifetime maximization' (would probably need to tweak those terms so as to be less confusing).

    I've wanted such a tool for years, and it's worse now that so many laptops have non-removable batteries.

    In the non-mac world, it's more difficult, because API access to functionality to stop the battery from charging, if available at all, has to be done at driver or BIOS level (as far as I understand). The only ones I know of that provide something to the user to control this are Toshiba and Lenovo (and Lenovo's seems like it's going defunct, as the driver lacks Windows 8 or 10 support).

    Seems like this would / could be easier for Apple, since the hardware and driver environment is so much more homogenous.

    Please, if anybody knows of or finds a way to do this, share with the rest of the world!

    Is Apple aware of the need for this? Do they care? I've seen so many older MacBooks that are perfectly good machines, but their batteries are completely trashed (i.e., won't function for even a second off the power cord) ... I'm using my new MBP as a desktop replacement, but don't want to trash the battery by keeping it plugged in all the time, nor by unnecessarily running it down all the time just to try to keep from always having it at or near 100%.
     
  17. robvas macrumors 68020

    Joined:
    Mar 29, 2009
    Location:
    USA
    #17
    I think you guys are severely underestimating how much battery engineering Apple does.
     
  18. ToomeyND macrumors 6502

    Joined:
    Sep 14, 2011
    #18
    I think you are underestimating that Apple engineers its batteries for the masses who want things to just work, while the OP and others like him are willing to sacrifice some benefits now for benefits later. It's battery chemistry, and it applies to all lithium ion batteries right now.

    Also note that Apple is not in the business of selling you an item to keep for a long time.
     
  19. dubaaron macrumors newbie

    dubaaron

    Joined:
    Mar 31, 2016
    Location:
    Albuquerque, NM
    #19
    Maybe. I don't know. I hope so. I guess we'll see.

    I've just seen too many thrashed, dead, MacBook batteries, and I don't want mine to end up the same way if I can help it; and I know that not using the battery (when not needing it) will help consume less of the approximately 1,000 charge cycles that Apple claims the battery is good for; and that not keeping the battery at 100% constantly is better for lithium batteries. (Yes, I know, it's good to excercise the battery somewhat; but certainly exercising the battery constantly, as I would have to do to keep it at a reasonable charge level by constantly plugging and unplugging, would be more wearing.)

    Agreed on both counts. While Apple products can and do last a long time in many cases, the upgrade-itis pervasive throughout its culture makes it hard to do so, as newer software and content simply stops working or is no longer available for the older devices.

    ...

    At least, with the aforementioned hardware hack (taping over the middle pin of the magsafe), there is SOME WAY to do this, which can't be said for the increasing numbers of non-Apple laptops out there these days which don't have removable batteries. Lacking any other option for the moment, I'm going to try it.

    But Toshibas have automatic software for battery charge management -- I don't see why it would be so hard for Apple to put an option in there somewhere to maximize overall battery longevity instead of temporary capacity ... when you need maximum capacity for untethered days, switch it. For when we are primarily deskbound, switch it back. It's certainly more convenient than having a dead battery, or constantly having to watch the charge level and putting tape over a pin in the power connector.

    (Yes, I'm aware that many laptops use battery to help even when connected with AC for peak power demands, and that things might run slower with no battery, as well. This seems to me like a compromise probably driven by being able to have smaller AC power supplies, or maybe ideal charging wattage being lower than peak. In any case, not a factor in modern MacBooks with non-removable batteries.)

    Unless Apple has magically modified the chemistry of Lithium batteries or something in the design of the batteries so that they are not damaged by remaining at high and low charge levels, or deep discharges (which is doubtful -- by their own admission, they recommend keeping close to 50% for long-term storage), or they have built in a secret, unused 'reserve capacity' so that the batteries are really only at 80% (or something) when they display 100% (doubtful as well; given the competitive nature of the marketplace, everyone wants to be able to advertise as much battery capacity as they truthfully can) ... then I think the limitations of the chemistry still apply.

    I understand that temperature is also a factor, maybe at least as much as charge level ... and while I'm sure they do what they can engineering-wise about the temperature, I also know that my MBP gets quite hot while charging, and they've certainly sacrificed things like fans in favor of silent operation, sleekness, portability, etc. So I'm using a cooling fan pad when possible when charging, as well, and minding the surface that it's placed upon.

    ...

    Apple admits that the batteries are consumables. Why not let us try to consume them as little as necessary, if possible, maximizing the time that they'll last?

    (Obvious cynical answer: so that you'll need to buy a new battery (non-user-replaceable, according to Apple's ideal view, even though they can be replaced, with difficulty) or a new MacBook sooner than later ... hopefully it's not as blatantly greedy as that.)
     
  20. Alrescha macrumors 68020

    Joined:
    Jan 1, 2008
    #20
    Except that Apple's success is based on keeping people happy, not needlessly sabotaging their products.

    On topic, the only problem I have had with devices left plugged in 24/7 is that in all cases, the battery swelled up and required replacement (or destroyed the device) long before the charge capacity noticeably declined. The list includes multiple brands of cell phones and laptops.

    Since then, I have taken to making sure that all such devices get unplugged once in a while and run down to 80 or 90 percent before getting plugged back in. So far, so good. No swelling batteries in the past few years.

    A.
     
  21. dubaaron macrumors newbie

    dubaaron

    Joined:
    Mar 31, 2016
    Location:
    Albuquerque, NM
    #21
    Yeah, I hope so. I'd rather believe that was the case. Though they do seem to routinely sacrifice backwards compatibility and support for older devices, in favor of their vision of innovation, whether for better or worse. (For the record, I believe that both are possible.)

    That's interesting. Thanks for sharing.

    When you say you "run down to 80 or 90 percent" before plugging back in, do you mean down to 80 or 90, or down to 10 or 20 (by running them down 80 or 90 percent)? Sorry, just want to make sure I'm understanding correctly.

    And I wonder if heat is a factor in swelling-battery-syndrome? I've certainly experienced the swelling battery on cellphones, despite my charging precautions ... but cellphones are routinely kept in pockets, which provide little heat dissipation. Just thinking aloud.
     
  22. Alrescha macrumors 68020

    Joined:
    Jan 1, 2008
    #22
    Given that I am running the latest iOS and OS X on 5 and 7 year old hardware, I do not see a problem.

    I mean just using 10 or 20 percent before plugging it back in. A habit that works reasonably well for me is to unplug things on Friday night, use them over the weekend on battery, and plug them back in Sunday night. This is just for things that do not get unplugged routinely: the old cell phone that acts as the 'home phone', the laptop that hardly ever leaves the desk, etc.

    Heat is usually bad for everything, but cell phones in pockets should not be producing much.

    A.
     
  23. robvas macrumors 68020

    Joined:
    Mar 29, 2009
    Location:
    USA
    #23
    Are you guys aware that Apple uses 'intelligent charging' so that even if you only use 10-20% of the charge, it distributes the wear across the cells of the battery?

    Sure, there's a lot of Macs out there with dead batteries but there are a lot of people out there who will just let the battery run down until the laptop turns off. And of course you get a small amount of them with defective batteries, that's just how things work.

    Apple rates their batteries for 1,000 charges for a reason. And they rate them that way from the factory, under normal use, not some not-that-well-thought-out idea like only charging to 80%.

    Let's hop in the time machine, go back to 2009 and hear about what Apple actually does. The batteries aren't just plain old rechargeables.

     
  24. Alrescha macrumors 68020

    Joined:
    Jan 1, 2008
    #24
    Umm... this is how batteries work. Pretty much all of them.

    A.
     
  25. abhibeckert macrumors regular

    Joined:
    Jun 2, 2007
    #25
    The best way to make your battery last a long time is to leave it plugged into power and fully "charged".

    If you do this, then it will do exactly what the original thread starter was trying to do - cycle the charge between 80% and 100% spreading the load around all the cells to prolong battery life as long as possible.

    This only applies to a battery that is left in a drawer for months at a time and you should avoid doing so at all costs.

    Leaving a battery unplugged at *any* charge level will damage it. The best thing to do is have it plugged into mains power so the complex charge circuitry can keep things active and prolong the life of the battery. Messing with how this works using custom software is a bad idea.

    You're wrong. Not using the battery destroys it, the battery needs to be kept active, but not pushed very hard, to last as long as possible.

    "1000" charge cycles is an approximate estimate of how long the battery will last with "normal" use. As soon as you do something out of the ordinary, such as never use the battery, that number goes out the window and does not reflect how many charge cycles you're going to use.

    Bottom line, if you want the battery to last keep it plugged in as much as possible and do not try to mess with Apple's built in battery management, which is the best in the world.
     

Share This Page