Sign inSign up

j3ko/motionberry

By j3ko

•Updated 11 months ago

A lightweight solution for motion detection and video streaming on Raspberry Pi, powered by picamera

Image
Internet of things
1

1.6K

j3ko/motionberry repository overview

⁠Motionberry

A lightweight solution for motion detection and video streaming on Raspberry Pi, powered by picamera2

Tested and optimized for Raspberry Pi Zero 2W with a Camera module v3

⁠Features

  • Support for Dockerized or bare-metal deployments
  • Responsive user interface
  • Motion-triggered recording
  • Triggered snapshots (JPEG)
  • Triggered clip recording
  • Output in raw H.264, mkv or MP4 format
  • RESTful API and webhook events (documentation⁠)
  • Optional notifications via ntfy, Pushover, and webhooks⁠
  • See CHANGELOG.md⁠ for more
Screenshot

⁠Pre-requisites

  • A Raspberry Pi (tested on Raspberry Pi Zero 2W and compatible with other models)
  • A camera module compatible with picamera2 (e.g., Raspberry Pi Camera Module 3).
  • Raspberry Pi OS 64-bit

To install Motionberry as a systemd service on your Raspberry Pi, follow these steps:

1. Clone the repository:

git clone https://github.com/j3ko/motionberry.git

2. Run the installation script:

sudo bash motionberry/scripts/install.sh

To uninstall Motionberry, run the following:

sudo bash motionberry/scripts/uninstall.sh

⁠Docker installation

To install Motionberry using Docker on your Raspberry Pi, follow these steps:

1. Install Docker⁠

2. Run the following command to deploy Motionberry:

docker run --name motionberry \
  --privileged \
  -e PUID 1000 \
  -e PGID 1000 \
  -v <path to config.yml>:/motionberry/config \
  -v <path to capture directory>:/motionberry/captures \
  -v /run/udev:/run/udev:ro \
  -p 5000:5000 \
  j3ko/motionberry:latest

Explanation of Options:

  • --privileged: Required for hardware access, such as the camera module.
  • -e PUID / -e PGID: Set user and group IDs to match your system's user permissions.
  • -v <path>: Map local directories to container paths:
    • <path to config.yml>: Path to your configuration file.
    • <path to capture directory>: Directory where captures will be stored.
  • -p 5000:5000: Maps port 5000 on the host to the container.

Replace <path to config.yml> and <path to capture directory> with appropriate paths on your host machine.

⁠Configuration

For configuration options, refer to config.default.yml⁠.

⁠Notifications

Motionberry supports runtime notifications through flexible REST-compatible services like webhooks, ntfy, and Pushover.

TypeDescription
http_postBasic POST request with raw body
form_postSends as application/x-www-form-urlencoded
json_postSends as application/json
⁠Example: ntfy

Send a plain-text notification via ntfy.sh⁠:

notification:
  motion_started:
    - type: http_post
      url: "https://ntfy.sh/my-motionberry"
      headers:
        Title: "Motion Detected"
        Tags: "camera,warning"
      data: "Motion detected!"
⁠Example: Pushover

Send an alert to your mobile via Pushover⁠:

notification:
  motion_started:
    - type: form_post
      url: "https://api.pushover.net/1/messages.json"
      data:
        token: "${pushover_token}"
        user: "${pushover_user}"
        message: "🚨‼️🚨 Motion Detected! 🚨‼️🚨"

Tip: Environment variables like ${pushover_token} can be used here.

⁠Dynamic Substitution

Notifications support dynamic placeholders. For example, to send the preview and duration of a recorded clip:

notification:
  motion_stopped:
    - type: form_post
      url: "https://api.pushover.net/1/messages.json"
      data:
        token: "${pushover_token}"
        user: "${pushover_user}"
        message: "🚨‼️🚨 Motion Detected (${clip_duration}s) 🚨‼️🚨"
        attachment_base64: "${preview_base64}"
        attachment_type: "image/jpeg"
⁠Supported Notification Actions
Action NameDescription
application_startedTriggered when the application successfully starts.
detection_enabledTriggered when motion detection is enabled.
detection_disabledTriggered when motion detection is disabled.
motion_startedTriggered when motion is detected and recording starts.
motion_endedTriggered when motion ends and a saved file becomes available.
⁠Substitution Keys per Action

These keys can be used inside strings with the ${key} syntax (e.g., ${filename}).

Action NameSubstitution KeyDescription
motion_stoppedfilenameThe name of the saved video.
motion_stoppedfilepathThe full path of the saved video.
motion_stoppedpreview_base64The JPEG preview of the clip in base64 encoding.
motion_stoppedclip_durationThe duration of the recorded clip in seconds.

⁠Reporting Issues

For bugs and issues, please create a GitHub issue here⁠.

Tag summary

Content type

Image

Digest

sha256:6459ae8e6…

Size

484.4 MB

Last updated

11 months ago

docker pull j3ko/motionberry