This solution works for me! I tried it many times (at least with three batteries). Every time I changed the battery, the problem appears: autostart when plugged in. Now, after I changed the battery I need to run this command on the terminal!
``$ sudo nvram SystemAudioVolume=%80``
Actually, the command is to disable startup sound, but it works too to prevent autostart when plugged in. Probably, the actual solution is to reset nvram, as I did in the comment above.