NTFY - Command-Line Notifications
Aug 30, 2023
Server config file (server.yml): https://github.com/binwiederhier/ntfy/blob/main/server/server.yml
NTFY DOCS: https://docs.ntfy.sh/
Docker Commands
BASIC SETUP
sudo docker run -p 80:80 -itd binwiederhier/ntfy serve
ADVANCED SETUP
sudo docker run \
-v /var/cache/ntfy:/var/cache/ntfy \
-v /etc/ntfy:/etc/ntfy \
-p 80:80 \
-itd \
binwiederhier/ntfy \
serve \
--cache-file /var/cache/ntfy/cache.db
Battery Level Alert
Windows Code
while ($true) {
# Get battery status
$batteryStatus = Get-WmiObject Win32_Battery
# Extract battery level
$batteryLevel = $batteryStatus.EstimatedChargeRemaining
# Check if battery level is below 20%
if ($batteryLevel -lt 20) {
Invoke-RestMethod -Uri "http://yourntfyserver" -Method POST -Body "the battery is low!!"
echo "it worked"
}
# Wait for 5 minutes (300 seconds) before checking again
Start-Sleep -Seconds 10
}
MAC/Linux CODE
#!/bin/bash while true; do
# Get the current battery level
BATTERY_LEVEL=$(pmset -g batt | grep -Eo "\d+%" | cut -d% -f1) # Check if the battery level is below 20%
if [ "$BATTERY_LEVEL" -lt 31 ]; then
curl -d "the battery is low!!" http://yourntfyserver
fi # Wait for 5 minutes (300 seconds) before checking again
sleep 5
done