MotionEye config

I’m getting an ‘invalid config’ error with Zoneminder (MotionEyeOS) running on a different Raspberry Pi with a USB webcam attached to it.

zoneminder:
  host: http://motioneye.local

camera:
  - platform: zoneminder

Anyone know what might be going on here?

Looks like you are attempting to use the zoneminder component with MotionEye. This won’t work. You will need to install zoneminder from https://www.zoneminder.com/, or integrate your cameras in a different way.

For some reason I was under the impression that MotionEyeOS was a convenient wrapper for ZoneMinder…wonders never cease.

Anyway, I did get the stream to show up from MotionEye using the generic MJPEG component. That works fine, but I was hoping to use the motion sensing stuff for automation. Oh well.

I have an SD card with ZoneMinder and one with MotionEyeOS. Maybe MotionEye support will be added some day. Until then, I can try to figure out ZoneMinder.

MotionEye (and by extension MotionEyeOS are a convenient wrapper for motion, which is perhaps where your confusion has arisen.

Glad you got the camera feed working. MotionEye supports webhook outputs, which you might be able to use to call into the HASS API. In addition the underlying motion software can run arbitrary commands, which you can use to integrate with HASS via MQTT (mosquitto_pub) or HTTP (curl).

I’d be interested to know how well ZoneMinder performs on a Pi. I’ve used both MotionEye and ZoneMinder and ZM definitely uses more resources (but then it does more).

Yeah. the options for motion notifications are email, webhooks (GET, POST [query, form, and json]) and “Run a Command”.

So I know what “email” means. :stuck_out_tongue_winking_eye:

MQTT seems like it makes the most sense. But I haven’t really gotten it to work yet. Will see what happens, I suppose.

Using the “Run a command” notification you could try something like this:

mosquitto_pub -h <broker> -t cameras/<camera_id>/motion -m ON

Then in your HASS config:

binary_sensor:
  - platform: mqtt
    state_topic: cameras/<camera_id>/motion

The question is how to get the sensor to return to the off state, since I don’t think MotionEye will alert you when the motion event finishes. You could do this with an automation which just resets the state after a few seconds.

Use AppDaemon with Momentary Switch module to turn it into a momentary switch.

Yeesh, well it seems that MotionEyeOS follows the “just enough OS” philosophy and has a read-only file system. Meaning that mosquitto_pub is not an available command. Nor, for that matter, are things like, ya know, Apt.

I think it’s ridiculous how an OS that can run on a toaster is just too much for some people.

But curl is installed. So I guess I should figure out how to use that as well. I know how to use Curl to download things from websites, but that’s about it.

I can do Debian or Ubuntu and install MotionEye on top of that instead of MotionEyeOS, I guess…:sleepy:

There is a curl example on the HTTP Binary Sensor docs, which should get you started.

Yay! I got something to work!

I replaced MotionEyeOS with Ubuntu Mate 16.04 and MotionEye (plus mosquitto). I set up my camera to look at the door of my studio.

This is the command I’m using in MotionEye under the “Motion Notifications” tab:

 mosquitto_pub -h 192.168.1.xxx -u <username> -P <password> -t cameras/StudioCam/motion -m "ON"

This is what goes in my configuration.yaml:

 mqtt:
   broker: 192.168.1.xxx
   port: 1883
   username: <username>
   password: <password>

 binary_sensor:
   - platform: mqtt
     name: "Studio Motion"
     state_topic: "cameras/StudioCam/motion"
     device_class: motion

I did sort of get the Curl command to work as well. The important lesson for me was that you don’t have to add anything to configuration.yaml when using HTTP components.

This is the Curl command I entered in MotionEye under the “Motion Notifications” tab:

 curl -X POST -H "Content-Type: application/json" -d '{"state": "on", "attributes": {"friendly_name: "studiomotion"}}' http://192.168.1.xxx:8123/api/states/binary_sensor.studiomotion

The problem with both of these approaches (MQTT and Curl), as @robconnolly said, is that the sensors just stay at “ON” forever after motion is detected. So I either have to figure out how to use that Python script that @DrJeff linked to, or find some other solution if there is one.

2 Likes

I previously handled this by making the sensor a momentary trigger with minimum trigger time.
This was enough for me to create automation based on motion from cameras.

  1. Create Script that makes Sensor ON>>wait 5 seconds>>sensor OFF for example
  2. set motioneye to trigger this script upon motion detection

This allows you to track how often motion is triggered

You may go one step further and replace timeout with something into script to verify if motion event is still occurring.

That’s a good idea. How are you doing this?

I have made a bash script that looks like this:

 #!/bin/bash
 mosquitto_pub -h 192.168.1.xxx -u <username> -P <password> -t cameras/StudioCam/motion -m "ON"
 sleep 10s
  mosquitto_pub -h 192.168.1.xxx -u <username> -P <password> -t cameras/StudioCam/motion -m "OFF"

and called it in MotionEye with:

 bash mqtt-motion.sh

I also tried simply:

 mosquitto_pub -h 192.168.1.xxx -u <username> -P <password> -t cameras/StudioCam/motion -m "ON"; sleep 10s; mosquitto_pub -h 192.168.1.xxx -u <username> -P <password> -t cameras/StudioCam/motion -m "OFF"

in the Motion Notifications field, but neither of these things appear to change the state of the sensor when there’s motion, even though I can trigger the state manually by executing the exact same commands from the terminal. :confused:

put the full path to mosquitto_pub

/usr/bin/mosquitto_pub -h 192.168.1.xxx -u <username> -P <password> -t cameras/StudioCam/motion -m "ON"

I’ve set this up the other day and it looks interesting. Haven’t had too much time to play with it.
https://shinobi.video/

I still have the same problem after adding the full path.

Shinobi looks pretty cool. Uses FFMPEG, which HA clearly supports. And that video is adorable. Not sure if it will run on a Pi though. That’s kind of my own fault. I need a grown-up computer.

OK. I had to reboot MotionEye for some reason because the MJPEG stream started messing up as well. Now the motion sensor works and I have my first working automation:

 - action:
   - alias: light.studio
     data:
     entity_id: light.studio
     service: light.turn_on
     alias: Turn on light when I enter studio
     id: '1499546682238'
   trigger:
   - entity_id: binary_sensor.studio_motion
     from: 'off'
     platform: state
     to: 'on'

MotionEye can do that out of the box:

image

1 Like

so what do i need for a command or webhook to send to google homeassistant text to speech alert? i have motioneyeos on a raspberry pi 2, i might just install motioneye on top of stretch with pihole though or something, but i also run another raspberry pi 3 with hassbian.

You can use the mqtt example from above. Then create an automation that reacts on that Change.

###MOTIONEYEOS CONFIG###
motion notifications run command:

curl -X POST -H "x-ha-access: PASSWORD" \
    -H "Content-Type: application/json" \
    -d '{"state": "on", "attributes": {"friendly_name": "downstairscam"}}' \
    http://remoteipaddress:8123/api/states/binary_sensor.downstairscam

motion notifications end command:

curl -X POST -H "x-ha-access: PASSWORD" \
    -H "Content-Type: application/json" \
    -d '{"state": "off", "attributes": {"friendly_name": "downstairscam"}}' \
    http://remoteipaddress:8123/api/states/binary_sensor.downstairscam

Of course i did it for both cams!
###HASS CONFIG####

Make sure and use the user login for motioneyeos not the admin
configuration.yaml:

camera :
  - platform: mjpeg
    name: UpstairsCamera
    mjpeg_url: http://camipaddress:8081
    username: username
    password: password

  - platform: mjpeg
    name: DownstairsCamera
    mjpeg_url: http://camipaddress:8082
    username: uername
    password: password

binary_sensor:
 - platform: mqtt
   name: "UpstairsCam"
   state_topic: "cameras/UpstairsCamera/motion"

 - platform: mqtt
   name: "DownstairsCam"
   state_topic: "cameras/DownstairsCamera/motion"

automation.yaml

- action:
  - data:
      entity_id: media_player.something_group
      message: Intruder Alert Downstairs!
    service: tts.google_say
  alias: motion downstairs
  condition: []
  id: '########'
  trigger:
  - entity_id: binary_sensor.downstairscam
    platform: state
    to: 'on'
- action:
  - data:
      entity_id: media_player.something_group
      message: Intruder Alert Upstairs!
    service: tts.google_say
  alias: motion upstairs
  condition: []
  id: '########'
  trigger:
  - entity_id: binary_sensor.upstairscam
    platform: state
    to: 'on'

thanks for all the help people!!

1 Like