How can I have my device charge only when battery is below a given percentage?
No, It is not possible on unrooted devices and yes, it can be done on rooted devices.

In a rooted device,

Add a permission to Android : android.permission.WRITE_SECURE_SETTINGS.

Then, system call the set function of the BATTERY_STATUS_CHARGING
from the BatteryManager with a 0 value.

To automate this function, use a third-party application like Tasker to set a trigger on Battery % &lt; 10 to do the forementioned system call.