Skip to content

Instantly share code, notes, and snippets.

@researcx
Created September 25, 2023 12:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save researcx/1996c82f09040df1d9acfa1deecbbadd to your computer and use it in GitHub Desktop.
Save researcx/1996c82f09040df1d9acfa1deecbbadd to your computer and use it in GitHub Desktop.
adjust cpu frequency based on time and weather
#!/bin/bash
LAT=53.3963308
LON=-1.5155923
JSON=$(curl -s "https://api.open-meteo.com/v1/forecast?latitude=$LAT&longitude=$LON&current_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