Ask Your Question
1

System sounds Fedora 28 Power Management

asked 2018-08-11 09:38:23 -0500

chiguy1256 gravatar image

I have recently replaced Windows 10 on my laptop with Fedora 27 and then upgraded to Fedora 28. I would like to setup some kind of system sound that gives me a warning when my laptop battery has 10% charge remaining. Can someone provide instructions or links on how to do this? Thanks.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2018-08-14 08:14:36 -0500

updated 2018-08-14 13:25:54 -0500

This is just to understand how we can achieve the desired function

Install acpi ( acpi-1.7-8.fc<ver_arch>.rpm , in this example we will use acpi command to get battery charge level use command acpi -b | grep -P -o '[0-9]+(?=%)' it will show you the battery charge level and simply write a shell script to run this command store and compare it with an alert value like if output is 15 than run a sound

there are many ways to do so . checking whether you have plugged the AC charger . and example of checking whether its on battery or plugged in with AC power Click Here

Or You can use various options which is available with power management itself like CLICK HERE and create a script to check battery status and play a sound if the power status goes below 15% , 10% etc etc. Remember there may be slight difference with each and every distribution of Linux OS on this . anyways this is just to understand the basic idea about how we can achieve the above said goal. Try reading things about If X session is running, it sends visual alert message through notify-send and plays a beep sound or custom sound .

example script ( these are example for getting idea , do some research on your system and it may need to be modified according to your distribution of OS )

#!/bin/bash
# Check AC adapter status and Battery Voltage
if [ $(cat /sys/class/power_supply/ACAD/online) = "0" ] && \
   [ $(cat /sys/class/power_supply/BAT0/voltage_now) \< "4810000" ]; then
       # Display Notification
       if [ $DISPLAY ]; then notify-send -u critical \
       -i /usr/share/icons/Antu/status/64/battery-low.svg \
       -t 2000 "Battery Critically Low" "Plug in to AC or Suspend immediately"; fi
       # Play Alert Sound
       for play_beep in {1..4}; do $(aplay /home/user/Downloads/alert_high.wav > /dev/null 2>&1); done
fi

run the script as a systemd service rather than running it as another cron job. So create a systemd service file, named low_battery.service under the /etc/systemd/system/ folder . sudo vi /etc/systemd/system/low_battery.service

The systemd service file,

[Unit]
Description=Send alerts on low battery

[Service]
Type=simple
ExecStart=/bin/bash /home/user/battery_low_alert
Environment="DISPLAY=:0" "XAUTHORITY=/home/user/.Xauthority"
Restart=always
RestartSec=10

[Install]
WantedBy=multi-user.target

Needless to say again, don't forget to edit the above systemd service according your system.

Now reload systemd daemons and enable the low_battery.service systemd service. You also could use User and Group parameters under the [Service] section to run the script as normal user

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2018-08-11 09:38:23 -0500

Seen: 35 times

Last updated: 18 hours ago