The motion-ai
solution is composed of multiple components
- Home Assistant - open-source home automation system
- Open Horizon - open-source edge AI platform
Home Assistant add-ons:
MQTT
- messaging broker for all componentsmotion
add-on for Home Assistant - captures images and video of motion (n.b. motion-project.github.io)
Open Horizon AI services:
yolo4motion
- YOLO object detection and classificationface4motion
- FACE detectionalpr4motion
- ALPR license plate detection and classificationpose4motion
- POSE human pose estimation
Installation is performed in five (5) steps:
- Install
motion-ai
software from this repository - Configure system messaging
- Configure cameras
- Install add-ons
- Start selected AI services (e.g.
yolo4motion
)
To get started flash a supported LINUX distribution image to a micro-SD card, enable ssh
and configure WiFi; insert into device, boot, update and upgrade (n.b. see here for additional information).
Access via ssh
or console; the following commands will complete the configuration and installation of motion-ai
# 1. enable appropriate permissions for the account
for g in $(groups pi | awk -F: '{ print $2 }'); do sudo addgroup ${USER} ${g}; done
# 2. install the minimum required software (n.b. `git` and `jq`)
sudo apt install -qq -y git jq
# 3. clone the repository into location with sufficient space
mkdir motion-ai
cd motion-ai
git clone [email protected]:dcmartin/motion-ai.git .
# 4. download and install Home Assistant, Docker, NetData, and supporting components
./sh/get.hassio.sh
# 5. add current user to docker group
sudo addgroup ${USER} docker
# 6. copy template for webcams.json
cp homeassistant/motion/webcams.json.tmpl webcams.json
# 7. build YAML files based on configuration options
make
# 8. reboot
sudo reboot
When the system has restarted, access via ssh
and continue with the next step.
Once Home Assistant has been downloaded and starts the Web UI may be reached on the specified port; default: 8123
.
Specify options for the motion
add-on, as well as the AI _services, as appropriate. Relevant variables include:
MOTION_GROUP
- identifier for a group of devices; default:motion
MOTION_DEVICE
- identifier for this device; default: hostname without-
and other special charactersMOTION_CLIENT
- identifier for device to listen; default:MOTION_DEVICE
; use+
for all devices in groupMQTT_HOST
- IPv4 address of MQTT broker; default:127.0.0.1
MQTT_PORT
- Port number; default:1883
MQTT_USERNAME
- credential identifier; default:username
MQTT_PASSWORD
- credential password; default:password
MOTIONCAM_USERNAME
- credential identifier; default:username
MOTIONCAM_PASSWORD
- credential password; default:password
NETCAM_USERNAME
- credential identifier; default:username
NETCAM_PASSWORD
- credential password; default:password
These variables' values may be specified by environment variables or persistently through files of the same name; for example in the motion-ai
installation directory:
# 1. specify a MQTT save device identifier
echo 'pi31' > MOTION_DEVICE
echo '+' > MOTION_CLIENT
# 2. specify credentials to access motion-ai cameras
echo 'username' > MOTIONCAM_PASSWORD
echo 'password' > MOTIONCAM_PASSWORD
# 3. specify credential to access third-party network cameras
echo 'username' > NETCAM_PASSWORD
echo 'password' > NETCAM_PASSWORD
# 4. specify MQTT options
echo '192.168.1.50' > MQTT_HOST
echo 'username' > MQTT_USERNAME
echo 'password' > MQTT_PASSWORD
Changes may be made for a variety of options; when changes are made (e.g. to the MQTT_HOST
) the following command must be run for those changes to take effect:
make restart
This JSON file contains information about the cameras which will be in the generated YAML; more cameras require more computational resources. Those details include:
name
: a unique name for the camera (e.g.kitchencam
)mjpeg_url
: location of "live" motion JPEG stream from camerausername
andpassword
: credentials for access via themjpeg_url
icon
: specified from the Material Design Icons selection.
# specify camera(s); default is one camera named `local`
cp homeassistant/motion/webcams.json.tmpl webcams.json
For example:
[
{ "name": "poolcam", "mjpeg_url": "http://192.168.1.251:8090/1", "icon": "water", "username": "!secret motioncam-username", "password": "!secret motioncam-password" },
{ "name": "road", "mjpeg_url": "http://192.168.1.251:8090/2", "icon": "road", "username": "!secret motioncam-username", "password": "!secret motioncam-password" },
{ "name": "dogshed", "mjpeg_url": "http://192.168.1.251:8090/3", "icon": "dog", "username": "!secret motioncam-username", "password": "!secret motioncam-password" },
{ "name": "dogshedfront", "mjpeg_url": "http://192.168.1.251:8090/4", "icon": "home-floor-1", "username": "!secret motioncam-username", "password": "!secret motioncam-password" },
{ "name": "sheshed", "mjpeg_url": "http://192.168.1.251:8090/5", "icon": "window-shutter-open", "username": "!secret motioncam-username", "password": "!secret motioncam-password" },
{ "name": "dogpond", "mjpeg_url": "http://192.168.1.251:8090/6", "icon": "waves", "username": "!secret motioncam-username", "password": "!secret motioncam-password" },
{ "name": "pondview", "mjpeg_url": "http://192.168.1.251:8090/7", "icon": "waves", "username": "!secret motioncam-username", "password": "!secret motioncam-password" }
]
Install the requiste add-ons for Home Assistant, including the MQTT
broker and the appropriate version of motion
. Browse to the Home Assistant Web interface (n.b. don't forget port
if not 80
) and visit the Supervisor via the icon in the lower left panel (see below).
Select the Add-on Store
and type in the address of this repository, for example:
When the system reloads, select the Motion Server add-on from those available; when utilizing a locally attached USB camera, select the Motion Video0 add-on; for example:
After selecting the appropriate add-on, install by clicking on the INSTALL
button, for example:
Configure the add-on using the following options:
group
- the identifier for the group of cameras; default:motion
device
- the identifier for the host of the camera; typically the hostnameclient
- the identifier for the client (single) or all+
; default:+
mqtt
-host
,port
,username
, andpassword
for MQTT servercameras
- an array ofdict
structure for each camera
For more information on configuring, please refer to the motion
documentation.
Specify options for the AI services, i.e. yolo4motion
, face4motion
, etc.. as appropriate. Relevant variables include:
In addition to those above, the level of logging and desired output location are shared across all services.
LOG_LEVEL
- logging level; default:info
LOG_TO
- logging output; default:/dev/stderr
YOLO_CONFIG
- may betiny
,tiny-v2
,tiny-v3
,v2
, orv3
; default:tiny
(pre-loaded)YOLO_ENTITY
- entity to detect; default:all
YOLO_SCALE
- size for image scaling prior to detect; default:none
YOLO_THRESHOLD
- threshold for entity detection; default:0.25
The tiny
model (aka tiny-v2
) only detects these entities; the remaining models detect these entities.
Note: The Docker container and the model's weights must be downloaded from the Internet; there may be a considerable delay given the device Internet connection bandwidth. The container is only downloaded one time, but the model's weights are downloaded each time the container is started.
For example:
echo debug > LOG_LEVEL
echo tiny-v3 > YOLO_CONFIG
./sh/yolo4motion.sh
... deleted ...
{
"name": "yolo4motion",
"id": "6d1765902d260f5b6e276f26391eb135eedef5388bf15ce77fa976adcf7a13c6",
"service": {
"label": "yolo4motion",
"id": "com.github.dcmartin.open-horizon.yolo4motion",
"tag": "0.1.2",
"arch": "amd64",
"ports": {
"service": 80,
"host": 4662
}
},
"motion": {
"group": "motion",
"client": "+",
"camera": "+"
},
"yolo": {
"config": "tiny",
"entity": "all",
"scale": "none",
"threshold": 0.25
},
"mqtt": {
"host": "192.168.1.50",
"port": 1883,
"username": "username",
"password": "password"
},
"debug": {
"debug": false,
"level": "info",
"logto": "/dev/stderr"
}
}
FACE_THRESHOLD
- floating point value between0.0
and0.99
; default:0.5
ALPR_COUNTRY
- designation for country specific license plates, may beus
oreu
; default:us
ALPR_PATTERN
- pattern for plate recognition, may be regular expression; default:none
ALPR_TOPN
- integer value between1
and20
limiting numbertag
predictions perplate
To monitor the MQTT
traffic from one or more motion
devices use the ./sh/watch.sh
script which runs a MQTT
client to listen for various topics, including motion detection events, annotations, detections, and a specified detected entity (n.b. currently limited per device). The script outputs information to /dev/stderr
and runs in the background. The shell script will utilize existing values for the MQTT
host, etc.. as well as the MOTION_CLIENT
, but those may be specified as well; for example:
echo motion > MOTION_GROUP
echo + > MOTION_CLIENT
./sh/watch.sh