Shutdown Raspberry PI 3 when phone is being disconnecting - mathoudebine/openauto GitHub Wiki
- Open openauto.rules file
$ sudo nano /etc/udev/rules.d/openauto.rules
- Add below lines at the end of the openauto.rules file
SUBSYSTEM=="usb", ACTION=="add", ENV{ID_VENDOR_ID}=="18d1", ENV{ID_MODEL_ID}=="2d00", RUN+="/bin/sh -c '/sbin/shutdown -c && echo 0 > /sys/class/backlight/rpi_backlight/bl_power'"
SUBSYSTEM=="usb", ACTION=="add", ENV{ID_VENDOR_ID}=="18d1", ENV{ID_MODEL_ID}=="2d01", RUN+="/bin/sh -c '/sbin/shutdown -c && echo 0 > /sys/class/backlight/rpi_backlight/bl_power'"
SUBSYSTEM=="usb", ACTION=="remove", ENV{ID_VENDOR_ID}=="18d1", ENV{ID_MODEL_ID}=="2d00", RUN+="/bin/sh -c '/sbin/shutdown --poweroff 1 && echo 1 > /sys/class/backlight/rpi_backlight/bl_power'"
SUBSYSTEM=="usb", ACTION=="remove", ENV{ID_VENDOR_ID}=="18d1", ENV{ID_MODEL_ID}=="2d01", RUN+="/bin/sh -c '/sbin/shutdown --poweroff 1 && echo 1 > /sys/class/backlight/rpi_backlight/bl_power'"
Above script will do:
- Turn off the screen and schedule shutdown delayed for 1 minute when phone is being disconnecting
- Turn on the screen and cancel shutdown when phone is being connecting
You can adjust 1 minute delay for your needs.