2018/03/02

is your Mac waking on its own, draining battery and then just plain powering down?

I've twiddled every setting I can find, and this still happens:

  • I close the lid of my MacBook,
  • Carefully listen for the fan to stop...
  • (Wish they'd kept the pulsing LED; that was an excellent design.)
  • And only _then_ do I put it in my bag.
  • Some time later, I pull it out - to find it hot and/or powered off. Yuck. :(
(Kudos to Apple for constructing macOS so solidly, that even when it powers down unexpectedly (still sub-optimal), it actually does come back quickly - even with unsaved work, ready to pick up where you left off. Nice.)

Recently, I've been watching this strange sleep behavior even more closely, and several times have witnessed this sequence:
  • Close lid & listen for fan to stop...
  • Keep listening; after a few more moments, the fan starts again!
  • This sequence repeats
This seems to be new-ish behavior; as of the last few releases of macOS.

I've done everything I can find (details below), to get it to _stay_ asleep, but to no avail.

However I just found something new; from the man page of the pmset command:
ttyskeepawake - prevent idle system sleep when any tty (e.g. remote login session) is 'active'. A tty is 'inactive' only when its idle time exceeds the system sleep timer.

Yes; if I've got an ssh connection open to a remote host, for a command-line, I do indeed not want it to sleep - _except_ here's the new (to me) part:

ttyskeepawake is apparently for _any_ TTY - _not_ just those open via Terminal, as one might think; see the output, as a result of turning ttyskeepawake off:

Warning: This option disables TCP Keep Alive mechanism when sytem is sleeping. This will result in some critical features like 'Find My Mac' not to function properly.
Example command to turn it off (for all power sources):
pmset -a tcpkeepalive 0

I'll try this over some time, to see if my MacBook finally does stay asleep, safely...

Feedback / suggestions welcome!

3/12 update: Apparently the "sudo pmset -a standbydelay 259200" setting must be performed _while on battery_; if done while on AC / wall power, the on-battery setting is not affected. :/

 - - - 

Other settings I use (each on a single line), to try to make it sleep quickly, _and_ stay asleep:

sudo pmset -a hibernatemode 0 # do NOT use Safe Sleep; saving time to sleep (and save disk space), by not writing /var/vm/sleepimage
sudo pmset -a standbydelay 259200 # 3 days of sleep, before moving from sleep to hibernate - MUST BE DONE WHILE ON BATTERY
sudo nvram boot-args="darkwake=0" # disable "Dark Wake" (requires reboot)
sudo pmset -a womp 0 # disable "Wake On Magic Packet" (AKA "Wake-on-LAN", AKA "Wake for Wi-Fi Network Access" on recent MacBooks; also seen in the Energy Saver pane in System Preferences)
Also: A command line that I use, to see what the pmset log has, since the most recent sleep event:
telltale='Entering Sleep state'; lastSleep=$(pmset -g log | fgrep -i -e "$telltale" | tail -1 | sed "s/${telltale}.*/$telltale/"); if [ "$lastSleep" ] ; then pmset -g log | sed -n "/$lastSleep/,\$p"; else echo '[WARN: Did not find a Sleep event]'; fi