ntfy.sh lets you send notifications to your devices from your own scripts, home lab, or automation projects. It's free and does all the work of delivering notifications to multiple platforms. All you need to do is know how to call it.

What is ntfy.sh?

ntfy.sh is a free notification app that works on Apple and Android mobile devices, as well as delivering notifications to desktop web browsers. It's primary use case is for IT administrators and tech enthusiasts to get live status updates on their infrastructure, but you can use it to receive alerts from pretty much any script or bit of code, or any service that supports webhooks.

Usually, to get these kinds of push notifications, you'd have to develop a whole app and go through the app store approval process, or set up a web app with web push, so having something that's already done all that for you saves a lot of hassle.

What Am I Using ntfy.sh For?

I've got a few useful and less-useful things I'm using ntfy.sh for: I receive notifications when backups succeed and fail, and if one of my websites stops responding or a server needs a reboot. My NAS reports when disk or memory starts running low, and I even have a temperature sensor attached to it, so I know if things are getting too toasty in my server cabinet. On the less-useful side, I get a smiley face notification when a new user signs up for one of my apps.

Server monitoring isn't the limit of this tool. You can integrate it into any home automation or script to make it send notifications. All you need to do is add the relevant ntfy.sh command to your Bash or Python scripts.

You could integrate it with a sensor on your washing machine to get a notification when it's done, or get an alert if your garage door is left open for more than a few minutes. You can connect a bunch of sensors to a Raspberry Pi and use it to get notified about all sorts of things around the house.

Raspberry Pi CanaKit with components Credit: Raspberry Pi
USB ports
1 USB-C, 4 USB-A
HDMI ports
2

CanaKit's Raspberry Pi 5 Starter Kit includes everything a user needs to pick up and go, including a 128 microSD loaded with the Raspberry Pi OS.

How Do You Use ntfy.sh?

You can call ntfy.sh from any script, code, or webhook that can make a POST HTTP request to its API.

It works like this: You create a topic on a ntfy.sh server, and subscribe to it on the ntfy.sh app (find the app store links at the ntfy.sh website, or click 'App' to use the browser-based version). The name of the topic should be unique and secret, as anyone who knows it can read the notifications (so, in the below examples, make sure you replace it!).

Then, from your scripts, you just send notifications to that topic, and any subscribed devices receive the notification. You can use the public ntfy.sh server for free, or replace the URL in the scripts with your own self-hosted instance. You can find out more about how to use it in the ntfy.sh documentation.

There's one important rule: don't publish sensitive information to it—only send alerts, don't include credentials or identifying information in your notifications as they could be read and intercepted by others. Authentication is available, but generally the name of the topic acts as the password, which is not sufficient security for important info.

Here are a few examples based on the snippets I use in my own scripts.

Using ntfy.sh To Notify on Bash Script Failure

Here are the commands I paste into my Bash scripts to send ntfy.sh notifications if the script fails at any point. It uses curl to make the HTTP request.

#!/bin/bash
set -Eeuo pipefail
NTFY_URL="https://ntfy.sh/my_super_secret_topic"
TITLE_OK="Job COMPLETED"
MESSAGE_OK="Finished successfully on $(hostname)"
TITLE_FAIL="Job FAILED"
MESSAGE_FAIL="Script interrupted on $(hostname)"
notify() {
local title="$1"
local message="$2"
curl -fsS -H "Title: ${title}" -d "${message}" "${NTFY_URL}" || true
}
# Notify on any error and exit with the same status
trap 'rc=$?; notify "$TITLE_FAIL" "Script failed on $(hostname) (exit ${rc})"; exit "${rc}"' ERR
# Notify if user hits Ctrl+C and exit with 130 (SIGINT)
trap 'notify "$TITLE_FAIL" "$MESSAGE_FAIL"; exit 130' INT
# -----------------------------
# Your script goes here
# Any non-zero exit triggers the ERR trap above
# -----------------------------
# Notify on success
notify "$TITLE_OK" "$MESSAGE_OK"

