Hi guys,
With my Fibaro HC2 I could start/stop my ip cam recordings on my synology nas with a script. Is there a way I could do this with indigo? I am not that good with programming, I would be great If someone could convert this to Python.
Here is the script I used with my HC2:
start recording:
-- User configurable variables
local login = "admin"
local password = "xxxxxxx"
local cameras = {1,3}
local action = "start"
-- System variables
local selfID = fibaro:getSelfId()
local ip = fibaro:get(selfID, 'IPAddress')
local port = fibaro:get(selfID, 'TCPPort')
local Synology = Net.FHttp(ip, tonumber(port))
local API_AUTH_ERROR_CODE = {
[100] = "Unknown error.",
[101] = "The account parameter is not specified.",
[400] = "Invalid password.",
[401] = "Guest or disabled account.",
[402] = "Permission denied.",
[403] = "One time password not specified.",
[404] = "One time password authenticate failed."
}
local API_RECORD_ERROR_CODE = {
[400] = "Execution failed.",
[401] = "Parameter invalid.",
[402] = "Camera disabled."
}
-- Discover available APIs and corresponding information
payload = "/webapi/query.cgi?api=SYNO.API.Info&method=Query&version=1&query=SYNO.API.Auth,SYNO.SurveillanceStation.ExternalRecording"
response, status, errorCode = Synology:GET(payload)
if tonumber(status) == 200 then
jsonTable = json.decode(response);
if jsonTable.data["SYNO.API.Auth"].maxVersion >= 2 and jsonTable.data["SYNO.SurveillanceStation.ExternalRecording"].maxVersion >= 2 then
fibaro:debug("Synology API version OK")
pathAuth = jsonTable.data["SYNO.API.Auth"].path
pathRecord = jsonTable.data["SYNO.SurveillanceStation.ExternalRecording"].path
fibaro:debug("Synology API Auth path = "..pathAuth)
fibaro:debug("Synology API Surveillance Station Record path = "..pathRecord)
-- Create new login session
payload = "/webapi/"..pathAuth.."?api=SYNO.API.Auth&method=Login&version=2&account="..login.."&passwd="..password.."&session=SurveillanceStation&format=sid"
response, status, errorCode = Synology:GET(payload)
if tonumber(status) == 200 then
jsonTable = json.decode(response);
if jsonTable.success == true then
SID = jsonTable.data.sid
fibaro:debug("Synology API Auth SID = "..SID)
for i = 1, #cameras do
-- Start or stop external recording of a camera
payload = "/webapi/"..pathRecord.."?api=SYNO.SurveillanceStation.ExternalRecording&method=Record&version=2&cameraId="..cameras[i].."&action="..action.."&_sid="..SID
response, status, errorCode = Synology:GET(payload)
jsonTable = json.decode(response);
if jsonTable.success == true then
fibaro:log("OK")
fibaro:debug('<span style="color:green;">Synology Surveillance Station '..action..' recording for camera "'..tostring(cameras[i])..'" OK</span>')
else
fibaro:log("Erreur")
fibaro:debug('<span style="color:red;">Synology Surveillance Station '..action..' recording for camera "'..tostring(cameras[i])..'" FAILED : '..API_RECORD_ERROR_CODE[tonumber(jsonTable.error.code)]..'</span>')
end
end
-- Destroy current login session
payload = "/webapi/"..pathAuth.."?api=SYNO.API.Auth&method=Logout&version=2&session=SurveillanceStation&_sid="..SID
response, status, errorCode = Synology:GET(payload)
else
fibaro:log("Erreur")
fibaro:debug('<span style="color:red;">Error : '..API_AUTH_ERROR_CODE[tonumber(jsonTable.error.code)]..'</span>')
end
else
fibaro:log("Erreur")
fibaro:debug('<span style="color:red;">Error : API Authentication failure</span>')
end
else
fibaro:log("Erreur")
fibaro:debug('<span style="color:red;">Error : Synology API version is too old : <b>DSM 4.0-2251</b> and <b>Surveillance Station 6.1</b> are required</span>')
end
else
fibaro:log("Erreur")
fibaro:debug('<span style="color:red;">Error : Can not connect to Synology server</span>')
end