Last active
October 18, 2024 14:01
-
-
Save czottmann/3d6ae1de37fabeb2f59ce1a7378a601c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/opt/homebrew/bin/fish --login | |
# Prerequisites: `jq` must be installed | |
# Adjust the URL below with the address of your Key Light. Ask your router. | |
argparse \ | |
"temperature=" "brightness=" help read \ | |
-- $argv | |
or return | |
if test -n "$_flag_help" | |
echo " | |
Controls the Elgato Key Light Air. | |
FLAGS: | |
--read Returns the current temperature and brightness as JSON. | |
Takes precedence over other flags. | |
--temperature INT A number between 2900 and 7000 (Kelvin). | |
--brightness INT A number between 0 and 100. Defaults to 100. | |
--help This usage description. | |
" | |
exit 1 | |
end | |
if test -n "$_flag_read" | |
curl 'http://Elgato-Key-Light-Air-EC76.local:9123/elgato/lights' \ | |
--connect-timeout 1 \ | |
--header 'Content-Type: application/json' \ | |
--silent \ | |
| jq -r '.lights[0] | "\(.brightness)% at \(1000000 / .temperature / 10 | ceil * 10)K"' | |
exit 0 | |
end | |
if test -z "$_flag_temperature" | |
echo "ERROR: --temperature must be set, exiting" | |
exit 1 | |
end | |
if test -z "$_flag_brightness" | |
set _flag_brightness 100 | |
end | |
set payload ( | |
echo '{"lights":[{"brightness":0,"temperature":0}]}' \ | |
| jq --raw-output --compact-output \ | |
--arg brightness $_flag_brightness \ | |
--arg temperature (math "round((1000000 / $_flag_temperature) + 0.5)") \ | |
'.lights[0].brightness = ($brightness | tonumber) | .lights[0].temperature = ($temperature | tonumber)' | |
) | |
curl --request PUT \ | |
'http://Elgato-Key-Light-Air-EC76.local:9123/elgato/lights' \ | |
--header 'Content-Type: application/json' \ | |
--data-raw $payload \ | |
--connect-timeout 3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment