MotionEye integration - How to use the motion_detected event for an automation?

I want to trigger an automation in HA, if motion on my network camera is detected.

Here is my setup:

  • running Home Assistant OS on a RasPi4 (Version 2022.2.6)
  • I’ve intalled the MotionEye addon and configured the integration according to the docs
  • Integration documentaion

In the MotionEye Web UI:

  • I added a network camera to MotionEye (the camera was auto generated in HA)
  • video streaming is turned on
  • motion detection is turned on
  • Call A Web Hook in motion notifications was auto configured
    webhook

I set up a template in my configuration yaml (found it in this forum topic):

template:
    - trigger:
      - platform: event
        event_type: motioneye.motion_detected
        event_data:
          device_id: abc123
      binary_sensor:
      - name: Haustuer Motion
        state: "true"
        device_class: motion
        auto_off: 10

I got device_id from the Web Hook URL. The last part of the URL is “device_id=abc123”

Unfortunately the binary sensors state is “unknown” and doesn’t change. Did I missed something?
I tried to listen for the motioneye.motion_detected event in the developer tools, but nothing is detected.
If I activate the notification via email in the MotionEye Web UI, motion detection is working fine.

3 Likes

Hello fuze,

Same as you, I would like to use the Webhook made by the MotionEye integration to trigger automation, send push notification or other.

But I unfortunately don’t understand how to create a sensor or event to catch the information and use it for automation.

If someone can explain the process and the right way to use this webhook, it could help a lot.

Thank you in advance,
Best Regards,

Gauthier

2 Likes

This worked for me. I would start off by doing some simple debugging:

  1. Turn on recording when motion is detected. If this does not work it means that no motion is being detected.
  2. Copy the webhook URL and paste it in the browser, you should get a message 405: Method Not Allowed
  3. Do you get any errors in the MotionEye plugin Log?
  4. Is homeassistant.local:8123 reachable? Try replacing homeassistant.local the IP of the homeassistant machine
1 Like
  1. Recording on motion is working

  2. When pasting the webhook URL, 405: Method Not Allowed is shown

  3. There are warnings and errors in the log, but I don’t really understand the error messages. Maybe anyone can help with that.

  4. homeassistant.local:8123 is reachable

[s6-init] making user provided files available at /var/run/s6/etc...exited 0.
[s6-init] ensuring user provided files have correct perms...exited 0.
[fix-attrs.d] applying ownership & permissions fixes...
[fix-attrs.d] done.
[cont-init.d] executing container initialization scripts...
[cont-init.d] 00-banner.sh: executing... 
-----------------------------------------------------------
 Add-on: motionEye
 Simple, elegant and feature-rich CCTV/NVR for your cameras
-----------------------------------------------------------
 Add-on version: 0.17.0
 You are running the latest version of this add-on.
 System: Home Assistant OS 7.4  (aarch64 / raspberrypi4-64)
 Home Assistant Core: 2022.2.5
 Home Assistant Supervisor: 2022.01.1
-----------------------------------------------------------
 Please, share the above information when looking for help
 or support in, e.g., GitHub, forums or the Discord chat.
-----------------------------------------------------------
[cont-init.d] 00-banner.sh: exited 0.
[cont-init.d] 01-log-level.sh: executing... 
[cont-init.d] 01-log-level.sh: exited 0.
[cont-init.d] motioneye.sh: executing... 
backing up /data/motioneye/motioneye.conf
[cont-init.d] motioneye.sh: exited 0.
[cont-init.d] nginx.sh: executing... 
[cont-init.d] nginx.sh: exited 0.
[cont-init.d] done.
[services.d] starting services
[services.d] done.
[21:52:00] INFO: Starting motionEye...
    INFO: hello! this is motionEye server 0.42.1
    INFO: cleanup started
    INFO: wsswitch started
    INFO: tasks started
    INFO: mjpg client garbage collector started
    INFO: smb mounts started
    INFO: server started
[21:52:05] INFO: Starting NGinx...
[21:52:06] INFO: Successfully send discovery information to Home Assistant.
/bin/sh: lsb_release: not found
 WARNING: 403 GET /login/?_=1644785755877&_username=_&_signature=89b1fc000b034d02bf5bb7a323442561c5a8c2b3 (127.0.0.1) 2.54ms
/bin/sh: lsb_release: not found
 WARNING: 403 GET /login/?_=1644786081947&_username=_&_signature=6dd13bb6726281fcd1fdc0e6098d39b1c961a406 (127.0.0.1) 3.01ms
/bin/sh: lsb_release: not found
 WARNING: 403 GET /login/?_=1644786600218&_username=_&_signature=27f61da21ccff318ca653ebe634192e8c1ae6f61 (127.0.0.1) 3.24ms
/bin/sh: lsb_release: not found
 WARNING: 403 GET /login/?_=1644786837614&_username=_&_signature=40be861b21f54d0d1822134ec680e59e8a388ae7 (127.0.0.1) 2.62ms
/bin/sh: lsb_release: not found
 WARNING: 403 GET /login/?_=1644786970840&_username=_&_signature=4e0c09e484a016e6077c9a72a2b1f90739ceaa8e (127.0.0.1) 3.62ms
/bin/sh: lsb_release: not found
 WARNING: 403 GET /login/?_=1644790220001&_username=_&_signature=394aa401f6223e31ff181e81dce7e08ee7d57fcc (127.0.0.1) 4.30ms
/bin/sh: lsb_release: not found
 WARNING: 403 GET /login/?_=1644793382578&_username=_&_signature=f039e58a714549f54b721ba7a8b2e24844fc3f4a (127.0.0.1) 3.61ms
/bin/sh: lsb_release: not found
 WARNING: 403 GET /login/?_=1645002822610 (127.0.0.1) 2.32ms
/bin/sh: lsb_release: not found
 WARNING: 403 GET /login/?_=1645002836067 (127.0.0.1) 3.33ms
/bin/sh: lsb_release: not found
 WARNING: 403 GET /login/?_=1645004107432 (127.0.0.1) 2.65ms
/bin/sh: lsb_release: not found
 WARNING: 403 GET /login/?_=1645004153774 (127.0.0.1) 2.70ms
/bin/sh: lsb_release: not found
 WARNING: 403 GET /login/?_=1645004558391 (127.0.0.1) 2.24ms
/bin/sh: lsb_release: not found
 WARNING: 403 GET /login/?_=1645004650254 (127.0.0.1) 3.41ms
/bin/sh: lsb_release: not found
 WARNING: 403 GET /login/?_=1645004898387 (127.0.0.1) 3.03ms
/bin/sh: lsb_release: not found
 WARNING: 403 GET /login/?_=1645008232828 (127.0.0.1) 2.66ms
/bin/sh: lsb_release: not found
 WARNING: 403 GET /login/?_=1645206524338 (127.0.0.1) 2.33ms
/bin/sh: lsb_release: not found
 WARNING: 403 GET /login/?_=1645206573693 (127.0.0.1) 1.97ms
 WARNING: mjpg client connection for camera 1 on port 8081 is closed
/bin/sh: lsb_release: not found
 WARNING: 403 GET /login/?_=1645624402638 (127.0.0.1) 2.56ms
   ERROR: authentication failed for user admin
 WARNING: 403 GET /login/?_=1645624409982&_username=admin&_login=true&_signature=26d6c3e09d91ee23309003392a98bb4b41ef53d2 (127.0.0.1) 4.28ms
/bin/sh: lsb_release: not found
 WARNING: 403 GET /login/?_=1645625122465 (127.0.0.1) 2.63ms
/bin/sh: lsb_release: not found
 WARNING: 403 GET /login/?_=1645625568259 (127.0.0.1) 3.63ms
/bin/sh: lsb_release: not found
 WARNING: 403 GET /login/?_=1645625682912 (127.0.0.1) 2.45ms
/bin/sh: lsb_release: not found
 WARNING: 403 GET /login/?_=1645625728523 (127.0.0.1) 3.65ms
