MotionEye, home assistant, camera motion, automation

Alright, here is another question.
I have home assistant and motioneye installed in the same raspberry.
Everything is setup and the two are working perfect.
I now want to have homeassistant notifying me if there is any motion from the camera.
How do I do that? I have to say that I want to avoid MQTT as I dont fully understand how it works, and it sounds like a fuss to me. So if there is another way I would be grateful.
MotionEye has 2 options:
call a web hook
run a command
Can I put them to use? If yes, how?

5 Likes

Sounds interesting. Perhaps you can find some inspiration by looking at the documentation about the RESTful API in home assistant, which will let you change state of entities with a webhook. https://home-assistant.io/developers/rest_api/ (scroll to the POST section)

1 Like

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!