So just after I have worked this out I need to rework this out for NX Witness as one cant just copy/paste the commands. Not sad to see MotionEye go.
im trying to mess with nx witnessâŚwhere do you add cameras on the media server?
i dont have any problems with connections to cameras on my motioneye, i even use a couple rstp streams over wireless
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?
Hopefully thisâll help someone.
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 /âŚ
So my âonâ command is:
curl -X POST http://192.168.*.*:8123/api/services/homeassistant/turn_on -H 'Authorization: Bearer [TOKEN]' -H "Content-Type: application/json" -d '{"entity_id": "input_boolean.motion_frontcam"}'
and âoffâ command is:
curl -X POST http://192.168.*.*:8123/api/services/homeassistant/turn_off -H 'Authorization: Bearer [TOKEN]' -H "Content-Type: application/json" -d '{"entity_id": "input_boolean.motion_frontcam"}'
I tried this but it didnât work for me, what does is:
for âonâ:
curl -X POST -H "Authorization: Bearer [TOKEN]" -H "Content-Type: application/json" -d '{"state": "on", "attributes": {"friendly_name": "Motion Frontcam"}}' http://192.168.*.*:8123/api/states/binary_sensor.motion_frontcam
and for âoffâ:
curl -X POST -H "Authorization: Bearer [TOKEN]" -H "Content-Type: application/json" -d '{"state": "off", "attributes": {"friendly_name": "Motion Frontcam"}}' http://192.168.*.*:8123/api/states/binary_sensor.motion_frontcam
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.
These are the âCommandsâ to use in MotionEyeâs Motion Detection settings to send âstateâ commands back to Home Assistant.
- In this case, they send API state commands to âturn onâ & âturn offâ an âinput_booleanâ named 'motion_frontcamâ.
Ah sorry, thought i was beeing helpfull.
Ignore these posts pleaseâŚ
Not at all⌠All, info / scripts / codes ARE helpful.
Never be afraid to share man.
well this works!
but I was wondering if someone has a working url for mqtt instead of input boolean.
I tried to adapt yours but without success
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!
well I studied on mqtt service page and tried to adapt a command
curl -X POST http://192.168.2.100:8123/api/services/mqtt/publish -H âAuthorization: Bearer xxxxxxxxxxxxxxxâ -H âContent-Type: application/jsonâ -d â{âpayloadâ: âMOTIONâ, âtopicâ: âcameras/motion/dafangâ, âretainâ: âTrueâ}â
but it doesnât work
Will this curl command work on Hassio?
Indeed. That is the solution I used and it works great!!!
HTTPS
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.
It doesnt matter now, as I am using long-lived tokens.
See this earlier post:
So, if you were using a webhook to call the script, now this is doable using a command_on and command_off. You just have to create a long-lived token.
However, your info can be useful! Thank you for sharing!
yeah i think everyones probably changed the authentication method by now or using mosquitto, anyways nice hearing from you again!
I know this post is all over the place so hereâs a summary for people of what I did. I combined different things.
I am looking to make a motion trigger when my left outdoor camera detects motion. For the sake of this reply, itâs called âleftmotionâ
I use !includes, so my configuration.yaml looks like this (not all is relevant here)
# includes
group: !include groups.yaml
automation: !include automations.yaml
script: !include scripts.yaml
binary_sensor: !include binary_sensor.yaml
sensor: !include sensor.yaml
device_tracker: !include device_tracker.yaml
camera: !include camera.yaml
media_player: !include media_player.yaml
zone: !include zones.yaml
input_boolean: !include inputboolean.yaml
panel_custom: !include panel_custom.yaml
scene: !include scenes.yaml
In my input_boolean.yaml, I added this.
leftmotion:
name: leftmotion
initial: off
icon: mdi:MotionSensor
In my binary_sensor.yaml, I put this. This means when the input it turned on, it automatically triggers the binary_sensor.leftmotion we created above.
- platform: template
sensors:
leftmotion:
friendly_name: left motion
value_template: "{{ states.input_boolean.leftmotion.state == 'on' }}"
device_class: motion
In my scripts.yaml, I added this.
This will be triggered by Motioneye. It will turn the boolean on (which turns the binary_sensor on) then turn it off in 30 seconds.
leftmotion:
alias: leftmotion
sequence:
- service: input_boolean.turn_on
entity_id: input_boolean.leftmotion
- delay: 00:00:30
- service: input_boolean.turn_off
entity_id: input_boolean.leftmotion
Check your config.
Restart Home Assistant.
Modify this for your needs.
**If you use SSL you need to change your IP to reflect that. **
In my case, it becomes https://MYSUBDOMAIN.DUCKDNS.org:8123/api/ etc etc
curl -X POST -H "Authorization: Bearer TOKEN" -H "Content-Type: application/json" -d '{"entity_id": "script.leftmotion"}' http://yourip:8123/api/services/script/turn_on
Get your token here: (only replace the word TOKEN and leave the rest)
Add your curl command here.
No script option
If you choose NOT to run a script, you can follow the rules above but instead.
use this for RUN A COMMAND:
(note this calls for the friendly name in the first part, and the sensor name at the end)
curl -X POST -H "Authorization: Bearer TOKEN" -H "Content-Type: application/json" -d '{"state": "on", "attributes": {"friendly_name": "left motion"}}' http://yourip:8123/api/states/binary_sensor.leftmotion
and in âRUN AN END COMMANDâ use:
curl -X POST -H "Authorization: Bearer TOKEN" -H "Content-Type: application/json" -d '{"state": "off", "attributes": {"friendly_name": "left motion"}}' http://yourip:8123/api/states/binary_sensor.leftmotion
You can use an SSH terminal and run just the curl commands to test it out to make sure it triggers your sensors if you run into issues.
The result, for me, is that I now have a visual in my floorplan that shows me when motion has been triggered beside my house since no one should be there.