Please note that I've no wake-up schedule, wake from network is unchecked, and powernap is also unchecked. I've also disabled any sharing service.

How can I resolve this problem? I want to use sleep mode without disabling wifi and without losing 20% of battery overnight…

UPDATE: It seems that Apple has fixed the battery drain (in sleep mode) in macOS Sierra (10.12). But the macOS Sierra update didn’t fix the problem for me. It just introduced a new problem to my solution (posted below). Now with Sierra, The SleepWatcher program doesn't always execute the wake-scripts when waking up, resulting in a delayed enabling of the Wi-Fi (sometimes up to 45 seconds after a wake).

When I look in my logs, I can see that it connects to 17.143.161.166 on port 5223 and to 17.110.229.212 on port 5223. These are IP-addresses owend by Apple Inc. located in California (according to ipinfo.io). I don't know why this happens...
– Kevin De KoninckNov 29 '15 at 10:49

6 Answers
6

I found a fix. Seems that 2015 and 2016 MBPs are affected. This required disabling SIP and changing a system setting. I reported the bug to Apple so hopefully they'll fix it sometime soon. Please report it to them as well since any changes you make will be probably reverted with a system update.

Right click on the file > get info, and change permission for 'Everyone' to read and write (or edit this using sudo chmod a+rw *.plist). Then change these key values with a text editor so that they match these settings:

This is a great solution and works! I'm glad someone found a real fix. Thanks for sharing!
– Kevin De KoninckFeb 9 '17 at 18:54

I applied your fix when Sierra came out. Recently I upgraded from Sierra to High Sierra and these settings went back to the default: true/true/false. My MBP 13 early 2015 started waking up every hour or so during the night again. Applied the fix again. Looks like Apple didn't fix the problem?
– Luca GibelliOct 13 '17 at 13:36

I didn't found the exact cause of the problem, but I did found a solution which will avoid massive battery drains in sleep mode. The solution was to disable Airport (WiFi) when the Macbook was sleeping.

I used SleepWatcher v2.2 (http://www.bernhard-baehr.de) to run 2 scripts at wake and sleep interrupts. When the macbook goes to sleep, I execute the following command to disable WiFi:

/usr/sbin/networksetup setairportpower en0 off

When the Macbook wakes up again, I enable WiFi again:

/usr/sbin/networksetup setairportpower en0 on

You can download a script that installs SleepWatcher and the scripts at a blog post of mine (No ads located on the page).

Please note that in the original question of mine I said that I didn't want to disable WiFi constantly when putting the Mac to sleep. This solution does the same, but automatically, which makes it a good solution for the battery drain.

I wonder, when Apple is going to fix that. I had the same problem since some update, your solution fixed it for me, thanks, but I'd love to be able to just pop my laptop open and start working, not wait a few seconds for WiFi to warm up.
– dotzJul 24 '16 at 12:16

I changed the wake up time from 7 seconds to about 3 seconds. You can experiment with the time, maybe it isn't necessary, but I've included it just to be sure. I've also updated the sleep and wakeup scripts on my github (added intelligent switching). Personally I don't think Apple is going to fix this. I wonder if they even now about this bug...
– Kevin De KoninckJul 25 '16 at 13:12

Sierra seems to fix this for me, past few hours I disabled your scripts and I still have some battery left. Sometimes I had useable (known) WiFi network in range, sometimes I didn't. What is your experience after upgrading to Sierra?
– dotzSep 22 '16 at 12:11

I disabled my script yesterday and charged my macbook to 100% and then I disconnected the power cable. I've put it to sleep at 00:25 AM and at 4:45 PM, I started my macbook again and it still had 100% battery left... So yes, I think Sierra has fixed this for me too. Thanks for pointing out!
– Kevin De KoninckSep 25 '16 at 14:47

Thanks for your scripts, which saved my ass for last 6 months or so. I suggest you update your original question somehow. There is almost no information on the net about this issue. Also... it may be re-introduced after some updates, because why not...
– dotzSep 25 '16 at 19:33

Does your machine support Power Nap? As I understand, this function causes the computer to wake at certain intervals to do things like check email but still keeps power use to a minimum. I'm not sure if it uses an RTC alarm to do this or not.
https://support.apple.com/en-us/HT204032

It does support Power Nap, but I've disabled it in Energy Saver Settings. When I look in my logs, I can see that it connects to 17.143.161.166 on port 5223. This is an IP-address owend by Apple Inc. located in California (according to ipinfo.io.
– Kevin De KoninckNov 29 '15 at 10:46

1. Start Automator, and create a new Service.
2. Set "Service receives selected: to "no input" in "any application".
3. Add an action named "Run Shell Script". It's in the Utilities section of the Actions Library.
4. Insert the bash command you want into the text box and test run it using the Run button (top right). It should do whatever the script does (off, on or toggle), and there should be green ticks below the Action.
5. Save it, giving it a service name you can remember.
6. Go to System Preferences -> Keyboard, and go to the Shortcuts tab
7. Go to the Services section, and scroll down to General - you should find your service there. If you select the line, you can click "add shortcut" and give it a keyboard shortcut.