Laptop fail to wake up if charger state has changed

I just realized what causes my occasional issues with resume from sleep and hibernate: Charger cable plugged in or out while the pc was suspended (to disk or ram). That is, if I have the charger connected when the pc goes to sleep, and then unplug the cable during the sleep, resume will most likely (>50%) fail.
If the charger was unplugged when the pc was suspended, then charger was connected during the sleep, resume will most likely fail.
But if the pc was suspended, then charger was connected, and disconnected before resume, it resumes ok. Likewise, if the charger was connected at suspend, and the cable disconnected, then there is a need to reconnect the cable before resuming.

In short: For a reliable resume, make sure charger cable has the same state as when the pc was suspended.