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:
- You have to enable Web Station on your DSM (I’m running DSM 6.0.2)
- Enable “Personal Website” with PHP 5.6 under “General Settings” in Web Station
- 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