Binding Request: Synology Surveillance Station

Is it correct that the Motion event only works when the Recording Schedule in Surveillance Station is set to Motion Detection? I would like to use Continuos recording, but also get motions detected in Openhab.

Any ideas to make this work?

I assume so. The binding only sees events generated by Surveillance Station.

1 Like

Is it possible to add Surveillance Station with 2FA enabled?

2018-09-21 23:50:01.107 [hingStatusInfoChangedEvent] - ‘synologysurveillancestation:station:survsta’ changed from OFFLINE (COMMUNICATION_ERROR): Errorcode: 403 to OFFLINE (COMMUNICATION_ERROR): Errorcode: 0

It seems to be possible to implement 2FA, however your Thing will be disconnected again as soon as Surveillance Station requests a new login (SID) or is restarted. Why don’t just create an 1FA user with surveillance access only?

you are completely right. I’ve the bad habit to logon with my own user which is admin…
Gonna check it out.

@Pavion - thank you very much for your nice binding. really helpful one observation and one question:

  1. can you tell, in which directory of the openhab installation your binding is storing the snapshot images?
    Im interested to use these jogs for a python script, which analyses these automatically, when a new image emerges. Using your binding would be handy, as the image is “in the system” and any other inquiry at synology or the IP cam could be avoided.
    I understand, that openhab builds all html pages on the fly, but “somewhere” there should be the image as jpg. - maybe there is another approach. Thanks for a hint.

  2. the current jar of the surevilance station binding doesnt install automatically on my fresh Openhabian installation. The log shows following ERROR, which can be easily resolved with the installation of two features, as described here: [BTicino/OpenWebNet] New openHAB2 binding ready for testing

2018-10-16 20:40:38.114 [WARN ] [org.apache.felix.fileinstall        ] - Error while starting bundle: file:/usr/share/openhab2/addons/org.openhab.binding.synologysurveillancestation-2.4.0-SNAPSHOT.jar

org.osgi.framework.BundleException: Could not resolve module: org.openhab.binding.synologysurveillancestation [200]

  Unresolved requirement: Import-Package: org.eclipse.jdt.annotation; resolution:="optional"

  Unresolved requirement: Import-Package: org.jupnp.model.meta

	at org.eclipse.osgi.container.Module.start(Module.java:444) ~[?:?]

	at org.eclipse.osgi.internal.framework.EquinoxBundle.start(EquinoxBundle.java:383) ~[?:?]

	at org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundle(DirectoryWatcher.java:1260) [10:org.apache.felix.fileinstall:3.6.4]

	at org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundles(DirectoryWatcher.java:1233) [10:org.apache.felix.fileinstall:3.6.4]

	at org.apache.felix.fileinstall.internal.DirectoryWatcher.startAllBundles(DirectoryWatcher.java:1221) [10:org.apache.felix.fileinstall:3.6.4]

	at org.apache.felix.fileinstall.internal.DirectoryWatcher.doProcess(DirectoryWatcher.java:515) [10:org.apache.felix.fileinstall:3.6.4]

	at org.apache.felix.fileinstall.internal.DirectoryWatcher.process(DirectoryWatcher.java:365) [10:org.apache.felix.fileinstall:3.6.4]

	at org.apache.felix.fileinstall.internal.DirectoryWatcher.run(DirectoryWatcher.java:316) [10:org.apache.felix.fileinstall:3.6.4]

Hi Martin and thank you for your feedback!

The snapshots are not stored, why should they normally? The Image item is always being populated with the latest snapshot, discarding older one. You might need to use some rule to save this image if needed (it’s basically a Base64 string). You might also skip openHAB and use a simple PHP script from inside your Python directly. See this forum post for more details (second script):
https://www.synology-forum.de/showthread.html?84259-Mjpeg-stream-und-jpeg-Snapshot-über-web-API-abfragen

The second issue is a known one while using the latest openHAB snapshot instead of stable version. With snapshot, some dependencies are deactivated by default, which can cause different problems and exceptions. Only registered bindings (with installation from within PaperUI) are allowed to install additional features. As this binding is not (yet?) integrated, no automatic installation is possible. On the other hand, supplying the same dependencies with the binding would but swell the jar size and overall installation overhead and could cause version conflict.

Please contact me, if you have further questions.
Best regards
Pav

1 Like

Hello,
Trying to configure, i think i got all parameter right but it doesn’t work

http://diskstation:5000/webapi/query.cgi?api=SYNO.API.Info&method=Query&version=1&query=SYNO.SurveillanceStation.Camera

Gives me succes:true

http://diskstation:5000/webapi/auth.cgi?api=SYNO.API.Auth&method=Login&version=6&account=YOUR-USER&passwd=YOUR-PASSWORD&ession=SurveillanceStation&format=sid

gives me false ( of course i replace user and pass…)

Thanks

Does this binding work with QNAP version of Surveillance Station?

Can’t prove it, but I assume no. It’s a completely different application, which just happens to have a similar name.

Hi,

