Controlling Elgato Key Light under Ubuntu with Ruby

Recently I’ve acquired Elgato Key Light. It is a WiFi controllable LED lighting panel.

The panel uses 160 LEDs to provide up to 2800 lumens of brightness and a color range of 2900-7000K. While you can control it from a mobile device, doing it directly from the shell makes the whole experience way more convenient.

Key Light officially does not support Linux, however it uses ESP32, and it does run an unprotected HTTP server that accepts JSON commands. You can not only turn it on and off but also adjust both light temperature and brightness with simple JSON requests.

Here’s the code that I use to control my lights written in Ruby:

Sponsored
Sponsored
class="brush: ruby; title: ; notranslate"> #!/usr/bin/env ruby require 'uri' require 'net/http' require 'json' require 'yaml' # Set your lights IPs LIGHTS = %w[ 192.168.0.199 ] COMMAND = ARGV[0] DETAIL1 = ARGV[1].to_i DETAIL2 = ARGV[2].to_i # Sends a json request to a given elgato light def dispatch(ip, payload, endpoint, method) uri = URI("http://#{ip}:9123/elgato/#{endpoint}") req = method.new(uri) req.body = payload.to_json res = Net::HTTP.start(uri.hostname, uri.port) do |http| http.request(req) end puts res.body end def on(light_ip) dispatch( light_ip, { 'numberOfLights': 1, 'lights': [{ 'on': 1 }] }, 'lights', Net::HTTP::Put ) end def off(light_ip) dispatch( light_ip, { 'numberOfLights': 1, 'lights': [{ 'on': 0 }] }, 'lights', Net::HTTP::Put ) end def temperature(light_ip, value) raise "Needs to be between 143 and 344, was: #{value}" if value 344 dispatch( light_ip, { 'numberOfLights': 1, 'lights': [{ 'on': 1, 'temperature': value }] }, 'lights', Net::HTTP::Put ) end def brightness(light_ip, value) raise "Needs to be between 3 and 100, was: #{value}" if value 100 dispatch( light_ip, { 'numberOfLights': 1, 'lights': [{ 'on': 1, 'brightness': value }] }, 'lights', Net::HTTP::Put ) end def info(light_ip) dispatch( light_ip, {}, 'accessory-info', Net::HTTP::Get ) end def command(command, light_ip) case command when 'on' on(light_ip) when 'off' off(light_ip) when 'temperature' temperature(light_ip, DETAIL1) when 'brightness' brightness(light_ip, DETAIL1) when 'theme' temperature(light_ip, DETAIL1) brightness(light_ip, DETAIL2) when 'info' info(light_ip) else raise "Unknown COMMAND #{COMMAND}" end end LIGHTS.each { |light_ip| puts command(COMMAND, light_ip) }

You can place this code in /usr/local/bin under elgato name with executable permissions and then you can just:

elgato on # turn your lights on
elgato off # turn your lights off
elgato info # get info on your lights
elgato brightness 50 # set brightness to 50%
elgato temperature 280 # make  light temperature quite warm

The post Controlling Elgato Key Light under Ubuntu with Ruby appeared first on Closer to Code.

Ubuntu Server Admin

Recent Posts

How is Livepatch safeguarded against bad actors?

Canonical Livepatch is a security patching automation tool which supports reboot-less security updates for the…

18 hours ago

Accelerating data science with Apache Spark and GPUs

Apache Spark has always been very well known for distributing computation among multiple nodes using…

18 hours ago

Cut data center energy costs with bare metal automation

Data centers are popping up everywhere. With the rapid growth of AI, cloud services, streaming…

2 days ago

Build the future of *craft: announcing Starcraft Bounties!

Our commitment to building a thriving open source community is stronger than ever. We believe…

2 days ago

NodeJS 18 LTS EOL extended from April 2025 to May 2032 on Ubuntu

The clock was ticking: Node.js 18’s upstream End of Life (EOL) The OpenJS Foundation is…

2 days ago

Native integration now available for Pure Storage and Canonical LXD

June 25th, 2025 – Canonical, the company behind Ubuntu, and Pure Storage, the IT pioneer…

3 days ago