Home Assistant support for MotionEye cameras limited. I created a custom component with auto-discovery and actions for my pan tilt zoom security camera.
You can find the Home Assistant MotionEye component on Github.
I’ve been working on automating my garage workshop. For me, it was important to be able to use MotionEye to control the camera. I find that a dedicated UI for a CCTV system is a nice way to control home security. At the same time, we use Home Assistant as our hub for everything in the house. I wanted to make this integration easier and more native to Home Assistant cameras.
Our IOT is DIY.
But any IP camera should work with MotionEye and the technique described here.
Home Assistant Security Cameras
The typical MotionEye configuration in Home Assistant uses the mjpeg camera. This supports both still images and video streaming. However, it has two main weaknesses:
- Each camera must be configured and added individually.
- MotionEye actions cannot be triggered by Home Assistant.
This means the user is left with two potential “hubs” for their devices. A pure Home Assistant UI would be preferable to me over something like a custom panel.
But what about the MotionEye community add-on?
This is no different than a custom panel. It requires loading the full MotionEye UI in an iframe.
To create a native integration with Home Assistant, I reverse engineered the MotionEye API. The process of signing requests with a password is quite simple. This means it is relatively easy to interact with MotionEye directly from the backend Python code executed by Home Assistant.
When the custom component is added, it automatically detects all MotionEye cameras as Home Assistant starts up. It can be configured from the Home Assistant UI or from a configuration file. The only two configuration parameters that should be changed are the URL and the password. In general, you want to use the admin+basic auth for full control of the cameras. All of this can be configured with YAML as well, of course:
motion_eye: hosts: - url: "http://motion-eye.local" username: !secret motion_username password: !secret motion_password
Upon restart, Home Assistant will automatically create camera
entities for each camera found at http://motion-eye.local
with the appropriate MotionEye camera name. Each camera entity will contain all of the MotionEye camera attributes.
A Raspberry Pi with MotionEyeOS installed will have a web UI on port 80. I have multiple Raspberry Pi Zero Ws, and I just add each as a separate integration to Home Assistant. Their configuration URLs are http://192.168.0.161
, etc.
If you’re trying to connect to a MotionEye instance between Docker containers (or Kubernetes pods), you need to make sure that the Home Assistant instance can access the target URL. For example, you should be able to to curl http://192.168.0.161
. I happen to run Kubernetes for all of my home automation, so I actually use the URL http://motion.home.svc.cluster.local:8765
for one of my integrations.
When in doubt, you can use the “Network Inspector” feature of your browser while using MotionEye:
In the above screenshot, the correct configuration URL would be https://cameras.snowy-cabin.com
. When running Ingress, I have seen configuration URLs like http://192.168.0.14:8123/api/hassio_ingress/7BYKXJ640FS5Ko-o5D9Sq8ZYBo5B7XzFbSUcPSxL-yQ
(screenshot of network inspector).
Likewise, when you press an action button on a camera, you should see a similar request made.
Taking a snapshot is a “camera action” built-in to MotionEye.
It is one thing you might want to do from Home Assistant. I’ll use a more complete example of actions below.
Pan Tilt Zoom Security Camera
In order to monitor various CNC cuts, I installed a Pan-Tilt HAT on my Raspberry Pi security camera. I’ll use this as an example of why a native Home Assistant integration for MotionEye is useful.
If you're new to Raspberry Pi, the popular CanaKits are a great place to start. I prefer to buy the Raspberry Pi 4, power adapter, micro SD cards, and heatsinks separately. Not only is this cheaper, but it reduces e-waste.
The following are affiliate links to other parts I used in this project. I never link to a product that I have not personally used.
Preview | Product | |
---|---|---|
Raspberry Pi Camera Module V2-8 Megapixel,1080p (RPI-CAM-V2) | ||
MakerFocus Raspberry Pi 4B Servo Motor Controller PWM Kit, 2-DOF Pan-Tilt HAT for RPi Light... |