Make Hyprsunset slowly change temperature throughout day

This commit is contained in:
Michael Bradley 2025-03-27 01:02:04 -04:00
parent 1c5bbd3373
commit ad845936d0
Signed by: MichaelBradley
SSH key fingerprint: SHA256:cj/YZ5VT+QOKncqSkx+ibKTIn0Obg7OIzwzl9BL8EO8
6 changed files with 84 additions and 6 deletions

View file

@ -7,8 +7,6 @@ The dotfiles are managed with [TOML Bombadil](https://github.com/oknozor/toml-bo
## TODO
* hyprsunset
* Ramp throughout day
* Wallpaper
* Adjust to time of day
* Make sure changed wallpaper is new

View file

@ -21,10 +21,12 @@ megasync = { source = "autostart/megasync.desktop", target = ".config/autostart/
git = { source = "git/config", target = ".config/git/config" }
# Also needs a one-time `systemctl --user enable --now eww-daemon.service eww-bars.service ip-geolocation.service swww-daemon.service'
# Also needs a one-time `systemctl --user enable --now eww-daemon.service eww-bars.service ip-geolocation.service sunset.timer swww-daemon.service'
eww-daemon = { source = "systemd/eww-daemon.service", target = ".config/systemd/user/eww-daemon.service" }
eww-bars = { source = "systemd/eww-bars.service", target = ".config/systemd/user/eww-bars.service" }
ip-geolocation = { source = "systemd/ip-geolocation.service", target = ".config/systemd/user/ip-geolocation.service" }
sunset-service = { source = "systemd/sunset.service", target = ".config/systemd/user/sunset.service" }
sunset-timer = { source = "systemd/sunset.timer", target = ".config/systemd/user/sunset.timer" }
swww-daemon = { source = "systemd/swww-daemon.service", target = ".config/systemd/user/swww-daemon.service" }
btop = { source = "btop", target = ".config/btop" }

View file

@ -1,8 +1,5 @@
#!/bin/env sh
if [ "$(pidof slurp)" = "" ]; then
hyprshade off
grimblast copy area
hyprshade auto
fi

64
scripts/sunset.sh Executable file
View file

@ -0,0 +1,64 @@
#!/bin/env sh
SUNRISE_START="$((5 * 60 * 60))" # When to start turning up temperature
SUNRISE_END="$((7 * 60 * 60))" # When to reach max temperature
SUNSET_START="$((21 * 60 * 60))" # When to start turning down temperature
SUNSET_END="$((23 * 60 * 60))" # When to reach min temperature
DAY_TEMP="6000" # Display temperature (K) to use in full daylight
NIGHT_TEMP="2400" # Display temperature (K) to use at night
CURRENT="$(((($(date '+%H') * 60) + $(date '+%M')) * 60 + $(date '+%S')))" # Time in seconds since start of day
# Performs a calculation using an argument containing an input string
calc() {
echo "scale=4; $1" | bc
}
# Evaluates a boolean expression on an argument containing an input string
bool() {
echo "scale=1; $1" | bc
}
# GLSL Smoothstep, takes a single number as an argument
smoothstep() {
if [ "$(bool "$1 <= 0")" = "1" ]; then
echo 0
elif [ "$(bool "$1 >= 1")" = "1" ]; then
echo 1
else
calc "$1 * $1 * (3 - 2 * $1)"
fi
}
# Interpolates between the 4th and 5th arguments based on the value of the 2nd in relation to the 1st and 3rd
interpolate() {
LOWER_IN="$1"
VALUE="$2"
UPPER_IN="$3"
LOWER_OUT="$4"
UPPER_OUT="$5"
if [ "$((VALUE <= LOWER_IN))" = "1" ]; then
echo "$LOWER_OUT"
elif [ "$((VALUE < UPPER_IN))" = "1" ]; then
calc "$LOWER_OUT + (($UPPER_OUT - $LOWER_OUT) * $(smoothstep "$(calc "($VALUE - $LOWER_IN) / ($UPPER_IN - $LOWER_IN)")"))"
else
echo "$UPPER_OUT"
fi
}
if [ "$((CURRENT <= SUNRISE_START))" = "1" ]; then
TEMP="$NIGHT_TEMP"
elif [ "$((CURRENT < SUNRISE_END))" = "1" ]; then
TEMP="$(interpolate "$SUNRISE_START" "$CURRENT" "$SUNRISE_END" "$NIGHT_TEMP" "$DAY_TEMP")"
elif [ "$((CURRENT <= SUNSET_START))" = "1" ]; then
TEMP="$DAY_TEMP"
elif [ "$((CURRENT < SUNSET_END))" = "1" ]; then
TEMP="$(interpolate "$SUNSET_START" "$CURRENT" "$SUNSET_END" "$DAY_TEMP" "$NIGHT_TEMP")"
else
TEMP="$NIGHT_TEMP"
fi
hyprctl hyprsunset temperature "$TEMP"

6
systemd/sunset.service Normal file
View file

@ -0,0 +1,6 @@
[Unit]
Description=Sets the monitor temperature based on the time of day
[Service]
Type=oneshot
ExecStart=/home/mbradley/scripts/sunset.sh

11
systemd/sunset.timer Normal file
View file

@ -0,0 +1,11 @@
[Unit]
Description=Changes the monitor temperature over the course of the day to ease eye strain
After=graphical-session.target
After=hyprsunset.service
[Timer]
OnCalendar=*-*-* *:*:00
Persistent=true
[Install]
WantedBy=timers.target