The trap command catches errors and calls the notify() function, which sends a request to the NTFY_URL, passing the TITLE_OK and TITLE_FAIL values to it for display on your device.

Using ntfy.sh with PowerShell and the Windows Task Scheduler

The Windows Task Scheduler doesn't just work on a timer, it can also perform actions when specific events are raised. Events like your PC running out of disk space or needing to reboot after updates can be used to trigger PowerShell scripts.

The below PowerShell script should be saved in its own file (e.g. my_ntfy_script.ps1). It accepts a title, message, and URL for a ntfy.sh server, then sends the supplied notification.

param(
[string]$Title = "Windows Event",
[string]$Message = "Triggered",
[string]$Url = "https://ntfy.sh/my_super_secret_topic"
)
try {
# Make HTTP Request to ntfy.sh API
Invoke-RestMethod -Method Post -Uri $Url -Headers @{ Title = $Title } -Body $Message -ErrorAction Stop
} catch {
# Write to the Application log on failure
Write-EventLog -LogName Application -Source "Windows PowerShell" `
-EventId 3001 -EntryType Warning `
-Message "ntfy.sh notify failed: $($_.Exception.Message)"
}

You can then create an event-triggered task in the Windows Task Scheduler. This example sends a notification when a user attempts to log in and is unsuccessful, which creates an event with ID 4625 in the Security log.

To create a scheduled task for this, open the Task Scheduler by searching for it in the Windows Start menu, then select Action > Create Basic Task from the toolbar. In the Create Task dialog, fill in the Name and optional Description for the task (for example, ntfy.sh login failed notification), click "Next," then set the Trigger to "When a specific event is logged", then click "Next" again.

To trigger a notification when your PC reboots, set the Log value to Security, and set the EventID to 4625, and again, press "Next."

Scheduling a task in the Task Scheduler triggered by an event.

Next, select the Action to Start a program, and hit the Next button once more. Copy the below command into the Program/script field, replacing the path to your script and topic name.

powershell.exe -NoProfile -ExecutionPolicy Bypass -File "C:\Scripts\my_ntfy_script.ps1" -Title "Login failed" -Message "Someone tried to access your PC" -Url "https://ntfy.sh/my_super_secret_topic"

Configuring a PowerShell script in the Task Scheduler.

Click "Next" again. You may be presented with a warning about arguments being provided in the Program text box—this is OK, they'll be converted into arguments when you save. Click Finish on the next screen when you're done.

Windows Task Scheduler entries.

When you're done, the new task should appear in the Task Schedule Library list as shown above. To test, you can right-click on the task and select "Run."

Note that these notifications don't contain any revealing information, such as IP addresses or usernames. I know what the notifications mean, but if someone else were to somehow guess the ntfy.sh topic name, they can't do anything with the info.

ntfy.sh and macOS Automator

The Automator tool that ships with macOS is often overlooked, is possibly neglected, but it can really do a lot. It lets you automate common tasks with minimal coding, and you can even record yourself doing things and then have it repeat them. You can incorporate Bash scripts, too, so the snippet provided above can be used here as well.

Subscribing From the ntfy.sh Apps

From the ntfy.sh app on your mobile device (or using the web app from your browser), tap Add Subscription, then enter your topic name (and custom server address if you're using one).

Adding a subscription to ntfy.sh.

The subscribed topic will then appear in the list...

Viewing subscribed topics in ntfy.sh.

... And when your scripts run, you'll get notified!

Notification received on an iPhone from ntfy.sh.

Pretty simple! And definitely useful.

DIY Projects You’ll Want To Hear About Away From Home

If you haven't got anything to send notifications about yet, why not start a homelab (they're super useful and let you self-host a bunch of apps, including ntfy.sh)?

Or, run your smart home from a Raspberry Pi using Home Assistant, which supports ntfy.sh for notifications. If you want to tinker, you can try some of these weekend Raspberry Pi projects (and some more projects here, and here!) and see if there's anything you can add ntfy.sh to that hasn't been done yet.