Welcome to the AndroidForums, zbysior.
Not totally sure why your device would begin to drain while its still plugged-in, having previously been charging...(if that is indeed what you were describing).
There is circuitry inside each battery that talks to the Android operating system to indicate its voltage, temperature, etc. When the battery is "full" (with a little head-room), the battery will sense this and report back to Android that it should no longer be charged. But after it is charged (and still plugged-in), I would expect that it remain nearly 100% charged even after being plugged-in all night. This is because Android will sense the battery needs additional charging once it falls below a certain threshold.
A "normal" (non-rooted) app wouldn't be able to control or time this behavior since it would require access to privileged data structures and APIs that owned by the kernel (i.e., battery / power management drivers).
I suppose an app might be written, but it might very well be extremely device- and operating system-specific.
At least that's my take on how I think things work

.
Cheers!