Find what's preventing Mac from sleeping

If Mac is failing to go to sleep or is waking up unexpectedly, you can run pmset -g log | egrep '\b(Sleep|Wake|Start)\s{2,}' in terminal to inspect last sleep/wake events

pmset -g log | egrep '\b(Sleep|Wake|Start)\s{2,}'

Read more: Find what's preventing Mac from sleeping

Installing Mac OS - An error occurred while preparing the installation...

Issue

Installing Mac OS X on iMac's blank formatted hard drive. Installation runs for 5-10 minutes and then fails with following error:

An error occurred while preparing the installation. Try running this application again.

Tried installing OS X El Capitan (10.11) and OS X Sierra (10.12) - the same error occurs in both cases.

Read more: Installing Mac OS - An error occurred while preparing the installation...