Created
September 25, 2023 12:48
-
-
Save researcx/1996c82f09040df1d9acfa1deecbbadd to your computer and use it in GitHub Desktop.
adjust cpu frequency based on time and weather
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
LAT=53.3963308 | |
LON=-1.5155923 | |
JSON=$(curl -s "https://api.open-meteo.com/v1/forecast?latitude=$LAT&longitude=$LON¤t_weather=true") | |
WEATHERCODE=$(echo $JSON | jq -r '.current_weather.weathercode') # WMO weather interpretation code | |
IS_DAY=$(echo $JSON | jq -r '.current_weather.is_day') # 1 if the current time step has daylight, 0 at night. | |
#echo -e "\033[1;33mDBG: IS_DAY=$IS_DAY\033[0m" | |
#echo -e "\033[1;33mDBG: WEATHERCODE=$WEATHERCODE\033[0m" # 0 for clear sky, 1 for mainly clear, 2 for partly cloudy (see https://open-meteo.com/en/docs#weathervariables) | |
if [ "$IS_DAY" -eq 1 ]; then | |
echo -e "\033[1;32mSUCC: It is daytime!\033[0m" | |
if [ "$WEATHERCODE" -gt 2 ]; then | |
echo -e "\033[1;31mERR: Unsuitable weather conditions (dark)\033[0m" | |
x86_energy_perf_policy --turbo-enable 0; cpupower frequency-set -u 1.5GHz > /dev/null | |
else | |
echo -e "\033[1;32mSUCC: Suitable weather conditions (bright)\033[0m" | |
x86_energy_perf_policy --turbo-enable 1; cpupower frequency-set -u 5GHz > /dev/null | |
fi | |
else | |
echo -e "\033[1;31mERR: It is not daytime!\033[0m" | |
x86_energy_perf_policy --turbo-enable 0; cpupower frequency-set -u 1GHz > /dev/null | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment