MacOS – How to find out what is keeping the Macbook from sleeping

macbook promacosNetworksleep-wakewifi

My Macbook will drain of battery when it's not plugged in. I thought it was a bad battery (it says it needs serviced) but even if it's a bad battery it should not be taking power when the lid is closed and it's in a sleeping state.

I figured it must be software since it's been software that sometimes prevents my computer from restarting (usually because I have an unsaved document):

"Application X has prevented shut down of your computer."

But I also figured that if software was preventing the computer from sleeping that I would see the same message, "Application X has prevented your computer from going to sleep". But I've seen no message!

But I've been working on an app recently that requires an internet connection and this is what I see in the console after opening the lid to my laptop after a few hours:

The network has changed! You may now be connected or disconnected. 19:47:48
The network has changed! You may now be connected or disconnected. 19:48:11
The network has changed! You may now be connected or disconnected. 20:48:33
The network has changed! You may now be connected or disconnected. 20:48:56
The network has changed! You may now be connected or disconnected. 21:49:14
The network has changed! You may now be connected or disconnected. 21:49:39
The network has changed! You may now be connected or disconnected. 22:49:59
The network has changed! You may now be connected or disconnected. 22:50:25

It looks like something is keeping the computer awake because the app I'm working on reports the network has been connecting and disconnecting.

What is keeping my computer awake? Or is it just a bad battery?

I'm running OSX 10.11.4 and Macbook AIR Mid 2011

UPDATE:
I have not checked if it occurs when it is not plugged in. I will do more testing. When it is plugged in, the network is enabled for about 25 seconds every hour, even when the laptop is closed.

UPDATE 2:
I ran pmset -g and this is what I get:

Active Profiles:
Battery Power       2
AC Power        -1*

Currently in use:
 standbydelay         4200
 standby              1
 womp                 1
 halfdim              1
 hibernatefile        /var/vm/sleepimage
 powernap             1
 networkoversleep     0
 disksleep            10
 sleep                0
 hibernatemode        3
 ttyskeepawake        1
 displaysleep         60
 acwake               0
 lidwake              1

Here is the results from using the assertions flag:

Assertion status system-wide:
   BackgroundTask                 0
   ApplePushServiceTask           0
   UserIsActive                   1
   PreventUserIdleDisplaySleep    0
   PreventSystemSleep             0
   ExternalMedia                  0
   PreventUserIdleSystemSleep     0
   NetworkClientActive            0
Listed by owning process:
   pid 102(hidd): [0x0002cf38000901c3] 09:14:50 UserIsActive named: "com.apple.iohideventsystem.queue.tickle" 
    Timeout will fire in 3596 secs Action=TimeoutActionRelease
No kernel assertions.
Idle sleep preventers: IODisplayWrangler

Best Answer

Try pmset -g. It will show you a list of process id's that somehow have hooked into the sleep or shutdown process.