Low Battery notification is not showing

in file and location /etc/udev/rules.d/lowbattery.rules
i wrote

SUBSYSTEM=='power_supply', ATTR{status}=='discharging', ATTR{capacity}=='[01]?[0-9]', RUN+='/usr/bin/systemctl start lowbattery.service'

and i created a lowbattery.service in location: /etc/systemd/system/lowbattery.service
in that file i had

[Unit]
Description=Low battery notification service
ConditionACPower=false
BindsTo=sys-subsystem-power-supply-devices
After=sys-subsystem-power-supply-devices

[Service]
User=burgersmomos
Type=oneshot
Environment=DISPLAY=:0
ExecStart=/usr/bin/notify-send "Time to Charge Up!" "Your battery is running low. It's time to plug in and recharge! ⚡💪"

[Install]
WantedBy=multi-user.target

but when i run

sudo systemctl daemon-reload
sudo systemctl start lowbattery.service

its giving the following error
Job for lowbattery.service failed because the control process exited with error code.
for

systemctl status lowbattery.service

i finally got to know where the error was only to cry not knowing how to solve it

Ă— lowbattery.service - Low battery notification service
     Loaded: loaded (/etc/systemd/system/lowbattery.service; disabled; preset: disabled)
     Active: failed (Result: exit-code) since Sat 2023-03-11 16:44:29 IST; 4min 1s ago
    Process: 125633 ExecStart=/usr/bin/notify-send Time to Charge Up! Your battery is running low. It's time to plug in and recharge! ⚡💪 (code=exited, status=1/FAILURE)
   Main PID: 125633 (code=exited, status=1/FAILURE)
        CPU: 19ms

Mar 11 16:44:29 Norway systemd[1]: Starting Low battery notification service...
Mar 11 16:44:29 Norway notify-send[125633]: Error spawning command line “dbus-launch --autolaunch=8c4bf46d32a844918837ddc4730d3858 --binary-syntax --close-stderr”: Child process exited with code 1
Mar 11 16:44:29 Norway systemd[1]: lowbattery.service: Main process exited, code=exited, status=1/FAILURE
Mar 11 16:44:29 Norway systemd[1]: lowbattery.service: Failed with result 'exit-code'.
Mar 11 16:44:29 Norway systemd[1]: Failed to start Low battery notification service.

Please help me, ive been racking my brain and the internet for hours

Try to run the service as user. notify-send needs to access your user’s dbus session.

I use a power manager. It’s not super cool but works. :grinning:

2 Likes