Today, I faced a frustrating issue: my Elgato Stream Deck refused to cooperate with a new light for my desk at work, the Elgato Key Light. After troubleshooting without success, I turned to ChatGPT. Together, we arrived at an elegant, geeky solution that solved the issue.
The Challenge
As with most IoT items, getting them connected to your network and phone/laptop is rarely straightforward. After a few minutes, I was able to get the Key Light to appear in the Elgato Control Center. Cool. The two big features of this light is that I can change the brightness/temperature in the Control Center, and I can turn on/off the light using my Stream Deck.
But I could only access this light once. Despite exhaustive attempts, the new key light refused to make an appearance in Elgato’s Control Center again. Determined to find a workaround, I turned to ChatGPT, where it suggested a solution with a shell script, a simple text file that contains executable commands in macOS Terminal. Here’s the first draft of that script (with generic IP address, except port 9123 which the light needs):
curl --location --request PUT 'http://192.168.1.1:9123/elgato/lights' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--data-raw '{
"numberOfLights": 1,
"lights": [
{
"brightness": 50,
"temperature": 300
}
]
}'
I could paste this into Terminal and turn the light on or off by changing the brightness value to 100 or zero! But pasting this into Terminal isn’t user-friendly, which is the whole point of this new light. Feeling more confident, I started to think about integrating it into my Stream Deck. ChatGPT gave me code to turn the light on and off. Here’s the key_light_control-on.sh script:
# !/bin/bash
#Update the settings to set brightness to 100%
curl --location --request PUT 'http://192.168.1.1:9123/elgato/lights' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--data-raw '{
"numberOfLights": 1,
"lights": [
{
"on": 1,
"brightness": 100,
"temperature": 143
}
]
}'
And here’s the key_light_control-off.sh script:
# !/bin/bash
# Update the settings to set brightness to 0%curl --location --request PUT 'http://172.16.62.192:9123/elgato/lights' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--data-raw '{
"numberOfLights": 1,
"lights": [
{
"on": 1,
"brightness": 0,
"temperature": 143
}
]
}'
If you want to copy this project, here are the steps to provide the necessary permissions for your new script files:
Step 1: Create two files to with the shell script code from aobe
Use a plain text editor like nano
, vim
, or Visual Studio Code to create your script. If you’re using TextEdit, make sure to switch it to “Plain Text” mode (Format > Make Plain Text) before saving. File extension should be ‘.sh’.
Step 2: Open Terminal
Launch the Terminal application on your macOS system. This will open a command-line interface where you can execute the requisite commands.
Step 3: Navigate to the Folder
Navigate to the folder where your scripts, key_light_control-on.sh
and key_light_control-off.sh
, are located. You can use the cd
(change directory) command for this purpose. For instance, if your scripts are located in the Documents/Stream Deck info/
folder, the command would be:
cd ~/Documents/Stream\ Deck\ info/
Step 4: Change File Permissions
Run the chmod
command to change the permissions of each script file, making them executable:
chmod +x key_light_control-on.sh
chmod +x key_light_control-off.sh
This command assigns the executable (x) permission to the files, making them runnable as programs.
Step 5: Verify
To confirm that the permissions have been successfully updated, run the ls -l
command in Terminal:
ls -l
Look for your script files in the listing. They should now have an x
in their permission settings, denoting that they are executable.
Step 6: Add the scripts as buttons on Stream Deck
Open the Stream Deck software and choose the profile where you want to add the new button. Drag the “Open” action (usually found under the “System” category) to an empty button slot.
After adding the “Open” action to a button, you’ll see a configuration pane on the right side. Here, you can set various properties for the button, including what file to open.
Click on the “Choose” option and navigate to the location of your shell script, such as key_light_control-on.sh
or key_light_control-off.sh
. Select the script/file to attach it to the button.
Once configured, the changes should automatically save. Press the button on your Stream Deck hardware to test the action and verify that it triggers the script as expected.
Final Thoughts
With a dash of creativity and a helping hand from ChatGPT, I transformed a frustrating tech issue into a successful journey through the weeds of coding iOT. For educators and tech geeks alike, let’s not forget that challenges like these aren’t just stumbling blocks; they’re opportunities. And more importantly, tools like ChatGPT enable us to tackle complex problems that would’ve required expertise in coding. So, the next time you find yourself stuck with tech, don’t shy away. Dive in headfirst and emerge with new knowledge and skills with the help of ChatGPT.