Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Lua Script for triggering a record light on OSX
#1
I have succeeded in coding this Lua script.

It works in conjunction with a bash script which communicates with a ITTT internet activated power socket.
The bash script will run in a terminal if set to be executable and it looks for the presence of a folder in the a certain place within the home folder.

The Bash Script
When the folder is present it sends an internet curl call to activate the socket and so the light. When not present it sends an internet curl call to deactivate the light. The use of the flag variables is so that the script only sends a curl call when the status changes. (to avoid repeated redundant curl calls). There is another folder which is constantly presents which works to trigger the while loop. (bit of clunky programming)

The lua Script
The script is for an action hook, implementation which then writes the folder to the file system and so triggering action of the bash script - running in the background.

I've gone for this clunky way of getting this to work, because I could get a way to make the ITTT curl call directly from the lua script. So perhaps there is a more elegant way of going about this.

Bash Script
Code:
while [ -d "[path to folder]/RECORD_LIGHT_ACTIVE" ]
do
    if     [ -d "[path to folder]/RECORDING" ]
        then
            REC_FLAG=1
        else
            REC_FLAG=0
    fi    
X_FLAG=1

    if     [[ "$REC_FLAG" = "1" ]] && [[ "$PREV_FLAG" = "1" ]]
        then
            X_FLAG=0
    fi
    
    if [[ "$REC_FLAG" = "0" ]] && [[ "$PREV_FLAG" = "0" ]]
        then
            X_FLAG=0
    fi
    
    if     [[ "$X_FLAG" = "1" ]] && [[ "$REC_FLAG" = "1" ]]
        then
            curl -X POST https://maker.ifttt.com/[path to maker channel]
            PREV_FLAG=1
            ECHO -e " RECORD LIGHT ON"
            
    fi
    
    if [[ "$X_FLAG" = "1" ]] && [[ "$REC_FLAG" = "0" ]]
        then
            curl -X POST https://maker.ifttt.com/[path to maker channel
            PREV_FLAG=0
            ECHO -e " RECORD LIGHT OFF"                                    
    fi
done

lua Script
Code:
ardour {
    ["type"] = "EditorHook",
    name = "Record Light Trigger",
    author = "Lawalks",
    description = [[
    Sends an external call for record light.
    ]]
}

function signals ()
    s = LuaSignal.Set()
    s:add ({[LuaSignal.RecordStateChanged] = true})
    return s
end

function factory ()
    return function (signal)
    
        --    print (Session:record_status())    
        --    print (Session:actively_recording())    

        if Session:actively_recording (true)
        then
            os.execute [[mkdir "[path to folder]/RECORDING"]]
            -- print ('recording')
        else
    
            os.execute [[rmdir "[path to folder]/RECORDING"]]
            -- print ('not recording')
        end
    end
end
Reply
#2
Wow, this is super neat! Great job with this, where can I get me one of these ITTT lights?
Welcome to Zombocom
Reply
#3
Well done! I've been waiting for someone to come up with this form day one after adding Lua scripting! Controlling lights was one of the first use-cases that came to mind.

Using indirection via a bash script is not a bad thing here. That way you can keep the credentials for accessing the light(s) separate.
Did you try calling a bash script that calls curl? os.execute("/path/to/my_light_on_script.sh");


PS. If you could get away with HTTP Get (not POST), you can make the http request directly from Lua e.g. print(ArdourUI.http_get("https://ardour.org/"))
Reply
#4
(08-30-2018, 01:06 PM)lawalks Wrote: I have succeeded in coding this Lua script.

Wow thanks man! When I started out building a studio I fetched a big red/green traffic light to hang outside and signalise recording time... it's still sitting in my "waiting projects" pile - but now there's no excuse anymore Smile

MMM
Reply
#5
(08-30-2018, 01:19 PM)Nikolaus Gullotta Wrote: Wow, this is super neat! Great job with this, where can I get me one of these ITTT lights?

This is the smart plug that I bought:

https://www.amazon.co.uk/gp/product/B07B...UTF8&psc=1

(08-30-2018, 01:55 PM)x42 Wrote: Well done! I've been waiting for someone to come up with this form day one after adding Lua scripting! Controlling lights was one of the first use-cases that came to mind.

Using indirection via a bash script is not a bad thing here. That way you can keep the credentials for accessing the light(s) separate.
Did you try calling a bash script that calls curl? os.execute("/path/to/my_light_on_script.sh");


PS. If you could get away with HTTP Get (not POST), you can make the http request directly from Lua e.g. print(ArdourUI.http_get("https://ardour.org/"))


Thanks:
I did try to make a direct call to the bash script from within Lua but couldn't get it to work. I'm no expert, and I may well have been doing something wrong. The work around with mkdir and rmdir is clunky, but reliable I guess.

As for the your other idea for making a direct internet call, that's certainly worth exploring, thanks.
Reply
#6
An update on the project

I have been concerned that for smartplug to be triggered I'm sending a signal to a cloud based server. So I started to search around and came across the sonoff units. The basic sonoff is even cheaper than the plug I bought - and the key thing is that it can be reprogrammed.
For me the purpose of the reprogramming is so that I can send a call to the switch directly without going to some cloud server. The advantage here is speed and security. I have found that if I use local IP address as a number (192.168.x.x) then the switching is almost immediate on going into record and stop.

Here are some links for getting started.


http://sonoff.itead.cc/en/products/sonoff/sonoff-basic

https://github.com/arendst/Sonoff-Tasmota/wiki

https://www.arduino.cc/en/Main/Software


There are quite a few tutorials out there for going in this direction.
Reply
#7
(09-12-2018, 08:33 PM)lawalks Wrote: An update on the project

I have been concerned that for smartplug to be triggered I'm sending a signal to a cloud based server. So I started to search around and came across the sonoff units. The basic sonoff is even cheaper than the plug I bought - and the key thing is that it can be reprogrammed.
For me the purpose of the reprogramming is so that I can send a call to the switch directly without going to some cloud server. The advantage here is speed and security. I have found that if I use local IP address as a number (192.168.x.x) then the switching is almost immediate on going into record and stop.

Here are some links for getting started.


http://sonoff.itead.cc/en/products/sonoff/sonoff-basic

https://github.com/arendst/Sonoff-Tasmota/wiki

https://www.arduino.cc/en/Main/Software


There are quite a few tutorials out there for going in this direction.

Cool stuff! I have been using X10 home automation gear for years and this could be very easily adapted to use heyu and the X10 CM11 controller via the serial port, or sending off to a RPi to include GPIO contacts to trigger nearly anything.
ASUS M5A99FX PRO R2.0 w/AMD FX™-8350 Eight-Core Processor 32GB RAM
M-Audio Delta 1010 / Echo AudioFire 12
Mixbus v7.x on Fedora 33 64bit
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)