I installed the binding ( v0.29-alpha ) today for my OpenHAB 2.3. Configuration works fine and also the Snapshot works. For Video it’s not working so far… I tested manually getting the URL from REST API and got the following stream URL :

http://diskstation.local:5000/webapi/entry.cgi?api=SYNO.SurveillanceStation.Stream.VideoStreaming&version=1&method=Stream&format=mjpeg&cameraId=4&StmKey=\"aa08174f67a8f2da67ec4289efd44ff4\"

When putting this URL into the browser I also get an error code 105. If I manually remove the escaped quotes from StmKey it’s working in the browser and also in OpenHAB (looks like ...&StmKey=aa08174f67a8f2da67ec4289efd44ff4 ). Is this somehow configurable or someone knows why openhab can’t deal with the escaped quotes?

I just found that there is already an issue for: https://github.com/nibi79/synologysurveillancestation/issues/26

Regards,
Michel

would you happen to have the jar file for this release?

You can find the jar file here: Releases · nibi79/synologysurveillancestation · GitHub

Thnx… why did i not see that :slight_smile:

Hi Michel!

As you’ve already figured out, the API is responding with a quoted URI, as stated in latest Surveillance Station API documentation v.2.8. This behavior seems to cause random issues depending on browser / playback software. In fact, in binding’s issue #26 you’ve found an user had an issue with StmKey not being quoted.
As it is, I’d rather leave the URI unchanged and hope for Synology to make it somehow… universal someday.

P.S. Just tested on my setup: both quoted and unquoted URIs were working in browser and VLC as well.
Your thoughts on this are welcome.

Best regards
Pav

Hi Pav,

as a workaround I created a new dummy item for the URL and then created a rule which does the string replacement. The basically does:
Cam_Dome_Snapshot_Live.postUpdate( Cam_Dome_Snapshot_Live_Uri_Mjpeg_Http.state.toString.replaceAll("\"", "" ) )

But later I also got the problem with leading 0 where this doesn’t work anymore. So I was further searching for a solution and maybe found (script from here https://forum.iobroker.net/viewtopic.php?t=4101&start=20#p46159) some good one which maybe could also be applied to your solution. The idea is to have a php script which does the authentification inside so the url is somehow static.

<?php
// Configuration
$user = "display";  // Synology user
$pass = "somepassword";  // Password
$ip = "192.168.10.64";  
$port = "5000";  
$cameraID = $_GET["CamID"];  // ID for the camera
$cameraStream = $_GET["stream"];
// You can change the stream by adding ?stream=0/1/2 to the url. For example: www.yourdomain.com/snapshot.php?stream=2
// 0: Live stream | 1: Recording stream | 2: Mobile stream
// Default value is stream 0
if ($cameraStream == NULL) {
        $cameraStream = "0";
}

// Authentification and get SID
$json = file_get_contents('http://'.$ip.':'.$port.'/webapi/auth.cgi?api=SYNO.API.Auth&method=Login&version=3&account='.$user.'&passwd='.$pass.'&session=SurveillanceStation&format=sid');
$obj = json_decode($json, true);
@$sid = $obj["data"]["sid"];

$Cam_Stream_URL = 'http://'.$ip.':'.$port.'/webapi/SurveillanceStation/videoStreaming.cgi?api=SYNO.SurveillanceStation.VideoStream&version=1&method=Stream&cameraId='.$cameraID.'&format=mjpeg&_sid='.$sid;
//set_time_limit(30);
ob_implicit_flush(1);

$fp =  fopen($Cam_Stream_URL, "r");
foreach ($http_response_header as $header) {
    header($header);
}
while($str = fgets($fp, 4096))
{
    echo $str;
}
?>

Maybe it’s possible also for you to get the SID and deliver a static URL without the StrKey?

Regards,
Michel

Nice idea! As you’re already there, you might just try it yourself. With following replacement in your rule you would convert the static snapshot URI (Surveillance_Snapshot_Uri_Static) into a new dummy item (Surveillance_Snapshot_Live_Uri_Static):

Surveillance_Snapshot_Live_Uri_Static.postUpdate(
  Surveillance_Snapshot_Uri_Static.state.toString.replace("entry.cgi", "SurveillanceStation/videoStreaming.cgi").replace(".Camera", ".VideoStream").replace("version=8", "version=1").replace("GetSnapshot", "Stream&format=mjpeg")
)

I’m looking forward to your feedback.

Hi Pav,

thanks for this workaround. It’s working fine:

Regards,
Michel

In my openhab.log I see such message:

2018-11-04 11:41:38.276 [WARN ] [.core.thing.binding.BaseThingHandler] - Handler SynoBridgeHandler of thing synologysurveillancestation:station:1630mqn415001 tried checking if channel homemode is linked although the handler was already disposed

Any idea what is causing this?

Glad it worked!
Your warning I haven’t seen yet though. Is your HomeMode channel linked/enabled? If yes, is it functioning properly? Can you see anything wrong at all? When do you receive this message? Every X seconds/minutes, on every Binding/openHab start, on configuration change?