Motion trigger light, but only during certain time

I have a scene that turns a light on when motion is detected using one of the motion detectors of my alarm system. I’m using the following code to do it. However, I want the light to come on only during certain times. I found code that should do this (see second set of code) however, I have not successfully integrated the code. Can a LUUP expert here help? I’ll also open to any complete different suggestions on how to tackle this.

Current LUUP Code:
local sensorDeviceNo = 32
local lightDeviceNo = 27
local period = 60

local SS_SID = “urn:micasaverde-com:serviceId:SecuritySensor1”
local SP_SID = “urn:upnp-org:serviceId:SwitchPower1”

function checkLastTrip()
local lastTrip = luup.variable_get (SS_SID, “LastTrip”, sensorDeviceNo) or os.time()
if (os.difftime (os.time(), tonumber (lastTrip)) >= period) then
luup.call_action (SP_SID, “SetTarget”, {[“newTargetValue”] = 0}, lightDeviceNo)
else
luup.call_delay (“checkLastTrip”, period)
end
end

luup.call_delay (“checkLastTrip”, period)

return true

Timing LUUP code, that I’m trying to integrate:
local t = os.date(‘*t’)
local current_second = t.hour * 3600 + t.min * 60 + t.sec – number of seconds since midnight
local min_time_in_seconds = 16 * 3600 + 0 * 60 – 16:00
local max_time_in_seconds = 21 * 3600 + 15 * 60 – 21:15

if (current_second > min_time_in_seconds) and (current_second < max_time_in_seconds) then
– do something
else
return false
end