I do this with the Home Assistant app on my phone. When the battery level gets to 80% it triggers the smart plug the charger is connected to, to switch off.
My phone is 3 years old now and according to AccuBattery still has a battery health of 2499mAh out of a design capacity of 2700mAh (Based on 977 charge sessions for 1,215,025 mAh total)