I have a Synology running surveilance station that can run an action rule when motion is detected. This rule can be a Http GET or POST (REST command). I can’t figure out how to create a switch that listens to this command and thus can be controlled from the synology. I would like to have an automation rule started when a command is received from the Synology. Therfore i was thinking of a switch to be able to trigger on any change.
Can anyone help me?
I think I was wrong, and your answer was correct. But I can’t figure out how a HTTP Binary Sensor should look like in the Configuration.yaml file. Could you give an example?
Do you know a hass sensor that can react on a simple GET command with params. I’am asking this because could not find a way to create an action rule in Surveillance station that sends a POST command.
I found a way to translate a GET command from an action rule in Synology Surveillance Station into a POST command by running a little php scrip in synology’s web server. This scrip creates a sensor an then changes the state from OFF to ON and OFF again.
The get command in the action rules looks like:
<?php
// usage
// http://SYNOLOGY-IP/home_assistant/hass.php?sensor=camera0&name=Motion Camera 0
// Will create a binary_sensor with the name "camera0" and friendly name "Motion Camera 0"
// and toggles its state from off to on and off again
//
echo $_SERVER['HTTP_HOST'];
echo '<br>';
// Set variables from cmd parameters
$options = array(
'sensor' => isset($_GET['sensor']) ? $_GET['sensor'] : false,
'name' => isset($_GET['name']) ? $_GET['name'] : false,
);
// Remove empty values
$options = array_filter($options);
// Quit if not exactly 2 get values were found
if (count($options) != 2) {
echo 'invalid options';
die;
}
$headr = array();
$headr[]="x-ha-access: PASSWORD";
$headr[]="Content-Type: application/json";
// See https://home-assistant.io/components/binary_sensor.http/#examples
// for more information about binary_sensor
// Send POST ON command, this will create a sensor with then name "sensor" and friendly name "name"
// and set the state to on
curl_setopt_array($ch = curl_init(), array(
CURLOPT_URL => "http://$_SERVER[HTTP_HOST]:8123/api/states/binary_sensor.$options[sensor]",
CURLOPT_POST => true,
CURLOPT_HEADER => false,
CURLOPT_HTTPHEADER => $headr,
CURLOPT_POSTFIELDS => "{\"state\":\"on\", \"attributes\": {\"friendly_name\": \"$options[name]\"}}"
));
curl_exec($ch);
curl_close($ch);
echo '<br>';
sleep(10);
// Send POST OF command
curl_setopt_array($ch = curl_init(), array(
CURLOPT_URL => "http://$_SERVER[HTTP_HOST]:8123/api/states/binary_sensor.$options[sensor]",
CURLOPT_POST => true,
CURLOPT_HEADER => false,
CURLOPT_HTTPHEADER => $headr,
CURLOPT_POSTFIELDS => "{\"state\":\"off\", \"attributes\": {\"friendly_name\": \"$options[name]\"}}"
));
curl_exec($ch);
curl_close($ch);
echo '<br>';
?>
Hi,
I have problems understanding what the POST commands should look like and I am not good at PHP. What does the resulting HTTP commands look like for On and Off state changes?