How to trigger a command on Linux when disconnected from power

For udev rules you should add

ENV{POWER_SUPPLY_TYPE}=="Mains"

because there is alot of devices in SUBSYTEM=="power_supply" with envinriment POWER_SUPPLY_ONLINE, including usb

2 Likes