Skip to content

Instantly share code, notes, and snippets.

@pnchinmay
Last active July 10, 2021 16:59
Show Gist options
  • Save pnchinmay/4a2da2758896f6b725061b63244dd399 to your computer and use it in GitHub Desktop.
Save pnchinmay/4a2da2758896f6b725061b63244dd399 to your computer and use it in GitHub Desktop.
Battery notification
#!/bin/bash
TOKEN="*****************************************************************"
ID_CHAT="*******************"
URL="https://api.telegram.org/bot$TOKEN/sendMessage"
URL1="https://api.telegram.org/bot$TOKEN/sendPhoto"
sout=$(sh ~/.config/autostart/checkheadphones.sh)
XDG_RUNTIME_DIR=/run/user/1000 #check with command "id -u"
export DISPLAY=:1 #check with command "echo $DISPLAY"
battery_percent=$(acpi -b | grep -P -o '[0-9]+(?=%)')
if !(upower -i /org/freedesktop/UPower/devices/battery_BAT1 | grep "state: discharging"); then
if [ "$battery_percent" -gt 85 ]; then
export DISPLAY=:1 && /usr/bin/notify-send --urgency=critical -i "~/.config/autostart/batteryfull.png" "Battery full." "Level: ${battery_percent}% "
MESSAGE="Battery full. Level: ${battery_percent}% "
curl -F "chat_id=$ID_CHAT" -F "photo=@/home/manas/.config/autostart/batteryfull.png" -F "caption=${MESSAGE}" \
https://api.telegram.org/bot$TOKEN/sendphoto
if [ "$sout" = "off" ]; then
exec /usr/bin/paplay /usr/share/sounds/gnome/default/alerts/danger_alarm.wav
fi
fi
fi
if (upower -i /org/freedesktop/UPower/devices/battery_BAT1 | grep "state: discharging"); then
if [ "$battery_percent" -lt 15 ]; then
export DISPLAY=:1 && /usr/bin/notify-send --urgency=critical -i "~/.config/autostart/depositphotos_5141262-stock-photo-battery-low.jpg" "Battery empty." "Level: ${battery_percent}% "
MESSAGE="Battery empty. Level: ${battery_percent}% "
curl -F "chat_id=$ID_CHAT" -F "photo=@/home/manas/.config/autostart/depositphotos_5141262-stock-photo-battery-low.jpg" -F "caption=${MESSAGE}" \
https://api.telegram.org/bot$TOKEN/sendphoto
if [ "$sout" = "off" ]; then
exec /usr/bin/paplay /usr/share/sounds/gnome/default/alerts/danger_alarm.wav
fi
fi
fi
killall batteryfull.sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment