Is there a way to make my tablet turn off when not charging? I am planning to mount my android tablet to my car with a charging cable permanantly left in. The idea is as soon as I turn the car on, the tablet starts charging,  and as soon as I turn the car off, the charging stops. (I'm prepared to accept the reduced battery life as a result).

It would be ideal to have the tablet turn on automatically as soon as the car does, and turn off automatically once the car does. I have found a way online to have the tablet turn on as soon as it starts charging, but I cannot find a way to make the Tablet/Android turn off once the charging stops. Could you please advise if there is an app, or a file that can be added/changed to make this happen?
For rooted devices:
To have your device power off as soon as it stops charging, You can use an app called MacroDroid.

On the main page of the app, press on add macro  → battery/power  → power connected/disconnected  → power disconnected

press on actions (found, on the top)  → device actions  → reboot/power off  → power off  → ok.

press on the ✓ on the bottom right of the screen, and give a name to this action.


Now, when your phone is charging, and you unplug it, or in this case, turn off your car, it will automatically power off.
Non-rooted devices:
As far as I know, you cannot automate this action on non-rooted devices.
Therefore, the best suggestion I can give, is to have the power off dialog show up as soon as you turn off your car. That way, all you have to do is just press on power off.

Download MacroDroid.

On the main page of the app, press on add macro  → battery/power  → power connected/disconnected  → power disconnected

press on actions (found, on the top)  → device actions  → Android shortcuts  → power options  → ok

press on the ✓ on the bottom right of the screen, and give a name to this action.


Now when you turn your car off, the power off dialog will popup and you can press on power off