diff --git a/modules/push-notifications.nix b/modules/push-notifications.nix index 4d354fb..8d066d8 100644 --- a/modules/push-notifications.nix +++ b/modules/push-notifications.nix @@ -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"; + }; + }; } diff --git a/scripts/push-sunrise-sunset.sh b/scripts/push-sunrise-sunset.sh new file mode 100755 index 0000000..60e7c2c --- /dev/null +++ b/scripts/push-sunrise-sunset.sh @@ -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"