MotionEye, home assistant, camera motion, automation

Definitely not going to perform on a RPi because they are a low power (including performance) device

Sorry but I am very new to this topic.
Where is the motion.conf file?

and where to run the curl -s “http://192.168.1.xxx:7999/1/detection/status”

My HA is installed in a NUC with ubuntu 18.04 desktop (supervised) so somewhere there I will find the motion.conf file, and I will run it (the curl -s …) as a linux command?

My motion.conf was here:
/etc/motioneye
Yes, you run curl as a linux command.

1 Like

Thanks a lot! It works! But how can I send picture from cam when motion detected to chrome push?

Do you mind updating your original post here to NOT say it was solved using the now outdated ?api_password= ? I wasted a good bit of time trying to figure out why this wasn’t working.

This is from this post which is newer than mine and I posted my procedure to get it working. So I am pasting this here too:

I am pasting my code below and all the procedures. I hope I wont miss anything. If I do, just tell me what it is, so I will edit my post to keep this clean.

Some notes:

  • Names and aliases and entities and paths etc, have to be changed to match yours. I am just pasting mine…
  • My automations are split in different files, so the indentation is according to that. Dont be confused. All you have to do is to indent accordingly if you dont have your automations split as I do.
  • Deleted usernames or passwords or IPs will be like this: [password]
    You will have to replace the brackets too

Here we go:
First of all, you have to create and whitelist the folder where the snapshots will be created.

configuration.yaml

  whitelist_external_dirs:
    - /home/homeassistant/.homeassistant/www/images

Go to HA and open the side menu. Click on your profile picture and then go to Long-Lived
Access Tokens
and create one. Copy the token and paste it in the step below.

Open motioneye and select your camera. Go to Motion Notifications and choose Run A Command .
paste this:

curl -X POST -k -H “Authorization: Bearer [TOKEN] ” -H “Content-Type: application/json” -d ‘{“entity_id”: “ [script.stairsmotion] ”}’ https:// [HomeAssistantIP] :8123/api/services/script/turn_on

Now every time MotionEye will detect motion, it will trigger the script you are about to create:

Script

stairsmotion:
  alias: Stairs Camera Motion Detection ON
  sequence:
  - service: automation.trigger
    entity_id: automation.stairs_camera_snapshot

The above script, triggers an automation. The reason I am triggering the script and not the automation, is because I have more actions in my sequence, but I am only pasting the automation here.
So, the purpose here is to create a script that will do a series of actions and one of them is take a snapshot and also notify you. And now lets create the automation to get the snapshot and the notification:

Snapshot Automation

- alias: 'Stairs Camera snapshot'
  trigger: []
  condition: []
  action:
  - service: camera.snapshot
    data:
      entity_id: camera.stairs
      filename: /home/homeassistant/.homeassistant/www/images/snapshot.jpg
  - condition: state
    entity_id: group.presence_tracker
    state: not_home
  - delay: 00:00:01
  - service: notify.telegram_argy
    data:
      message: 'Motion Detected.'
      data:
        photo:
          file: /home/homeassistant/.homeassistant/www/images/snapshot.jpg
          caption: 'Motion Detected.'

This Automation will create a snapshot and send it to me via Telegram if I am not home.

4 Likes

Motion sensor works, but for some reason I constantly get Login attempt or request with invalid authentication from … in notifications.

I think this describes my problem.

I had the problem
Login attempt or request with invalid authentication
But the reason of this was that camera had no authentication.
And the camera.yaml config had
authentication: basic
Now both (camera and config) have basic authentication and the error is gone.

I can’t get passed the Login attempt or request with invalid authentication problem. I have basic authentication turned on for the Motioneye OS camera and it is set like that in config, which I think is default anyway but I added to be sure (after trying without). I have the Long-Lived Access Token and I’m using the Run Command like argykaraz detailed above. I’m guessing everything is almost correct otherwise HA OS wouldn’t be warning me of the failed login attempt.

Has anyone else had this problem and worked out what is causing it please?

The authentication settings in motioneye are just for viewing the camera from any device. It has nothing to do with this setup. So dont mind this…
Next, try to open a command line from the machine that has Motioneye installed and paste the command ON or OFF in the terminal and see what the error is. This would help a lot.

I thought the authentication was a strange problem, since there access token should permit access regardless, thanks for clearing that up. I’m away from home for a while but I’ll do that when I get back. Thank you for your response.

Has anyone had any luck in getting motion eye to send a command to HA using a Token? I just get a authentication error.

When I ran the command from my motioneye device I had a few “Could not resolve host:” errors. I was able to resolve these by removing any spaces from the parts of the command that had quotation marks. The only remaining error is “invalid character in header”. I’ve copied and pasted your curl command and just changed the relevant information, so I can’t see where the problem is.

@kingphil123 I have been able to achieve the desired result with a Webhook though.
https://[HomeAssistantIP]:8123/api/webhook/[Some Number]
HTTP Method - POST (form)
You can then trigger an automation with a webhook referencing [Some Number].

I’ll try and discover what the invalid character in the curl command is and I’ll post here if I find out what the problem is.

  • “Could not resolve host” usually means DNS error. Are you by any chance trying to do this through the internet? I mean, do you use any ddns services (instead a local IP) to execute the command? You should be using the internal IP of your HA instance, for example the IP should start by 192.168…
  • Invalid character, could be a bracket. Have you removed them all?
  • Copying the code from this forum has caused me some errors in the past with the quotes. Make sure to copy the command in a notepad and delete and REwrite the quotes (single and double), and then paste this in the terminal.
    Hope some of the above helps.

It was the quotes! :man_facepalming:t2: It always seems to be the basics that catch me out.

Thank you for taking the time to resolve this @argykaraz, very much appreciated.

1 Like

I’ve installed the motioneye add-on. Do I still have to use the REST way for communication with HA or is there a direct way integrated in the add-on?

Hi
Thank you for your the above work.
I’ve got issue on motion detection. i have to move the camera then the motion detected and if I wave, it doesnt trigger the motion detector. im using esp32cam.
and also when it trigger it take about 21seconds to activate thedetector.

thank you for your help.

Hey,

Thanks for your detailed explanation!
Howevever, I am very bad at this as I can’t get it to work.
Here is the command I tried:
curl -X POST -H “Authorization: Bearer eyJ0eXAI3NMEACMUIYLs” \ -H “Content-Type: application/json” \ -d ‘{“state”: “on”, “attributes”: {“friendly_name”: “camera”}}’ \ http://192.168.1.xx:8123/api/states/binary_sensor.camera

I did reduce the size of the token here. Y the way is there an easy way to test the command outside of motioneye?

1 Like

try replacing ’ and “” like this -

curl -X POST -H “Authorization: Bearer eyJ0eXAI3NMEACMUIYLs” -H “Content-Type: application/json” -d “{‘state’: ‘on’, ‘attributes’: {‘friendly_name’: ‘camera’}}” http://192.168.1.xx:8123/api/states/binary_sensor.camera

If you have CURL installed on a pc you can try it from the command line

Hello everybody,
Maybe one of you can help me.

i would like to make the motioneye webcontrol functional.

I use a RPi 4 where HA runs on it with the addon motioneye.

when I enter the ip the motoneye page is displayed, but the camera stream is not.

no matter whether in the browser chrome, edge, opera.

what and where do i still have to do so that the webcontrol works?

my intention is to link HA and motion via curl.

Unbena1nnt

1 Like

Thank you.

This method worked for me perfectly.