Unifi NVR Video - control recording
Posted: Monday 24 July 2017 16:20
I have used the python plugin created by gysmo38 (thanks for that), but somehow my installation keeps having issues from time to time with python plugins. Because of that reason I recreated the functionality in LUA code, which works without an issue for me.
I'm using the function below to turn recording on for my three camera's when I activate my alarm.
Perhaps some other people are looking for the same solution and that is why I'm sharing this with you all.
The variables:
The Function:
An Example:
I'm using a virtual device which has the Unifi camera attached to it. This way I can quickly open the camera preview and can see if they are in recording.
I'm using the function below to turn recording on for my three camera's when I activate my alarm.
Perhaps some other people are looking for the same solution and that is why I'm sharing this with you all.
The variables:
Code: Select all
--Cameras
Device_UVC_IP = "192.168.0.2" -- NVR IP for example 192.168.0.2
Device_UVC_Port = "7080" -- NVR port, default is 7080
Device_UVC_API = "API12345678" -- API key get this from the NVR (Listed as a tab under the user account)
Device_UVC_UVCG3Dome = "UVC G3 Dome" -- Camera name
Device_UVC_UVCG3Dome_ID = "3284710471094891084" -- Camera _id (You can get this from this url: http://192.168.0.2:7080/api/2.0/camera/?apiKey=12345678 . Fill in your own IP address and apiKey
Code: Select all
-- Device is the virtual switch with for example the camera attached
-- Camera is the camera name
-- ID is the camera ID
-- Status is to turn recording Always, Motion or Off
function CameraSetRecordingMode(Device,Camera,ID,Status)
if (Status == "Always")
then
url = 'curl -X PUT --data \'{"name":"' .. Camera .. '","recordingSettings":{"motionRecordEnabled":"false","fullTimeRecordEnabled":"true","channel":"0"}}\' http://' .. Device_UVC_IP .. ':' .. Device_UVC_Port .. '/api/2.0/camera/' .. ID .. '?apiKey=' .. Device_UVC_API .. ' --header "Content-Type:application/json"'
io.popen(url .. ' &')
commandArray[#commandArray +1]={[Device] = 'On'}
elseif (Status == "Motion")
then
url = 'curl -X PUT --data \'{"name":"' .. Camera .. '","recordingSettings":{"motionRecordEnabled":"true","fullTimeRecordEnabled":"false","channel":"0"}}\' http://' .. Device_UVC_IP .. ':' .. Device_UVC_Port .. '/api/2.0/camera/' .. ID .. '?apiKey=' .. Device_UVC_API .. ' --header "Content-Type:application/json"'
io.popen(url .. ' &')
commandArray[#commandArray +1]={[Device] = 'On'}
elseif (Status == "Off")
then
url = 'curl -X PUT --data \'{"name":"' .. Camera .. '","recordingSettings":{"motionRecordEnabled":"false","fullTimeRecordEnabled":"false"}}\' http://' .. Device_UVC_IP .. ':' .. Device_UVC_Port .. '/api/2.0/camera/' .. ID .. '?apiKey=' .. Device_UVC_API .. ' --header "Content-Type:application/json"'
io.popen(url .. ' &')
commandArray[#commandArray +1]={[Device] = 'Off'}
end
end
Code: Select all
--This will turn on recording on the Unifi NVR/Camera and set a virtual switch to On. Use "Off" to turn this off again
CameraSetRecordingMode("Camera",Device_UVC_UVCG3Dome,Device_UVC_UVCG3Dome_ID,"On")