Sometimes you’ll have situations, where macOS won’t go to sleep. To determine, what causes the absent from sleep, you can issue following command

sudo pmset -g assertions

this will give you something like that:

2015-11-17 08:04:25 +0100
Assertion status system-wide:
   BackgroundTask                 0
   ApplePushServiceTask           0
   UserIsActive                   0
   PreventUserIdleDisplaySleep    0
   PreventSystemSleep             0
   ExternalMedia                  1
   PreventUserIdleSystemSleep     1
   NetworkClientActive            1
Listed by owning process:
   pid 58(powerd): [0x000000040008012c] 10:43:06 ExternalMedia named: "com.apple.powermanagement.externalmediamounted"
   pid 92548(AddressBookSourceSync): [0x000096a700010b0f] 00:00:06 PreventUserIdleSystemSleep named: "Address Book Source Sync"
	Timeout will fire in 1793 secs Action=TimeoutActionTurnOff
   pid 92546(cupsd): [0x000096a800110b11] 00:00:05 NetworkClientActive named: "org.cups.cupsd"
Kernel Assertions: 0x4=USB
   id=500  level=255 0x4=USB mod=01.01.70, 01:00 description=com.apple.usb.externaldevice.fd140000 owner=USB Receiver
   id=501  level=255 0x4=USB mod=01.01.70, 01:00 description=com.apple.usb.externaldevice.fa140000 owner=My Passport 0820
Idle sleep preventers: IODisplayWrangler

In the first section we see what types of applications prevent the deserved sleep. In the second part, you’ll see what applications are preventing. You can issue this command a few times, because some applications will disappear, because they are done, in my case the addressbook synchronization will be comleted soon. But I find the cupsd process more interessting. Why is the macOS/LINUX print service prevent the sleep of my Mac? Having a look at the printer spooler/queue, reveals a print job not yet finished, because the printer run out of paper. After killing that job, the cupsd assertion went away and the Mac goes to sleep like a baby 😄.