In MotionEye, under motion events, theres an option to send a webook.
I have rpi doing a number of things, one of hwich is a webserver. I wrote a simple handler for the HA api to make it easier to integrate with.
The webhook in MotionEye is just http://blah/ha?action=event&entity=camera_motion
then my handler grabs this, adds the auth header, and sends the relevant API request to HA.
You could, in theory, also turn on the legacy API for HA and do the same thing directly, but i decided for security reasons i didnt want to turn that on.
Sorry
I’m a newbi an I’m a little bit confused about setting motioneye hassio’s addon to make motion notification working…
I’ve tried hassCast setting (i routinely use mqtt via mosquitto broker addon to control switch sensor ecc.) with no luck… I think it’s not possible to send mqtt_publish command with motioneye addon on HASSIO.
Then i tried with a webhook…I’ve setup IFTTT integration, than I’ve copied the right URL (https://mydomain:8123/api/webhook/TOKENfromIFTTintegration/services/script/camdetecon
than i create a script like this MotionEye, home assistant, camera motion, automation but my script never run.
What am I doing wrong?
Has anyone experienced an issue in motion eyes where you can only send a command on motion without the option of a individual on command and a off command?
I’m using “…/api/services/homeassistant/turn_on” & “turn_off” to control an “enitity_id”, in my case an “input_boolean”. However, that could equally be a: script / switch / automation /…
I found an other method of creating a binairy sensor by use of a php-script.
Name it for example motion.php and put it on your web-server in a directory phpscript.
http://SERVER-IP/phpscript/motion.php?sensor=camera0&name=Motion Camera 0&state=on
Will create a binary_sensor with the name “camera0” and friendly name “Motion Camera 0”
and sets its state to “on” and will switch to “off” after 10 seconds.
Here’s the php-script:
<?php
// usage
// http://SERVER-IP/phpscript/motion.php?sensor=camera0&name=Motion Camera 0&state=on
// 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,
'state' => isset($_GET['state']) ? $_GET['state'] : false,
);
// Remove empty values
$options = array_filter($options);
// Quit if not exactly 3 get values were found
if (count($options) != 3) {
echo 'invalid options';
die;
}
$headr = array();
// $headr[]="x-ha-access: PASSWORD";
$headr[]="Authorization: Bearer TOKEN";
$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\":\"$options[state]\", \"attributes\": {\"friendly_name\": \"$options[name]\"}}"
));
curl_exec($ch);
curl_close($ch);
echo '<br>';
// Sleep for 10 seconds
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>';
?>
Replace TOKEN, in the php-script, with your generated long lived token.
I am not an mqtt expert, but I guess you CAN use mqtt publish command instead of the curl command. Just replace Run a command with the same command you would use if you ran mqtt_publish in a terminal. I am not sure about the commands though, but I think it should work. Give it a try!
I know this is a late reply lol, but I used the curl command with the no check certificate like with wget and it worked by adding -k to the beginning of the arguments. Curl -k for example, if anyone’s having issues with trailing video on cam from motion check you capture frames before motion, I had mine at 500 then dropped it to 100 or lower and didn’t have the issue any longer.