#!/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"