Once the lamp joined my local WLAN network (and I know the IP address), I use this script for controlling it.
Contents of /usr/local/bin/e
#!/bin/bash
function _elgatoGet {
local ip="$1"
local path="$2"
curl --silent \
--url "http://${ip}:9123/elgato/${path}"
}
function _elgatoPut {
local ip="$1"
local path="$2"
local msg="$3"
echo "${msg}" | curl --silent --request PUT \
--header "Content-Type: application/json" \
--url "http://${ip}:9123/elgato/${path}" \
--data @-
}
function _elgatoIdentify {
local ip="$1"
local displayName="$( _elgatoGet "${ip}" "accessory-info" | jq -r ".displayName" )"
echo "Light ${displayName} is blinking"
# empty POST
curl --silent \
--request POST\
--url "http://${ip}:9123/elgato/identify"
}
function _elgatoTurnOnOff {
local ip="$1"
local current="$( _elgatoGet "${ip}" "lights" | jq ".lights[0].on" )"
local new="$(( 1-${current} ))"
local state="$( _elgatoPut "${ip}" "lights" "{ \"lights\" : [ { \"on\" : ${new} } ] }" | jq ".lights[0].on" )"
local displayName="$( _elgatoGet "${ip}" "accessory-info" | jq -r ".displayName" )"
echo "$( if [[ "${state}" == "0" ]] ; then echo "Light \"${displayName}\" turned off" ; else echo "Light \"${displayName}\" turned on" ; fi ; )"
}
function _elgatoTemperature {
local ip="$1"
local temperature="$2"
# temperature must be in range [143..344]
if [[ ${temperature} -lt 143 ]] ; then
temperature="143" ;
elif [[ ${temperature} -gt 344 ]] ; then
temperature="344" ;
fi
echo "Temperature: $( _elgatoPut "${ip}" lights \
"{\"lights\":[{ \"on\": 1 , \"temperature\": ${temperature} }]}" \
| jq '.lights[0].temperature' )"
}
function _elgatoBrightness {
local ip="$1"
local brightnessDelta="$2"
local currentBrightness="$( _elgatoGet "${ip}" lights | jq ".lights[0].brightness" )"
local newBrightness="$(( $currentBrightness + $brightnessDelta ))"
# brightness must be in range [3..100]
if [[ ${newBrightness} -lt 3 ]] ; then
newBrightness="3" ;
elif [[ ${newBrightness} -gt 100 ]] ; then
newBrightness="100" ;
fi
echo "Brightness: $( _elgatoPut "${ip}" lights \
"{\"lights\":[{ \"on\": 1 , \"brightness\": ${newBrightness} }]}" \
| jq '.lights[0].brightness' )"
}
# ELGATO_KEY_LIGHT_IPADDRESS="192.168.0.106"
ELGATO_KEY_LIGHT_IPADDRESS="elgatoip"
if [[ $# -eq 0 ]] ; then
echo "$( _elgatoTurnOnOff "${ELGATO_KEY_LIGHT_IPADDRESS}" )"
elif [[ $# -eq 1 ]] ; then
command=$1
if [[ "${command}" == "+" ]] ; then
echo "$( _elgatoBrightness "${ELGATO_KEY_LIGHT_IPADDRESS}" 20 )"
elif [[ "${command}" == "-" ]] ; then
echo "$( _elgatoBrightness "${ELGATO_KEY_LIGHT_IPADDRESS}" -20 )"
elif [[ "${command}" == "1" ]] ; then
echo "$( _elgatoTemperature "${ELGATO_KEY_LIGHT_IPADDRESS}" 143 )"
elif [[ "${command}" == "2" ]] ; then
echo "$( _elgatoTemperature "${ELGATO_KEY_LIGHT_IPADDRESS}" 243 )"
elif [[ "${command}" == "3" ]] ; then
echo "$( _elgatoTemperature "${ELGATO_KEY_LIGHT_IPADDRESS}" 344 )"
elif [[ "${command}" == "i" ]] ; then
echo "$( _elgatoIdentify "${ELGATO_KEY_LIGHT_IPADDRESS}" )"
fi
fi