Homey alert!

This commit is contained in:
2026-09-03 11:37:12 +03:00
parent df97c76527
commit 943498ce52
2 changed files with 86 additions and 0 deletions
+84
View File
@@ -0,0 +1,84 @@
{...}: {
config.flake.modules.homeManager.homey-alert = {
lib,
config,
pkgs,
...
}: {
options.azos.homey-alert.enable = lib.mkOption {
default = false;
example = true;
type = lib.types.bool;
};
config = lib.mkIf config.azos.homey-alert.enable {
home.packages = [
(pkgs.writeShellApplication {
name = "homey-alert";
runtimeInputs = with pkgs; [curl pass];
text = ''
usage() {
cat <<EOF
Usage: homey-alert [OPTIONS] [MESSAGE]
Send a notification to the homey ntfy server (ntfy.zakobar.com/alerts).
MESSAGE can be given as a positional argument or piped via stdin.
Options:
-t, --title TITLE notification title
-p, --priority PRIO priority: min|low|default|high|urgent (default: default)
-T, --tags TAGS comma-separated emoji shortcodes (e.g. warning,rotating_light)
-h, --help show this help
Examples:
homey-alert "Backup complete"
homey-alert -t "Backup" -p high -T white_check_mark "restic finished"
echo "done" | homey-alert -t "Job finished"
EOF
}
TITLE=""
PRIORITY="default"
TAGS=""
while [[ $# -gt 0 ]]; do
case "$1" in
-t|--title) TITLE="$2"; shift 2 ;;
-p|--priority) PRIORITY="$2"; shift 2 ;;
-T|--tags) TAGS="$2"; shift 2 ;;
-h|--help) usage; exit 0 ;;
--) shift; break ;;
-*) echo "Unknown option: $1" >&2; usage >&2; exit 1 ;;
*) break ;;
esac
done
if [[ $# -gt 0 ]]; then
MESSAGE="$*"
elif [[ ! -t 0 ]]; then
MESSAGE="$(cat)"
else
echo "homey-alert: no message provided" >&2
usage >&2
exit 1
fi
TOKEN="$(pass zakobar-homecenter/ntfy-token)"
HEADERS=(
-H "Authorization: Bearer $TOKEN"
-H "Priority: $PRIORITY"
)
[[ -n "$TITLE" ]] && HEADERS+=(-H "Title: $TITLE")
[[ -n "$TAGS" ]] && HEADERS+=(-H "Tags: $TAGS")
curl -sf "''${HEADERS[@]}" \
-d "$MESSAGE" \
https://ntfy.zakobar.com/alerts
'';
})
];
};
};
}