I’m new here, but old hat when it comes to troubleshooting Macs.
Sounds like the computer isn’t going to sleep consistently. Often this happens if there’s something running on the computer preventing it from sleeping.
These are the steps I usually take, for this kind of thing, with the more common, easier steps first. If you find something during one of these steps, take the action to resolve it, then test the sleep functionality.
Check for updates. It may sound awfully trite, but Apple does release firmware updates from time to time, often addressing issues relating to the System Management Controller (SMC), which has everything to do with this kind of issue.
Third-party software also plays a big role when it comes to software problems, so check for updates for all of these as well. (Most third-party software allows you to check for updates within the application.)
Check for any errant, unfinished print jobs. I’ve frequently seen this be the cause. You can do this by opening System Preferences > Print & Scan (or similarly named).
If you see a printer that says “In Use,” and you’re not trying to print something right now, then that’s a good clue this is your problem. From here, you can delete the troubled job (Apple Support article PH10608).
Check Activity Monitor (it’s in the Utilities folder) to see what’s currently running. Be sure to choose “All Processes” from the pop-up menu.
Backup software (like WD SmartWare), online syncing software (Dropbox, CrashPlan, Carbonite, etc.), out-of-date anti-virus or security software, auto-updaters and some third-party utilities can all prevent the computer from sleeping, especially if they’re in the middle of a task. Try disabling or turning them off from within its application or menu in the menu bar (and check updates for these, too).
Check how much hard drive space you have available. You’d probably have other symptoms, but it doesn’t hurt to check. Activity Monitor will tell you (click “Disk Activity” and look for the pie chart), or in OS X 10.7 Lion or later, Choose > About this Mac, then “More Info…” and “Storage.”
It varies by version, and what you’re actively using on the computer but if you have under 10 GB hard disk space free then it’s time to empty the Trash.(Apple Support article PH10628) (Tools like DaisyDisk, WhatSize, and OmniDiskSweeper (this one is free) are great help for this. And keep in mind these may only report sizes for the currently logged-in user account.)
Check the file system using Disk Utility (also in the Utilities folder). When your computer goes to sleep, it saves the current state of the computer to a sleep image in
/var/vm. If the computer has filesystem or hard disk issues, it may not be able to finish saving the data.
Choose your hard disk, then click “Verify Disk.” If any errors are found, you can repair them from the Recovery disk.
Check Console for disk errors (where else? Yep, in the Utilities folder). Usually you’d be noticing slowdown issues, but perhaps not if the drive is only just beginning to show trouble.
With “All Messages” showing, in the search box, type
disk i/o. It’s possible to go further back in time through
kernel.log. If you see repeated errors with
disk0s2, that’s going to be your boot volume, which ordinarily will be your internal hard drive. You have a failing hard drive.
Check for any connected peripherals. USB and Bluetooth devices, like hard drives or audio interfaces can prevent computers from going to sleep. Disconnect these things and test it out.
Reset the SMC. Though hardly ever needed, it’s a simple and quick step that can easily fix power-related issues.
Try from Safe Mode. (Learn how to Safe Boot: Apple Support article HT1455.) This allows you to test without any auto-launching third-party software and non-essential items, and rebuilds your boot cache, too. (If it works flawlessly, restart and check Activity Monitor again for any constantly running processes.)
After that I suspect I’d backup and try re-installing OS X. And after that, I’d install a fresh copy of OS X onto a second partition of the internal hard drive, or onto an external drive (or erase the hard drive and install if you can afford it) and test. Should you narrow it down to this, try then installing your most essential software one at a time, testing after each item, until you find the culprit.
If after an erase and install you’re still encountering a problem, it’s probably a hardware issue, meaning you’ll need to take it in for repair.