I have been changing my motion detector and camera setup. This caused me to revisit the code for starting and stopping external camera recording on the Synology Surveillance Station. I have made the code more suitable for use with PLEG - which has some advantages over using normal Vera scenes. The main benefit is that PLEG will check its timers after a restart so can stop a recording that was started before Vera crashed.
I have my ip cameras set to continuously record one frame/second onto their internal microSD cards. With careful choice of resolution and H.264 compression bit-rate, I can get 14 days of history on a 16GB card. This is a useful feature as it reduces the loading on the network and NAS drives. The recordings would be lost, of course, if a thief stole the camera! :
To back this up, I use PLEG to start a seven frame/second full-resolution recording of a camera on the Surveillance Station when a nearby motion detector is tripped whilst the house alarm is armed. PLEG will stop the recording after a timed interval.
The following routine is placed in PLEG’s Startup LUA. It provides the function SsRecordControl(, <camera#> [,<camera#>]). Where is either “start” or “stop” and <camera#> is one or more camera numbers previously set up on Surveillance Station and separated by commas. E.g. SsRecordControl(“start”,1,3) starts recording cameras 1 and 3.
[code]–
– Start or Stop recording one or more cameras on Synology NAS Surveillance Station
– SsRecordControl(action, camera# [,camera#]…)
– action = “start” or “stop”, camera# = 1 to cameras on NAS-SS
function SsRecordControl(…)
local args = {…}
if #args < 2 then luup.log(“SsRecordControl: Missing arguments”) return false end
local action = string.lower(args[1])
if (action ~= “start”) and (action ~= “stop”) then
luup.log(“SsRecordControl: Invalid action: " .. args[1])
return false
end
– Request session ID from NAS-SS
local nasip = “192.168.1.253”
local account = “XXXXXXXX”
local passwd = “XXXXXXXX”
local sidurl = “http://”..nasip..”:5000/webapi/auth.cgi?api=SYNO.API.Auth&method=Login&version=2"..
“&account=”..account..“&passwd=”..passwd..“&session=SurveillanceStation&format=sid”
local status, response = luup.inet.wget(sidurl,30)
local sid = string.match((response or “”),‘{"sid":"(.+)"}’)
if sid == nil then luup.log(“SsRecordControl: No SID from NAS-SS: " .. (response or “nil”))
return false
end
– Request action for each camera in argument list
for icam=1,#args-1 do
local cameraid = args[icam+1]
local ssurl = “http://”..nasip..”:5000/webapi/SurveillanceStation/extrecord.cgi?“..
“api=SYNO.SurveillanceStation.ExternalRecording&method=Record&version=1&cameraId=”..cameraid..
“&action=”..action..”&_sid="..sid
status, response = luup.inet.wget(ssurl,5)
local success = (string.match(response or “”,‘{"success":true’) ~= nil)
if success then luup.log("SsRecordControl: Camera “..cameraid..” “..action)
else luup.log(“SsRecordControl: Error on “..action..” camera “..cameraid..”: " .. (response or “nil”))
end
end
– Terminate session
local endurl = “http://”..nasip..”:5000/webapi/auth.cgi?api=SYNO.API.Auth&method=Logout&version=2”
status, response = luup.inet.wget(endurl,5)
end[/code]
This function can now be used in PLEG Actions by placing a single line into the LUA tab. Here is a simple example of the PLEG configuration:
Triggers
AlarmSet Alarm Armed is On
BackPIR Back PIR is Tripped
Schedules
TimerRecB StartType: Self ReTrigger, StopType: Interval, 30 seconds
Conditions
BackStartRec [Repeat=No] BackPIR and AlarmSet and (AlarmSet; BackPIR)
BackStopRec [Repeat=No] !TimerRecB and (BackStartRec; !TimerRecB)
Actions
BackStartRec This PLEG, StartTimer, timerName=TimerRecB
LUA: SsRecordControl(“start”,1)
BackStopRec LUA: SsRecordControl(“stop”,1)