View Full Version : Turn smart bulb red while recording
vbash
12-23-2021, 04:19 PM
I've had one of those RGB bulbs for a while, and thought - wouldn't it be cool to turn it red when recording in REAPER? I tried it and of course, it's possible with ReaScript! Technically you could control any smart home device with this, as long as it has an API.
https://i.imgur.com/RRLFmnR.png
First we need the 'recording trigger script', which is a simple deferred function which runs in a loop and checks the current recording status. I wish that ReaScript had triggers / event hooks for this, but polling works just fine actually. If the recording state changes - it executes a Python script that changes the bulb color.
To change the lights you'll likely need to create an account on the device manufacturer's developer portal. I have a Tuya bulb so I used the tinytuya (https://github.com/jasonacox/tinytuya) library for Python to set the bulb color, and followed the instructions on the README to set up API access. If you have Philips Hue, you might use a library like phue (https://github.com/studioimaginaire/phue). Not sure about other manufacturers, but check on their website and it's likely they also have API support!
Here is a video of it in action (https://youtu.be/CaTaeP-j7Uk)
Here's the recording trigger script:
starttime=os.time()
lasttime=starttime
local wasRecording = reaper.GetPlayState() & 4 == 4
local function runloop()
local isRecording = reaper.GetPlayState() & 4 == 4
local newtime=os.time()
if newtime-lasttime >= 1 then
lasttime=newtime
if (not wasRecording and isRecording) then
reaper.ExecProcess('cmd.exe /C ""<python.exe location>" "<set bulb red colour script>""', 5000)
else
if (not isRecording and wasRecording) then
reaper.ExecProcess('cmd.exe /C ""<python.exe location>" "<set bulb white colour script>""', 5000)
end
end
wasRecording = isRecording
end
reaper.defer(runloop)
end
runloop()
Happy to answer any questions if anyone is interested :)
karbomusic
12-23-2021, 05:45 PM
Nice job!
And welcome. :) If you search around the forum there are a few threads on the subject. I think I first did it 2012'ish by adding custom code to my FaderPort extension's controller code, but quite a few have done it with scripts since then.
X-Raym
12-23-2021, 07:34 PM
So cool !
I use second screen or mobile to show red square to participant when record active but with light bulb it is quite fancy !
I wonder what are the other possibilities...^^
Including devices like littlebits or arduino... Some fancy things could be done !
karbomusic
12-23-2021, 08:58 PM
I wonder what are the other possibilities...^^
Including devices like littlebits or arduino... Some fancy things could be done !
The sky is kind of the limit. :)
https://forum.cockos.com/showpost.php?p=2321569&postcount=7
https://forum.cockos.com/showthread.php?t=203449
https://forum.cockos.com/showthread.php?t=165165
https://forum.cockos.com/showthread.php?t=202644
https://www.youtube.com/watch?v=uf4IKTfbi64
The setup I have with the Faderport is the light turns red during record, green during playback and white when stopped. I also have/had a light in the hallway, so that if I'm recording and the wife is coming my way, she knows "Caution: tape is rolling".
X-Raym
12-24-2021, 02:48 AM
@karbo
Do you have a video of your set up ? it seems awesome !
X-Raym
12-24-2021, 02:54 AM
@vbash
You put the lua code but do you also have python code to share ? 🤓
vbash
12-24-2021, 05:34 AM
The setup I have with the Faderport is the light turns red during record, green during playback and white when stopped. I also have/had a light in the hallway, so that if I'm recording and the wife is coming my way, she knows "Caution: tape is rolling".
That's awesome, things like this take a home studio to the next level! But something tells me I'll be soon using REAPER as an IDE instead of actually making music :D
You put the lua code but do you also have python code to share ? 🤓
of course! Here is the tiny script to turn it red:
import tinytuya
d = tinytuya.BulbDevice(DEVICE_ID, LOCAL_IP_ADDRESS, LOCAL_KEY)
d.set_version(3.3)
data = d.status()
if (data['dps']['20']): # if bulb is on
d.set_colour(255, 0, 0) # turn it red
It's been said before but the recording trigger script needs to be a Global startup action, so it's always running.
X-Raym
12-24-2021, 06:57 AM
It looks indeed so simple on code side... I need to go ASAP to a friends studio which has smart lights in the whole room, he has no idea that he could do that with them haha
Tough, not sure what brand he has. Code will vary for sure.
Meo-Ada Mespotine
12-24-2021, 11:24 AM
I wonder, if it's possible to hook into the Lightbulb's API. That way, we could have an extension, that's talking directly to the lightbulb, without having to run python via commandline in reascript.
It would allow more immediate control of the lightbulb with no delay, maybe even having multple states for multi-colored lightbulbs, green for nothing is happening, yellow for tracks are armed, red for recording.
karbomusic
12-24-2021, 11:38 AM
I wonder, if it's possible to hook into the Lightbulb's API. That way, we could have an extension, that's talking directly to the lightbulb, without having to run python via commandline in reascript.
It would allow more immediate control of the lightbulb with no delay, maybe even having multple states for multi-colored lightbulbs, green for nothing is happening, yellow for tracks are armed, red for recording.
The API is just a JSON endpoint.
My original version is via reaper extension and it talks directly to that endpoint - well I call an external script because I didn't know how to do a web request in C++ but achieves the same goal plenty fast enough - and I like the external script as I can modify it on demand. I just wrote and added code to the FaderPortXT branch I own.
If you see my other post, mine already does multiple colors based on state.
Green = Playback
Red = Recording
White = Stopped
^Because all those transport events already fire in the csurf API.
Etc.
X-Raym
12-24-2021, 02:13 PM
vbash solution is full scripts, this is nice :P
Though I wonder how much lag it has. On the video color transition is smooth so it is hard to evaluate.
X-Raym
02-12-2022, 05:31 AM
Yesterday I finally got the occasion to go into a friend studio where he has 6 WIFI Tuya lights, so I was finally able to try it!
Damn the set up is complex. Creating account on Tuya cloud as regular user, as developper, creating project, subscripting to at least 3 services with expirtation date, having tochange browser cause for some reason popups which should appears to allow that doesn't work on firefox, got local keys after python + pip + tinytuya + scan + wizard etc....
... and worst of all, trying to get the 6 lights to be recocgnized. Always one missing... Maybe weak wifi but anyway...
In the end I do have a successful script but it is so slow to run, can take 3-5 seconds to turn all the light on.
I guess for one light near the router it is ok, but 6 a bit far and it is barely usable :S
What astonished me is how complex it is to just tell a light to change color. Sending message which seems to pass to continent level server etc, having to register some developper API keys online... Took about 3 hours to explore these...
This seems so overkill compare to the 'simplicity' of the result. The complex part isn't the python code, but all which is before, and the sync lights parts.
Make me wonder if there isn't more simple system than tuya, something with direct wifi only or bluetooth for eg (like when controlling a gopro), cause tuya... Exhausting ! Well, it would have been surely more easy if their website wasn't that buggy.
@vbash You are definitely very patient to have gone to all this haha :P Anyway, this was interesting to explore :P Maybe works better with simpler set ups and very good wifi connection. Cheers !
karbomusic
02-12-2022, 06:15 AM
Make me wonder if there isn't more simple system than tuya, something with direct wifi only or bluetooth for eg (like when controlling a gopro), cause tuya... Exhausting ! Well, it would have been surely more easy if their website wasn't that buggy.
I think pretty much every other way of doing it is easier LOL. My Philips Hue setup's latency is ~100 ms.
Right now I'm in the middle of a DIY project using addressable LED strips and an ESP32 microprocessor which allows me to run them remotely over WiFi. This isn't for Reaper but for lighting in my office and areas in the house, but I'll possibly replace the Hue/Reaper/Transport setup with this in the near future because it is more versatile and will work with simple local GET requests.
It's a little too low-level hardware wise for most here I assume and C++ for programing the microprocessor but if anyone is serious about doing similar I'll share out the github link. Here's some testing last week where I'm using aluminum tracks with milky white lenses (facing the wall for testing indirect lighting). The web app is running on the microprocessor so it is fully self-contained, no web, no signups etc..
eoBLxk2HP4M
X-Raym
02-12-2022, 07:54 AM
@karbo
No Tuya and other complicated cloud based subscripting or anything with this method ? Does it run local without internet ?
karbomusic
02-12-2022, 10:11 AM
@karbo
No Tuya and other complicated cloud based subscripting or anything with this method ? Does it run local without internet ?
Right, I refuse to use subscription or third-party cloud based stuff in general for this kind of thing. It's just a microprocessor which has the ability to connect to the local network over WiFi, and it can be a web server at the same time which is how I control from my computer or phone - it also has plenty of other stuff I'm not using such as Bluetooth.
Ya' have to write the code against the API to use all these features but that's easy for you. There is absolutely zero dependency on any third-party as far as signups go and you can pretty much make it do whatever you want.
ESP32 and ESP8266 are extremely popular, with outstanding DIY community support and API documentation. These same processors are the guts of many existing "name brand" IoT and home automation products. I've been working with them since about 2014. You can plug via USB into your computer and start programming immediately. The best toolchain/programming setup right now is likely VSCode with the PlatformIO extension installed.
https://randomnerdtutorials.com/projects-esp32/
X-Raym
02-12-2022, 02:49 PM
@karbo
Sounds nice on paper, especially the no subscrition part :P
So what device would I need for eg to explore that ? is there some kind of compatible RGB light bulbs ? i have to look for ESP32 kind of lights ?
karbomusic
02-12-2022, 04:30 PM
@karbo
Sounds nice on paper, especially the no subscrition part :P
So what device would I need for eg to explore that ? is there some kind of compatible RGB light bulbs ? i have to look for ESP32 kind of lights ?
Does it have to be a bulb? Because these usually come as strips or matrixes: https://www.google.com/search?q=ws2812+leds&oq=ws2812+leds
A little creative thinking can likely result in something better than a bulb.
So WS2812b (https://www.google.com/search?q=ws2812+leds&oq=ws2812+leds) or WS2813 LED strips or matrixes.
For the device, maybe a little starter kit like this. Just because there are some extra components so you can hook things up and experiment and learn how to blink a regular LED first:
https://www.amazon.com/ESP32-WROVER-Contained-Compatible-Bluetooth-Tutorials/dp/B09BC1N9LL
^That helps bridge the gap on how to hook stuff up to the device, which is usually just 3 small wires. Once you got that, the rest is just code which you are already great at. You're just doing stuff you already know and some of that is talking directly to the wires/gadgets you hookup, in this case addressable LEDs.
Just be careful, if the lightbulb goes off (in your head), it can be kind of addicting because there are so many uses.
X-Raym
02-12-2022, 06:57 PM
Thanks for the infos!
Yes I would prefer a bulb, cause I want the "lamp" design.
But I keep your solution in mind, maybe at some point... :P
But for sure, tiny tuya wasn't that "plug and play" as I would have expect. :S I wonder if philips hue as such intricating activations etc. but it is definitely more expensive.
karbomusic
02-12-2022, 08:18 PM
I wonder if philips hue as such intricating activations etc. but it is definitely more expensive.
You sign up as developer to access the API documentation but using that API doesn't require using their cloud. Your code is talking directly to your Hue hardware.
vbash
02-16-2022, 01:22 AM
Yeah the Tuya setup process sucked! Although I hope it is communicating via local network first since you provide the LOCAL_KEY, but not 100% sure.
@karbomusic interesting stuff! Thanks for sharing, this could be the basis for the next studio evolution :D
Another way to do this without using third-party APIs would be Home Assistant (https://www.home-assistant.io, you need to set up a local server for this) and then add Tuya support via this integration: https://github.com/rospogrigio/localtuya/. I haven't tried this, but sounds like a nice local solution, even better if you have a Raspberry Pi laying around to use as your 'automation station'.
X-Raym
02-16-2022, 04:07 AM
@vbash
Maybe better with hole assistant, more expensive though 😔
Sure thing is that just telling a rgb lamp near to you to turn red is far from straightforward. I had the feeling to hack something, as if the industry wasn't their yet. It really should be simpler. 😆
karbomusic
02-16-2022, 08:50 AM
Sure thing is that just telling a rgb lamp near to you to turn red is far from straightforward. I had the feeling to hack something, as if the industry wasn't their yet. It really should be simpler. ��
For my mom yes of course but for someone like you/me...
With one Phillips Hue bulb and 2 HTTP requests you're up and running. You won't even need the API, I'll just send you the command directly (or you can download any free app that controls them, and press F12 in your browser to see what command(s) it sends). It's just an HTTP request with a PUT verb in JSON format:
Turn the light red:
request = new XMLHttpRequest();
request.open("PUT", "http://IPOfYourHueBridge/api/YourLocalUserName/groups/2/action", false);
request.send("{\"on\":true,\"bri\":255,\"sat\":255,\"hue\":0}");
^YourLocalUserName is NOT a cloud account, it's local to the device for security.
You can do this or some version of it in a reaper script (see other threads).
X-Raym
02-16-2022, 11:10 AM
@karbomusic
Then philips hue seems definitely to be the way of simplicity ! :)
simple HTTP requests, I'm ok with that!
karbomusic
02-16-2022, 01:28 PM
@karbomusic
Then philips hue seems definitely to be the way of simplicity ! :)
simple HTTP requests, I'm ok with that!
Yay. :) All the Phillips hue stuff is just that talking to the "bridge" as they call it which is where the internal web server you talk to lives. Then it sends the commands to the lights for you.
If you get these, I would suggest getting a developer account. I never really get any spam that I know of, it's just so they know how many are using the API and the API docs are really good.
X-Raym
04-26-2022, 11:26 AM
https://forum.cockos.com/showpost.php?p=2551058&postcount=1 Maybe Lua Socket for ReaScript can interest some people here ? :)
X-Raym
04-26-2022, 02:58 PM
Edited.
bignottalle
05-11-2022, 02:30 PM
The review is great, thank you. I also have a smart bulb, and it also can be programmed.
Thanks for sharing this code, and I think I will make use of it someday. I really want to synchronize all the three bulbs that I have. These color-changing RGB LED light bulbs (https://www.vont.com/product/vont-bulb-color-smart-light-bulbs-smart-bulbs/) make my house look much better, and I love the atmosphere that they create inside. The house looks like a place from Nicolas Winding Refn’s movie. They can be programmed to turn on or turn off at a particular time or change lights depending on a certain schedule.
But they cannot shine red when you start recording. So, thanks for the code.
vBulletin® v3.8.11, Copyright ©2000-2025, vBulletin Solutions Inc.