Raspberry pi zero camera - surveillance system

Dear all, I am sure that this is not the first time someone tries to do this project, but I was not able to find the info a need in the forum (sorry if dup)

I am trying to build a basic surveillance system for my home with HomeAssitant installed in a Raspberry Pi 2 and a Raspberry Pi Zero with camera. I was able to install everything correctly but now I am struggling to capture any motion detected from Pi Zero and trigger and event in HA.

How should I configure to capture those events? How should pi Zero trigger them?

thanks so much in advance. BR, Fernando

What are you using to capture video on the pi Zero? Motion? If so then you should be able to directly link the feed via the IP address of the pi Zero. I actually recently built one of these but have not integrate to HA yet (fighting with the pi Zero W dropping wifi).

I believe Motion will send a trigger event. Have you considered MotionEyeOS? I have read that it is highly configurable and easier to send notifications.

I have motioneyeos. I am missing how I connect this to homeassistant. I am quite new to this platform, which platform should I use for it? Thks

I use MotionEye installed in docker and currently integrating it with HA, what I got so far:

Video stream:
In MotionEye enable “video streaming” and you get MJPEG stream in port 8081 which you can set as camera component in HA or better set as “picture-glance” in Lovelace-UI and you’ll get live stream on frontend and because it’s not component it will not give connection errors like cameras usually do

Motion sensor:
In HA create binary sensor then in MotionEye enable “motion detection” and in “motion notifications” put two commands:
Run A Command:

curl -X POST -H “x-ha-access: PASSWORD” -H “Content-Type: application/json” -d ‘{“state”: “on”, “attributes”: {“friendly_name”: “Motion”,“device_class”: “motion”}}’ http://IP:8123/api/states/binary_sensor.motion

Run An End Command

curl -X POST -H “x-ha-access: PASSWORD” -H “Content-Type: application/json” -d ‘{“state”: “off”, “attributes”: {“friendly_name”: “Motion”,“device_class”: “motion”}}’ http://IP:8123/api/states/binary_sensor.motion

Switches (work in progress)
To send commands from HA to MotionEye need to enable API (default port 7999), find “motioneye.conf” and “motion.conf” files and edit these lines:

motioneye.conf:

motion_control_localhost false

motion.conf:

webcontrol_parms 1
webcontrol_localhost off

in HA:

command_shell:
start_motion_detect: “curl http://IP:7999/1/detection/start”
pause_motion_detect: “curl http://IP:7999/1/detection/pause”

Until here everything works.

Problem I’m having is to get status state from this address:

http://IP:7999/1/detection/status

it returns HTML type:

<!DOCTYPE html>
<html>
<head><title>Motion 4.1</title></head>
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
<body>
<a href=/1/detection>&lt;&ndash; back</a><br><br><b>Camera 1</b> Detection status PAUSE
</body>
</html>

and I don’t know how to extract only one word from it, what need is only last word “PAUSE”

cool thks! I will try to work on this during the weekend

this is the camera integration in HA

- platform: mjpeg # camera setup with motioneye
  name: Front Door
  mjpeg_url: http://IP:8701
  still_image_url: http://IP:8765/picture/1/current/?_username=admin&_signature=<your key>  
  username: admin
  password: !secret camera_password

Still image info is in the “video streaming section” > snapshot url

the motion trigger is as described above.
you need to put it in “motion notification section”

this is the run command and corresponding sensor

curl -X POST -H “x-ha-access: HAPassword” \ -H “Content-Type: application/json” \ -d ‘{“state”: “on”, “attributes”: {“friendly_name”: “Frontdoor_Motion”}}’ \ http://IP:8123/api/states/binary_sensor.frontdoor_motion

- platform: mqtt  #motioneye sensors
  name: "Frontdoor Motion"
  state_topic: "cameras/frontdoor/motion"  
  device_class: "motion"
  payload_on: "ON"
  payload_off: "OFF"
1 Like

@ haskimo, use a command line sensor and then use the value template to extract what you want.

1 Like

Hi haskimo,
Your post has been an inspiration for me, I finally solved the status feedback received from MotionEye.
This is the procedure that I done:
You need to customize your /etc/motioneye/motion.conf like these:

webcontrol_html_output off
webcontrol_port 7999
webcontrol_localhost off

After that you have to use Command Line Switch as follow:

switch:
platform: command_line
scan_interval: 35
switches:
switch:
command_on: 'curl -k "http://IP:7999/1/detection/start"'
command_off: 'curl -k "http://IP:7999/1/detection/pause"'
command_state: 'curl -s "http://IP:7999/1/detection/status"'
value_template: '{{ value == "Camera 1 Detection status ACTIVE" }}'
friendly_name: Motion Camera 1

Hope this will work also for you.

@krikko I think you meant to indent correctly:

switch:
  - platform: command_line
    switches:
      camera_motion:
        command_on: 'curl -k "http://192.168.1.18:7999/1/detection/start"'
        command_off: 'curl -k "http://192.168.1.18:7999/1/detection/pause"'
        command_state: 'curl -s "http://192.168.1.18:7999/1/detection/status"'
        value_template: '{{ value == "Camera 1 Detection status ACTIVE" }}'
        friendly_name: Motion Camera 1