Created
February 1, 2022 21:33
-
-
Save andreineculau/6306b0829db1d229de4e32e18d0e4613 to your computer and use it in GitHub Desktop.
Control Elgato Air Light from shell
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
#!/usr/bin/env bash | |
set -euo pipefail | |
# USAGE | |
# elgato-air-light IP ON BRIGHTNESS TEMPERATURE | |
# | |
# ON can be 0 or 1 | |
# BRIGTHNESS can be 0-100 | |
# TEMPERATURE can be 0-100 | |
# | |
# e.g. to have it on with half brightnesss and half temperature | |
# elgato-air-light 192.168.1.11 1 50 50 | |
# | |
# DEPS | |
# bash | |
# curl | |
# jq | |
function main() { | |
local IP=$1 | |
local ON=$2 | |
local BRIGHTNESS=$3 | |
local TEMPERATURE=$4 | |
[[ -z "${TEMPERATURE}" ]] || TEMPERATURE=$((${TEMPERATURE} * 2 + 143)) | |
local URL="http://${IP}:9123/elgato/lights" | |
local STATE=$(curl "${URL}" 2>/dev/null) | |
[[ -n "${ON}${BRIGHTNESS}${TEMPERATURE}" ]] || { | |
echo "${STATE}" | jq | |
return 0 | |
} | |
[[ -n "${ON}" ]] || ON=$(echo "${STATE}" | jq -r ".lights[0].on") | |
[[ -n "${BRIGHTNESS}" ]] || BRIGHTNESS=$(echo "${STATE}" | jq -r ".lights[0].brightness") | |
[[ -n "${TEMPERATURE}" ]] || TEMPERATURE=$(echo "${STATE}" | jq -r ".lights[0].temperature") | |
cat <<EOF | jq --compact-output | curl -XPUT -d @- "${URL}" | |
{ | |
"lights": [{ | |
"on": ${ON}, | |
"brightness": ${BRIGHTNESS}, | |
"temperature": ${TEMPERATURE} | |
}] | |
} | |
EOF | |
} | |
main "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment