MotionEye, home assistant, camera motion, automation

No automations set up yet, literally just putting the front_motion binary sensor on the front end for testing purposes. If I manually toggle the input_boolean the template sensor works correctly.

ON:

curl -X POST -k -H "Authorization:Bearer CODE" -H "Content-Type: application/json" -d '{"entity_id": "input_boolean.front_motion"}'  https://192.168.5.101:8123/api/services/homeassistant/turn_on

OFF:

curl -X POST -k -H "Authorization:Bearer CODE" -H "Content-Type: application/json" -d '{"entity_id": "input_boolean.front_motion"}'  https://192.168.5.101:8123/api/services/homeassistant/turn_off

Iā€™ve also tried running the service call homeassistant.turn_on with the entity ID of:

"input_boolean.front_motion"

And that does set the boolean to ON which then marks motion as being on on the template.

After ā€œauthorization:ā€ I have a space. Try it:

ā€œAuthorization: Bearer CODEā€

If you have any problems, you can open a terminal using ssh and test the command from the machine that hosts motioneye and there you will see any errors that come up.

When I throw the command into putty (as root on the machine that hosts the docker that Hass and Motioneye are in) I get:

curl: (35) error:1408F10B:SSL routines:ssl3_get_record:wrong version number

I honestly have no idea what this isā€¦ Did you google it? Could it be a compatibility or a communication problem due to docker? I am not a docker expert, but I think that every container acts as a different machine in docker. That means that Motioneye and HASS should have different ip. That means you should ssh into the machine that has motioneye. Not HASS. And obviously not the main host that has Docker installed.

Are any of these ā€œRun a Commandā€ options (mosquitto_pub or curl) available in the HassOS (Hass.io) Addon of MotionEye?

Yes they are.

@PetrolHead @zoltant7

Hi
I am trying to add the motion switch in my config.
i have live feed from my camera (ffmpeg) and through motioneye addon

I have place the following in my config but the it is always off

- platform: command_line
    switches:
      camera_1:
        command_on: 'curl -k "http://192.168.1.xxx:7999/1/detection/start"'
        command_off: 'curl -k "http://192.168.1.xxx:7999/1/detection/pause"'
        command_state: 'curl -s "http://192.168.1.xxx:7999/1/detection/status"'
        value_template: '{{ "ACTIVE" in value }}'
        friendly_name: Motion Sensor Camera LivingRoom

Should I add something in motioneye - motion notifications?
the 7999 is it a port? my camera in motioneye is at 8081 should I change it?
/1/ is my camera id

any ideas how to proceed?

Yes, I use the following in the Hassio Container

mosquitto_pub -h 10.0.0.11 -t cameras/motion/garage -u [username] -P [password] -m ON

and

mosquitto_pub -h 10.0.0.11 -t cameras/motion/garage -u [username] -P [password] -m OFF
1 Like

You need to customize your motion.conf like this:

webcontrol_html_output off
webcontrol_port 7999
webcontrol_localhost off

Then after a restart you could try if it works by running:
curl -s ā€œhttp://192.168.1.xxx:7999/1/detection/statusā€
from the commandline.

I am so extremely unsatisfied with the performance of motioneyeos (in regards to possible framerates) that I canā€™t imagine running it on the same device as my Hassio. At least not if it is a Raspberry.

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.