Open garymh opened 3 years ago
If it can be done with simple HTTP, it ought to be possible to whip up a Spoon that talks to the light with hs.http.
It can be done using simple HTTP, and discovery uses Bonjour (per this repo), so it should be possible to write a spoon that does both discovery (with hs.bonjour
) and control (with hs.http
).
I'll likely do so myself soon, and I'll post here if/when that happens.
I put a quick and dirty function with keybinding together to get a single elgato key light air to toggle on and off and keep the settings (brightness + temperature). URL is hardcoded so feel free to build on top of that:
local function toggle_key_light()
local url = "http://elgato-key-light-air-1.local.:9123/elgato/lights"
local status_code, response_body, response_header = hs.http.get(url)
local response = hs.json.decode(response_body)
--tprint(response)
if response["lights"][1]["on"] == 0 then
print("light is off: ", response["lights"][1]["on"])
response["lights"][1]["on"] = 1
else
print("light is on: ", response["lights"][1]["on"])
response["lights"][1]["on"] = 0
end
print("light is?: ", response["lights"][1]["on"])
--tprint(response)
print(hs.json.encode(response))
hs.http.doRequest(url, "PUT", hs.json.encode(response))
end
hs.hotkey.bind({ "ctrl", "alt", "cmd" }, "l", "toggle key light", function() toggle_key_light() end)
I've built a tiny spoon for it… all it does is turn it on and off: https://github.com/evantravers/hammerspoon-config/tree/master/Spoons/ElgatoKey.spoon
This would be a great compliment to the already awesome Stream Deck module 😄
According to https://github.com/adamesch/elgato-key-light-api:
It looks like this can be done with GET/POST requests?