MotionEye, home assistant, camera motion, automation

Ok, got it! It looks like this will work. I read the documentation and this might do the trick. I am not a developer, so I have no idea what the web hook command should be. I am more like a “copy-edit-paste” guy.
Can you give me an example of the format? I need some guidance, and the rest will be easy for me.
Thank you a lot!!
3

1 Like

This might work:

Create an input_boolean in home assistant and call it something like “motion_detected”. Use the webhook to set the state of the entity to “on”. Then set an automation that will reset it to off when the state changes to on.

Then you can base your motion automations on whenever the switch state changes to on.

So it would look like this:

/api/states/input_boolean.motion_detected

body:
{
“state”: “on”
}

1 Like

I think you could also do like this

/api/services/input_boolean/turn_on

body:
{
“entity_id”: “input_boolean.motion_detected”
}

my apologies, I just realized you cant use a regular “switch” like that - it has to be an input_boolean

It looks like you have figured it out.
I created this boolean: input_boolean.motion_stairs
and I am trying to figure out how to call the webhook.
I am looking all over the internet with no luck. As I said before, I am not a developer and I have no idea on how to achieve these commands.
The webhook textbox (in the motioneye) is a single line text box. I dont see how i can put your code into use:

/api/services/input_boolean/turn_on

body:
{
“entity_id”: “input_boolean.motion_detected”
}

Also I have setup a password for my HA.

I guess I have to also use a url where the command should be sent.
All my reading have led me to this (which is obviously wrong, but it’s something):
http://192.168.1.3:8123/api/states/input_boolean.motion_stairs but I have to continue my url to enter the password and also change the state of the boolean: x-ha-access: MYPASSWORD and “state”: "on"

Can you help me write my url?
Thank you!

i did a whole write up on the config with mqtt binary sensor, feel free to cut and paste. Also you can use an android as a web cam!

or use it as a remote to control the downstairs!!

1 Like

does this work?

http://192.168.1.3:8123/api/services/input_boolean/turn_on?entity_id=input_boolean.motion_stairs&api_password=YOUR_PASSWORD

There might be a problem with the password though. I think Home assistant expects it to be part of the url, but if you select “POST (json)” in motionEye OS, all the parameters in the url are sent as a json body, and the password will not be part of the url.

If it does not work, you can try creating a script that turns on the input_boolean for you. A script can be triggered with a plain url and no json body, so you can just use the POST (query) option, and put this in the url:

http://192.168.1.3:8123/api/services/script/my_motion_script?api_password=YOUR_PASSWORD

Let me know if you succeed :slight_smile:

1 Like

Yea, I tried your first suggestion and It came with this error

Login attempt or request with invalid authentication from 192.168.1.3

So I guess you are right.

I tried the second url and it just worked fine! Thank you so much!

To recap:

MotionEye can send a web hook on home assistant by using this url:

http://192.168.1.3:8123/api/services/script/camdetecon?api_password=1234

But in order for this to work, you have to:

Make a script that will turn on an input_boolean in order for the automation to work.

Webhook>Script>Boolean>Automation

It sounds like a lot of things but it is actually easy if you know what you are doing.

Great :slight_smile:

Maybe you could even just use the script itself to do whatever you need to do and then get rid of the input boolean and the corresponding automation.

Scripts are great and they work with conditions also.

do you think the webhook is better than curl?

It will also be cleaner! Great tip. Thanks.

I absolutely have no idea what is the difference between them or what each of them do. I found webhook more convenient or maybe “easier” for a noob like me.

lol im a noob too, thats why im asking. i just started home assistant last week. Anyways either way it works, just wondering about speed or response time, maybe someone knows how to check it!
But i also found this, if anyone wants to start up their own mjpeg stream with another device running linux and stream to motioneyeos i found this:


or this:

The notification is immediate. I am using it since the day @anderstbl gave me the solution it is working perfect. So far no problems. It is just how sensitive (or correct) your motion detection settings are on Motioneye.

have you tried any infrared cameras? or the bcm2835 pi module? what settings do you use on motioneyeos? Also anybody used opencv with this either remotely or locally?

No I havent tried any of these. The settings are very tricky on the motion detection. I really cant tell you what settings I use, because it depends on the video size, the noise of the camera, the lighting (artificial or physical or both), the colors and I cant think what else… The documentation or the tooltips are not very helpfull, you just have to play with it.

Has anyone had problems with the bcm2835-4vl2 with motion and infrared? if i use motion it doesnt respond as well if i were to use https://github.com/jacksonliam/mjpg-streamer/tree/master/mjpg-streamer-experimental. i thought motion had issues with infrared maybe?

Any chance we can see a sample of said script?

I’m still trying to get this to work, I couldn’t figure out @sycohexor 's method…

Thanks in advance!

Sure, here you go:
Go to Motioneye and open Motion notifications
Turn on call a web hook
on the Web Hook URL use this:

http://192.168.1.3:8123/api/services/script/camdetecon?api_password=1234

Note this ~script/camdetecon?api~
This should be the same name as your script!

Select the POST (query) on the HTTP Method field.

Make sure you change to you own homeassistant ip and use your own password. If you havent set a password for homeassistant web interface, then do it by following this guide here:

All the above are just half way for setting up the whole thing. What you just did was have Motioneye notify the homeassistant when there is motion detected. Now you are going to setup homeassistant to do some automations when motion is detected by motioneye.

So:
You need a script which will do some actions when motion is triggered:
open scripts.yaml

camdetecon:
  alias: Camera Motion Detection ON
  sequence:
  - data:
      data:
        method: alarm
      message: chime
    service: notify.jarvis_lenovo

I have a Lenovo tablet and I have lannouncer setup on it. This enables me with the cool feature to have a text announced (like: Sir, Someone is outside.) or have a chime sound. You can do whatever.

If interested, here is the lannouncer setup:

A tip:
Go to Motioneye and then go to Motion Detection and change the Motion Gap to 30 or maybe 60 seconds. That way you wont have constant notifications when someone is just ringing your doorbell waiting for you to open the door.

I hope everything is clear. Feel free to ask anything.

Edit:
I simplified the thing by just doing everything inside the script. If you want, you can have a boolean turn on and off by using the script. Then you can have an automation that will read the boolean state and do anything when the boolean turns on.
I just thought the script can do all I want, so there is no need for me to have a boolean and an automation.

8 Likes

How can motion eye to simply trigger a state change with detected motion? …I mean without the script and all… ideally MQTT seems like the way to go, I just can’t seem to make it work with the codes posted. What am I missing?

I’ve tried your setup and it doesn’t seem to work for me since I don’t have a notify.jarvis_lenovo.

If HA can see the state change in developer tools, I can figure out how to make HA do automations, I just can’t seem to pass the detected motion to HA…

Any help is appreciated.

Thanks