/bin/sh: lsb_release: not found
 WARNING: 403 GET /login/?_=1645625796662 (127.0.0.1) 2.38ms
 WARNING: mjpg client connection for camera 1 on port 8081 is closed
   ERROR: failed to create movie preview for /share/motioneye/Camera1/2022-02-23/15-27-14.mp4: Command '[u'ffmpeg', u'-i', u'/share/motioneye/Camera1/2022-02-23/15-27-14.mp4', u'-f', u'mjpeg', u'-vframes', u'1', u'-ss', u'4', u'-y', u'/share/motioneye/Camera1/2022-02-23/15-27-14.mp4.thumb']' returned non-zero exit status 1
   ERROR: failed to create movie preview for /share/motioneye/Camera1/2022-02-23/15-27-14.mp4: Command '[u'ffmpeg', u'-i', u'/share/motioneye/Camera1/2022-02-23/15-27-14.mp4', u'-f', u'mjpeg', u'-vframes', u'1', u'-ss', u'4', u'-y', u'/share/motioneye/Camera1/2022-02-23/15-27-14.mp4.thumb']' returned non-zero exit status 1
 WARNING: 416 GET /movie/1/playback/2022-02-23/15-27-14.mp4?_username=admin&_signature=90b8cdd6f5f5cc915e6abc0bcd35d17df951ae39 (127.0.0.1) 5.03ms
/bin/sh: lsb_release: not found
 WARNING: 403 GET /login/?_=1645626881499 (127.0.0.1) 2.54ms
/bin/sh: lsb_release: not found
 WARNING: 403 GET /login/?_=1645626913557 (127.0.0.1) 2.51ms

I see that there are a number of authentication errors but i’m not quite sure what they relate to either. They are also followed by /bin/sh: lsb_release: not found which leads me to ask: Are you using the supervised version of HA?

No, I’m running Home Assistant OS on a Raspberry Pi 4 (4GB) and it is updated to the latest version.

When starting the MotionEye addon, I noticed this error in the Home Assistant log:

Error fetching motioneye data: Error communicating with API
15:57:54 – (FEHLER) motionEye
Connection failed to motionEye: Cannot connect to host 127.0.0.1:28765 ssl:default [Connect call failed ('127.0.0.1', 28765)]
15:57:54 – (WARNUNG) /usr/local/lib/python3.9/site-packages/motioneye_client/client.py

It doesn’t seem to matter, if I set ssl to “false” or “true” in the motionEye addon configuration. The error message stays the same. Did you had to set up anything in the MotionEye addon configuration?

What does your MotionEye add on configuration look like?

It’s the standard configuration, I only tried to change ssl from true to false.

action_buttons: []
certfile: fullchain.pem
keyfile: privkey.pem
motion_webcontrol: false
ssl: false

I had the same problem when I started ha again and I solved it by removing Despeckle Filter

I have Despeckle Filter turned off. For me it was turned off by default.

I did a fresh HA OS install on a virtual machine and tried to setup MotionEye. In this installation I do get the motioneye.motion_detected event, when listening to it in the developer tools. No special configuration was needed. Altough I do have similar errors as in my productive HA installation in the addon logs:

/bin/sh: lsb_release: not found
 WARNING: 403 GET /login/?_=1646647695703&_username=_&_signature=27bcac92397187d2ab5735c5917d198ee6260860 (127.0.0.1) 1.00ms
/bin/sh: lsb_release: not found
 WARNING: 403 GET /login/?_=1646647708709&_username=_&_signature=a316811b727c9f1d263484669eab9b8780c64426 (127.0.0.1) 0.99ms
/bin/sh: lsb_release: not found
 WARNING: 403 GET /login/?_=1646647728970&_username=_&_signature=d1fe5962ee051571c9e3136e83266a057dd80054 (127.0.0.1) 1.89ms

For me motionEye motion detection only works with “Motion Triggered” Recording Mode.

With Recording Mode set to Continuous and Motion Detection active my webhook call is not being made. When changing only the Recording Mode it works.