Automate Charging cycles for always connected devices to wall outlet
If you have Magisk installed, this module Magic Charging Switch (MCS) can automate charging with certain conditions.

I didn't try it but according to the XDA post it's a decent option.