Skip to content

Commit

Permalink
Test sunrise/sunset notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
wagdav committed Nov 21, 2024
1 parent fcd976b commit bc3110b
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
22 changes: 22 additions & 0 deletions modules/push-notifications.nix
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,26 @@
Unit = "send-room-humidity.service";
};
};

systemd.services."sunrise-sunset" = {
path = [ pkgs.sunwait pkgs.curl ];
script = ''
set -eu
${../scripts/push-sunrise-sunset.sh}
'';
serviceConfig = {
Type = "oneshot";
User = "ntfy";
};
};

systemd.timers."sunrise-sunset" = {
wantedBy = [ "timers.target" ];
wants = [ "network-online.target" ];
after = [ "network-online.target" ];
timerConfig = {
OnCalendar = [ "*-*-* 5:30" "*-*-* 16:30" ];
Unit = "sunrise-sunset.service";
};
};
}
24 changes: 24 additions & 0 deletions scripts/push-sunrise-sunset.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/sh

NTFY_ADDRESS=http://nuc:8080/home-thewagner-ec1
LAT="46.519833N"
LON="6.6335E"

now=$(sunwait poll $LAT $LON)

if [ "$now" = "NIGHT" ]; then
echo "Waiting for sunrise"
HEADER="Sunrise!"
MESSAGE="Good morning! 🌅"
else
echo "Waiting for sunset"
HEADER="Sunset!"
MESSAGE="Good evening! 🌇"
fi

sunwait wait $LAT $LON

curl \
-H "Title: $HEADER" \
-d "$MESSAGE" \
"$NTFY_ADDRESS"

0 comments on commit bc3110b

Please sign in to comment.