Motioneye integration

Hello there @alexandresalome, awesome write-up!! Thanks a million for putting this all together in the first place.

I’ve been carefully following it step by step and started troubleshooting the different steps when I tried it end-to-end and wouldn’t work. So far I managed to “unit test” steps 1 up to 7 but I got stuck in number 7. I would swear that the rest API call isn’t successful:

Marcs-Air:~ marc$ curl -XPOST http://192.168.1.5:7999/1/detection/start
curl: (52) Empty reply from server
Marcs-Air:~ marc$ curl -XPOST http://192.168.1.5:7999/1/detection/stop
curl: (52) Empty reply from server

I think it is important to state that I’m running the duckdns add-on. I’m saying this because in step #4 I had to fine tune the commands like this

from:

curl -XPOST http://home-assistant:8123/api/webhook/motioneye-camera1-started

to

curl -XPOST https://MYDUCKDNSADDRESS.ORG:8123/api/webhook/motioneye-camera1-started

(note that I have a local definition in my router in /etc/hosts to redirect the lookup of MYDUCKDNSADDRESS.ORG to the local IP

Marcs-Air:~ marc$ nslookup MYDUCKDNSADDRESS.ORG
Server:		192.168.1.1
Address:	192.168.1.1#53

Name:	MYDUCKDNSADDRESS.ORG
Address: 192.168.1.5

I’ve now tested both over http

Marcs-Air:~ marc$ curl -XPOST http://192.168.1.5:7999/1/detection/start

curl: (52) Empty reply from server

Marcs-Air:~ marc$ curl -XPOST http://192.168.1.5:7999/1/detection/stop

curl: (52) Empty reply from server

and over https

Marcs-Air:~ marc$ curl -XPOST https://192.168.1.5:7999/1/detection/start

curl: (35) LibreSSL SSL_connect: SSL_ERROR_SYSCALL in connection to 192.168.1.5:7999

and it won’t work. Motioneye won’t display any change in the toggle for motion detection and I don’t get any notification email either.

If I do a telnet into the port, I do see that a service is listening. And if I check the add-on log, I see I’m warned about the lack of authentication and the lack of encryption, so I’m ruling out the add on being not properly configured.

Marcs-Air:~ marc$ telnet 192.168.1.5 7999
Trying 192.168.1.5...
Connected to MYDUCKDNSADDRESS.ORG.
Escape character is '^]'.
^C

Anybody running motioneye as an add-on and duckdns add-on could help me finish this up? Should the REST calls above change this section in all my defined cameras at once or is there any global setting hidden somewhere?

thanks!!

OK! I’m going to answer to my own points above.

No, there is not a global command.

The menu itself won’t change when the REST API is used. The only way to check if the commands sent are successfully enabling Motion Detection is by activating the option “Show Frame Changes”. When you run the automation go and check whether you see frames highlighting movement.

I followed the above steps and got to a point where the UI displays the camera stream and motionEye detects motion (pink squares, images are saved once motion is detected).

However, I’m running out of ideas to get the motion notification to work. I’m running motionEye as an addon to Home Assistant. I can’t get anything inside motionEye’s Run a command box to work. Are there any logs or loglevels that I could use? I reckon it has something todo with the containers but I’m not too familiar with containers.

I finally managed to get the webhooks runnings (verified on a shell command), i.e. the commands themselves. The last bit now is the trigger from motionEye to run a command.

1 Like

Ok, solved it myself. My previous setup was

  • Router fritz.box with open external ports 443 and 8123 to the raspi 4 (no DynDNS on fritz.box)
  • Home Assistant running on raspi 4
  • DuckDNS as add-on
  • motionEye as add-on
  • an old iPhone serving as a guinea pig camera

I had had to install NGINX as an add-on. I just added my domain in the config

domain: xxxx.duckdns.org
certfile: fullchain.pem
keyfile: privkey.pem
hsts: max-age=31536000; includeSubDomains
cloudflare: false
customize:
  active: false
  default: nginx_proxy_default*.conf
  servers: nginx_proxy/*.conf

but contrary to the documentation

In the configuration.yaml file, some options in the http: section are no longer necessary for this scenario, and should be commented out or removed:

  • ssl_certificate
  • ssl_key
  • server_port

my configuration.yaml still contains

ssl_certificate: /ssl/fullchain.pem
ssl_key: /ssl/privkey.pem

The two commands for motionEye are now …

/usr/bin/curl -X POST https://xxxx.duckdns.org:443/api/webhook/motioneye-camera1-started
/usr/bin/curl -X POST https://xxxx.duckdns.org:443/api/webhook/motioneye-camera1-ended

Just the curl didn’t do the job, we need the absolute path of curl in that particular docker container. Also note the different ports.

Sortings things out took me all afternoon ;-/

-Stefan.

1 Like

I’ve noticed not only does the motioneye GUI not reflect the changes to motion detection when using the webcontrol command, the actual config files (camera-1.conf) remain unchanged. The only way to tell if it’s enabled from the GUI is to have “Show Frame Changes” and the number in the top right corner will then change to a “-” when it’s disabled. If it’s enabled and no motion is detected it will be a “0”.

I was also having an issue with high CPU usage causing intermittent results with this making it hard to know what is going on so I disabled two cameras which made me stumble upon this “quirk”:

When you disable a camera from the motioneye gui by switching “video device” to off it changes the numbering of the cameras. So for example I have 6 cameras and I disable camera’s 4 and 5, camera 6 becomes camera 4. I was hoping to disable cameras when not in use but this makes controlling them very problematic.

I’ve figured out the numbering is determined by the order in motion.conf not the name of the file. So if you’re having problems with turning motion detection on with webcontrol it’s worth checking that file to make sure the order is the same as the numbering!

EDIT: I’ve also just noticed that making changes in the GUI and then applying them will also change motion detection to whatever it’s set to in the GUI. So if you had disabled it with webcontrol and then apply the settings in the GUI and it’s set to on there, it will come back on.

This is really awesome!

I’ve been able to easily make my motionEye OS with a USB camera running on an RPi3 separate from my HA RPi installation used as a motion sensor.

Worked great!

Might be good to edit step 5 as follows:

binary_sensor:
  - platform: template
    sensors:
      camera1_motion:
        friendly_name: "Camera - Mouvement"
        device_class: motion
        value_template: "{{ is_state('input_boolean.camera1_motion_detected', 'on') }}"
1 Like

Thanks for this awesome guide.
I didn’t manage to get the binary sensor working.
I verifed that automations
“Motioneye - Camera1 - Motion started” and
“Motioneye - Camera1 - Motion ended” triggered, but the input_boolean is never updated.
What am I missing? Some new requirements since some HA update?

I found the answer in one of my other automations. I need to add data: {} after the service in the action part like this:

- alias: "Motioneye - Camera1 - Motion started"
  trigger:
  - platform: webhook
    webhook_id: motioneye-camera1-started
  action:
  - service: input_boolean.turn_on
    data: {}
    entity_id: input_boolean.camera1_motion_detected

Now everything is working fine.

Thanks for you help on this. That made it work for me.

altho I still have one nasty thing.
When there s motion detected I have 10 sec delay on the webhook command.

therefore making a sanpshot 10sec later …
Did you notice that also?

hello
I have installed motioneye on my raspbian buster pi3b+ and plugged in an old usb microsoft camera.
It works great, i get the stream inside motioneye.
Once i install the motioneye integration on my hassio pi3b+ with:

host: http://192.168.x.xxx:8765
and admin/user credentials

the camera is unavailable and doesn’t receive the stream from the raspbian buster motioneye camera.
What is wrong?
Is it because the host is in http and not https? All access is locally.

Hello all,

If you’re motionEye enthusiast this post announcing a new custom component may be relevant to your interests, and may significantly simplify some of the automations in this thread:

Thanks.

1 Like

Can you please share your motioneye addon config? Here is mine:

motion_webcontrol: true
ssl: true
certfile: fullchain.pem
keyfile: privkey.pem
action_buttons: []
log_level: trace

What am I missing?

Yeh that is the same as mine. So when i want to turn recording on and of I then send a a webcontrol value through a rest command.

  ai_motion_right_side_capture_on: 
    url: 'http://yourip:7999/3/config/set?emulate_motion=on'
    method: get
    
  ai_motion_right_side_capture_off: 
    url: 'http://yourip8:7999/3/config/set?emulate_motion=off'
    method: get

Where do you exactly are you writing this? is this into the motion configuration section of motioneye?

Thank you so much for sharing this!!!

this custom component gives us the binary sensor for using it in automation.

raspi4 with Motioneye server – add-on in home assistant – connected the integration to localhost – all entities are working fine

thank you

btw: I love this community here, always helpful and friendly.

Is there any easy way to get motion detection from particular camera into automation?

Define easy….

I use a webhook from motioneye notification section, which triggers an automation in HA

yes, I have noticed it, but what to put in there webhook url?

so you enter something like:
http://your-home-assistant:8123/api/webhook/some_hook_id
type will be ‘post(query)’

and then create a trigger for it:

automation:
  trigger:
    - platform: webhook
      webhook_id: "some_hook_id"

I’m trying to use webhook to trigger event from my camera (motioeye) but can’t get it working:

alias: 'Auto Terace Lights '
description: Automaticaly switch light on terace from terace ptz camera motion notification
trigger:
  - platform: webhook
    webhook_id: terace
condition:
  - condition: time
    after: '18:00'
    before: '09:00'
action:
  - service: switch.turn_on
    target:
      entity_id: switch.terrace_lights
  - delay:
      hours: 0
      minutes: 5
      seconds: 0
      milliseconds: 0
  - service: switch.turn_off
    target:
      entity_id: switch.terrace_lights
mode: restart

and in motioneye I have done:
image
where address is: https://myhomeassistant:8123/api/webhook/terace

Time is 05:00 AM
Why is it not working?