Go Back   Cockos Incorporated Forums > REAPER Forums > REAPER for Live Use

Reply
 
Thread Tools Display Modes
Old 12-23-2021, 04:19 PM   #1
vbash
Human being with feelings
 
vbash's Avatar
 
Join Date: Dec 2021
Posts: 4
Default Turn smart bulb red while recording

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.



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 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. 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

Here's the recording trigger script:

Code:
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
vbash is offline   Reply With Quote
Old 12-23-2021, 05:45 PM   #2
karbomusic
Human being with feelings
 
karbomusic's Avatar
 
Join Date: May 2009
Posts: 29,260
Default

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.
__________________
Music is what feelings sound like.
karbomusic is offline   Reply With Quote
Old 12-23-2021, 07:34 PM   #3
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 9,875
Default

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 !
X-Raym is offline   Reply With Quote
Old 12-23-2021, 08:58 PM   #4
karbomusic
Human being with feelings
 
karbomusic's Avatar
 
Join Date: May 2009
Posts: 29,260
Default

Quote:
Originally Posted by X-Raym View Post
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.ph...69&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".
__________________
Music is what feelings sound like.
karbomusic is offline   Reply With Quote
Old 12-24-2021, 02:48 AM   #5
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 9,875
Default

@karbo
Do you have a video of your set up ? it seems awesome !
X-Raym is offline   Reply With Quote
Old 12-24-2021, 02:54 AM   #6
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 9,875
Default

@vbash
You put the lua code but do you also have python code to share ? 🤓
X-Raym is offline   Reply With Quote
Old 12-24-2021, 05:34 AM   #7
vbash
Human being with feelings
 
vbash's Avatar
 
Join Date: Dec 2021
Posts: 4
Default

Quote:
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

Quote:
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:

Code:
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.
vbash is offline   Reply With Quote
Old 12-24-2021, 06:57 AM   #8
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 9,875
Default

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.
X-Raym is offline   Reply With Quote
Old 12-24-2021, 11:24 AM   #9
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig
Posts: 6,621
Default

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.
__________________
Use you/she/her.Ultraschall-Api Lua Api4Reaper - Donate, if you wish

On vacation for the time being...
Meo-Ada Mespotine is offline   Reply With Quote
Old 12-24-2021, 11:38 AM   #10
karbomusic
Human being with feelings
 
karbomusic's Avatar
 
Join Date: May 2009
Posts: 29,260
Default

Quote:
Originally Posted by Meo-Ada Mespotine View Post
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.
__________________
Music is what feelings sound like.

Last edited by karbomusic; 12-24-2021 at 11:46 AM.
karbomusic is offline   Reply With Quote
Old 12-24-2021, 02:13 PM   #11
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 9,875
Default

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 is offline   Reply With Quote
Old 02-12-2022, 05:31 AM   #12
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 9,875
Default

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 !
X-Raym is offline   Reply With Quote
Old 02-12-2022, 06:15 AM   #13
karbomusic
Human being with feelings
 
karbomusic's Avatar
 
Join Date: May 2009
Posts: 29,260
Default

Quote:
Originally Posted by X-Raym View Post
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..

__________________
Music is what feelings sound like.
karbomusic is offline   Reply With Quote
Old 02-12-2022, 07:54 AM   #14
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 9,875
Default

@karbo
No Tuya and other complicated cloud based subscripting or anything with this method ? Does it run local without internet ?
X-Raym is offline   Reply With Quote
Old 02-12-2022, 10:11 AM   #15
karbomusic
Human being with feelings
 
karbomusic's Avatar
 
Join Date: May 2009
Posts: 29,260
Default

Quote:
Originally Posted by X-Raym View Post
@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/
__________________
Music is what feelings sound like.

Last edited by karbomusic; 02-12-2022 at 10:18 AM.
karbomusic is offline   Reply With Quote
Old 02-12-2022, 02:49 PM   #16
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 9,875
Default

@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 ?
X-Raym is offline   Reply With Quote
Old 02-12-2022, 04:30 PM   #17
karbomusic
Human being with feelings
 
karbomusic's Avatar
 
Join Date: May 2009
Posts: 29,260
Default

Quote:
Originally Posted by X-Raym View Post
@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=ws28...oq=ws2812+leds

A little creative thinking can likely result in something better than a bulb.

So WS2812b 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-.../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.
__________________
Music is what feelings sound like.
karbomusic is offline   Reply With Quote
Old 02-12-2022, 06:57 PM   #18
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 9,875
Default

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.
X-Raym is offline   Reply With Quote
Old 02-12-2022, 08:18 PM   #19
karbomusic
Human being with feelings
 
karbomusic's Avatar
 
Join Date: May 2009
Posts: 29,260
Default

Quote:
Originally Posted by X-Raym View Post
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.
__________________
Music is what feelings sound like.
karbomusic is offline   Reply With Quote
Old 02-16-2022, 01:22 AM   #20
vbash
Human being with feelings
 
vbash's Avatar
 
Join Date: Dec 2021
Posts: 4
Default

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

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'.
vbash is offline   Reply With Quote
Old 02-16-2022, 04:07 AM   #21
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 9,875
Default

@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. 😆
X-Raym is offline   Reply With Quote
Old 02-16-2022, 08:50 AM   #22
karbomusic
Human being with feelings
 
karbomusic's Avatar
 
Join Date: May 2009
Posts: 29,260
Default

Quote:
Originally Posted by X-Raym View Post

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:

Code:
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).
__________________
Music is what feelings sound like.

Last edited by karbomusic; 02-16-2022 at 08:58 AM.
karbomusic is offline   Reply With Quote
Old 02-16-2022, 11:10 AM   #23
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 9,875
Default

@karbomusic
Then philips hue seems definitely to be the way of simplicity !


simple HTTP requests, I'm ok with that!
X-Raym is offline   Reply With Quote
Old 02-16-2022, 01:28 PM   #24
karbomusic
Human being with feelings
 
karbomusic's Avatar
 
Join Date: May 2009
Posts: 29,260
Default

Quote:
Originally Posted by X-Raym View Post
@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.
__________________
Music is what feelings sound like.
karbomusic is offline   Reply With Quote
Old 04-26-2022, 11:26 AM   #25
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 9,875
Default

https://forum.cockos.com/showpost.ph...58&postcount=1 Maybe Lua Socket for ReaScript can interest some people here ?

Last edited by X-Raym; 04-26-2022 at 02:58 PM.
X-Raym is offline   Reply With Quote
Old 04-26-2022, 02:58 PM   #26
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 9,875
Default

Edited.
X-Raym is offline   Reply With Quote
Old 05-11-2022, 02:30 PM   #27
bignottalle
Human being with feelings
 
Join Date: May 2022
Posts: 1
Default

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 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.

Last edited by bignottalle; 05-16-2022 at 12:35 PM.
bignottalle is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 04:17 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.