Device: LG G4
Android version: 6.0
Status: rooted

What can I do to power off the device (with a 20 sec delay) when I remove the charger. I tried with AutomateIt app, but after first cycle of power off / power on, it doesn't work if I don't open the app again, to run in the background.

I want to use my old phone in a old car, as a GPS device. I make it power on automatically as is described here: https://forum.xda-developers.com/att-lg-g3/general/lg-d3-d850-autoboot-t3714070

3 Answers 3


Using Macrodroid:

  1. On the Triggers tab, under Battery/Power section select "Power Connected/Disconnected", then choose "Power Disconnected".
  2. On the Actions tab, under Macrodroid Specific, select "Wait Before Next Action", then set the delay period to 20 seconds.
  3. On the Actions tab, under Device Actions, select Reboot/PowerOff, then choose "Power Off". If "Power Off" does not work on your device, choose "Power Off (Alternative)".
  4. Save the macro and give it a name.

When completed, the macro will look like the image below. Use the 3-dot to test the macro.

Note: Powering off requires the device be rooted.

Power off when charger is removed macro

Update: The way the macro is programmed above does not allow to stop the device from being power off if the charger is connected again before the 20 seconds delay expires. To stop the trigger, a condition to check the state of the device after the delay expires but before the action to power it off.

Edit the macro. Add a new action. Under the Actions, on the Conditions/Loops section, select "If clause". Add a condition. Select "Power Connected" under the Battery/Power section and choose "Power Disconnected", then OK. Click the up and down arrows button on the Actions box, move the "Power Off" action inside the "If...End If". Save the macro. The macro will look like the image below.

Power off when charger is removed macro version 2


Try Automate (free):

  1. Power source plugged block
  2. Delay block; 20s
  3. Device shutdown block (rooted device required)

Run the following shell script from init.d or /data/adb/*.d/ in case of Magisk. Or run directly from init's .rc file. See How to run an executable on boot and keep it running?


    [ $(cat /sys/class/power_supply/battery/status) = Charging ] || return 1

# keep waiting
while is_charging; do sleep 1; done

# charger is disconnected, countdown
sleep 20

# again start waiting if charger is connected
is_charging && exec $(realpath $0)

# else, shutdown
/system/bin/reboot -p charger_disconnected ||
/system/bin/setprop sys.powerctl shutdown,charger_disconnected

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .