Synology Surveillance Station IP Camera

So I’m trying to set this up but fail.
I’m on version 0.35.3 and have a foscam c2 connected to the Synolgy.
I created a user on the Synology with Surveillance Read Only access + in applications: Desktop and Surveillance Allowed.
I get this error when Hass is starting:

17-01-27 20:21:38 homeassistant.loader: Loaded camera.synology from homeassistant.components.camera.synology
17-01-27 20:21:38 homeassistant.bootstrap: Setting up camera
17-01-27 20:21:38 homeassistant.components.camera: Setting up camera.synology
17-01-27 20:21:39 aiohttp.client: Attempt to decode JSON with unexpected mimetype: text/plain; charset="utf-8"
17-01-27 20:21:39 aiohttp.client: Attempt to decode JSON with unexpected mimetype: text/plain; charset="utf-8"
17-01-27 20:21:39 homeassistant.components.camera: Error while setting up platform synology
Traceback (most recent call last):
  File "/srv/hass/hass_venv/lib/python3.4/site-packages/homeassistant/helpers/entity_component.py", line 145, in _async_setup_platform
    entity_platform.async_add_entities, discovery_info
  File "/srv/hass/hass_venv/lib/python3.4/site-packages/homeassistant/components/camera/synology.py", line 134, in async_setup_platform
    cameras = camera_resp['data']['cameras']
KeyError: 'data'

Any idea what that can be?

Same problem here. I have read its an issue with aiohttp. Been broken for a few months :frowning:

I think I’ve figured this problem out, it’s a problem introduced in aiohttp 1.2.0. I opened an issue today against the aiohttp project. https://github.com/KeepSafe/aiohttp/issues/1566

1 Like

well done nugget. Definitely looks like a problem there.

Let’s all request @fafhrd91 to also fix it for 3.4.2 !

So he fixed it for 3.4.3? Why does Ha not have python 3.4.3? Not a python Dev so not sure of the implications.

I am running on the latest HA 0.37.1 on All-in-One raspberry Pi 3. How can I get that fixed?

This has been fixed in aiohttp 1.3 (released 4 hours ago) so we need to get this update in homeassistant and fingers crossed its fixed.

https://github.com/KeepSafe/aiohttp/releases/tag/1.3.0

cool. any idea how we can get it in? :slight_smile:

PR #5821 was already merged to update aiohttp to version 1.3, and PR #5838 was opened to update it again to version 1.3.1

So I suspect it’ll be updated in Home Assistant version 0.38 :slight_smile:

1 Like

Hi,

the synology camera starts working again with 0.38.1.

But today I updated to 0.38.3 and the Camera failed again.

    17-02-15 08:04:58 ERROR (MainThread) [homeassistant.components.camera] Error while setting up platform synology
Traceback (most recent call last):
  File "/srv/hass/hass_venv/lib/python3.4/site-packages/homeassistant/helpers/entity_component.py", line 146, in _async_setup_platform
    entity_platform.async_add_entities, discovery_info
  File "/srv/hass/hass_venv/lib/python3.4/site-packages/homeassistant/components/camera/synology.py", line 80, in async_setup_platform
    params=query_payload
  File "/home/hass/.homeassistant/deps/aiohttp/client.py", line 577, in __iter__
    resp = yield from self._coro
  File "/home/hass/.homeassistant/deps/aiohttp/client.py", line 213, in _request
    proxy=proxy, proxy_auth=proxy_auth, timer=timer)
  File "/home/hass/.homeassistant/deps/aiohttp/client_reqrep.py", line 73, in __init__
    assert isinstance(url, URL), url
AssertionError: http://192.168.2.2:5000/webapi/query.cgi

Just as a datapoint, I’m not seeing this with 0.38.3. Upgraded today and cameras are still working.

Like nugget, mine is also working. Strange

Following this thread, it would be great to have the enable/disable recording functionality. Then you could disable recording when you are home, and have synology do the motion detecting processing on it’s end when you’re not.

Thanks for the contribution

1 Like

Unfortunately, I haven’t been able to find an API to enable/disable recording. Maybe you can browse the API documentation and see if there’s something I missed:
https://global.download.synology.com/download/Document/DeveloperGuide/Surveillance_Station_Web_API_v2.0.pdf

You can start and stop a recording remotely through the API SYNO.SurveillanceStation.ExternalRecording (listed in the document linked above).

How can i detect motion on synology camera?

Regards

The synology itself does the motion detection. You can set the recording mode to always on, or record on motion. I don’t know that you can get the motion events via HA, I haven’t looked into it.

Thanks. I have enabled this under synology but I want to react on move with example light on so I need that HA can trigger this “on move” event but I have always “idle” state.
Regards
Artur

Hi!

I’m not sure whether there is a “native” way of doing this, or not. Anyway, you can easily setup an “interface” between your Synology Surveillance Station and HA. The original idea came from Styxit blog.

The logic is the following: create an Action Rule in Surveillance Station, using External Device as an action device. Since SS only lets you call URL-s instead of executing curl or bash commands, you have to create a PHP interface which translates the commands sent from SS to HA.

So, here’s a simple step-by-step tutorial:

  1. You have to enable Web Station on your DSM (I’m running DSM 6.0.2)
  2. Enable “Personal Website” with PHP 5.6 under “General Settings” in Web Station
  3. make sure you checked the “CURL” extension for PHP under “PHP Settings” in Web Station

If you did all these correctly, you should be able to browse your “web” shared folder on your NAS.

Now, create the interface.
Create a new PHP file with the following contents and name it whatever you want:

<?php
/************************************/
/********** CONFING START ***********/

// Only allow request made by localhost?
// Set this to false if this script is not running on your synology webserver (less secure)
$localOnly = true;

/********** CONFING END *************/
/************************************/
echo time();
// Validate httpHost and/or remote addr?
if ($localOnly) {
  if ($_SERVER['HTTP_HOST'] != 'localhost') {
    // Not locahost
    die;
  }
}

// Set variables
$options = array(
  'state' => isset($_GET['state']) ? $_GET['state'] : false,
// you can insert as many variables here as you want

);
// Remove empty values
$options = array_filter($options);

// Quit if not exactly 1 get values were found
if (count($options) != 1) {
  echo 'invalid options';
  die;
}


// Do Pushover curl
curl_setopt_array($ch = curl_init(), array(
  CURLOPT_URL => "http://YOUR_HA_IP:8123/api/states/sensor.YOURSENSOR",
  CURLOPT_POST => true,
  CURLOPT_HEADER => "Content-Type: application/json",
  CURLOPT_POSTFIELDS => "{\"state\":\"$options[state]\"}"
));
curl_exec($ch);
curl_close($ch);

?>

This is a simple PHP file, which executes CURL commands and communicates with your HA instance through RESTful API. Please note, that I’m not a PHP dev guy (in fact I’m not any kind of coder), so this might not be most elegant PHP code in the universe… But it does the job.

Now, all you have to do is to set up the Action Rule in SS, select External Device as Action device, and use the following URL:
http://localhost/YOUR_PHP_FILE.php?state=WHATEVER_STATE_YOU_WANT_TO_SET

Feel free to modify the PHP code to pass the sensor name AND the status as a variable for example:
http://localhost/YOUR_PHP_FILE.php?sensor=CAM_NAME&state=WHATEVER_STATE_YOU_WANT_TO_SET

That’s it. You have your SS Motion Alert in HA.

Cheers,
Ben