How to automatically shutdown below certain battery level
I suggest you look at the app Tasker.
With Tasker you are able to literally automate your whole phone.
There are also many tutorials covering the of Tasker and what you can do with it (change settings and launch apps based on events, location, time and other variables)


  As with many similar applications, this one needs root for many functions.