I finally started over from scratch with my Raspberry Pi Zero W and Camera Module V2. These are the steps I took to configure it with Homebridge as a Homekit-compatible camera.
Initial Pi Setup
- Using balenaEtcher, I installed the September 2019 version of Raspbian Buster Lite (link to latest release) on my SD card.
- I enabled
ssh
access by creating an empty file namedssh
at the root of the SD card. To allow the Pi onto my home network, I created a file named
wpa_supplicant.conf
at the root of the SD card. The contents should be:country=US ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev network={ ssid="YOUR_NETWORK_NAME" psk="YOUR_PASSWORD" key_mgmt=WPA-PSK }
Then I inserted the SD card in the Pi, booted it up, found it’s IP address on my network (I used LanScan), and connected via
ssh pi@<ipaddress>
.- It’s important to change the
pi
account password with thepasswd
command. - I selected my time zone and set the locale to
en_us.UTF-8
viasudo raspi-config
. Finally, I updated the software with:
sudo apt-get update sudo apt-get upgrade
Install Homebridge, homebridge-pi, and homebridge-camera-rpi
Homebridge requires an installation of node.js, which, surprisingly, can’t be installed via
apt
on the Pi Zero. This command will install the most recent LTS version of node.js by running a script from node-pi-zero:wget -O - https://raw.githubusercontent.com/sdesalas/node-pi-zero/master/install-node-v.lts.sh | bash
From Running Homebridge on a Raspberry Pi, Homebridge will require
git
to be installed:sudo apt-get install git
Those instructions also indicate that
avahi
must be installed:sudo apt-get install libavahi-compat-libdnssd-dev
Finally, we can actually install
homebridge
:sudo npm install -g homebridge
As well as
homebridge-pi
(which will provide thermal measurements from the Pi in Homekit):sudo npm install -g homebridge-pi
Before installing
homebridge-camera-rpi
(which will expose the camera to Homekit), we need to:- Activate the camera via
raspi-config
- Edit
sudo nano /etc/modules
and add the linebcm2835-v4l2
- Reboot
- Install ffmpeg:
sudo apt install ffmpeg
- Activate the camera via
Then, we can install
homebridge-camera-rpi
:sudo npm install -g homebridge-camera-rpi
And then setup the configuration file (
~/.homebridge/config.json
) to contain:{ "bridge": { "name": "PiZeroHomebridge", "username": "CC:22:3D:E3:CE:30", "port": 51826, "pin": "031-45-154" }, "description": "This is an example configuration file", "accessories": [ { "accessory": "PiTemperature", "name": "Pi Zero Temperature" } ], "platforms": [ { "platform": "rpi-camera", "cameras": [{"name": "Pi Camera"}] } ] }
Finally, I needed to add
homebridge
to my path viaexport PATH=/opt/nodejs/bin:$PATH
.- Now, you can run
homebridge
and add the devices to HomeKit configuration.
Configuring Homebridge to run on Bootup
There are great instructions for running Homebridge automatically at Bootup. These are the steps I used to configure it as a system service:
-
homebridge
to/etc/default
via this command:sudo wget -O /etc/default/homebridge https://gist.github.com/johannrichard/0ad0de1feb6adb9eb61a/raw/1cf926e63e553c7cbfacf9970042c5ac876fadfa/homebridge
homebridge.service
to/etc/systemd/system
via this command:sudo wget -O /etc/systemd/system/homebridge.service https://gist.github.com/johannrichard/0ad0de1feb6adb9eb61a/raw/1cf926e63e553c7cbfacf9970042c5ac876fadfa/homebridge.service
Fix path to the
homebridge
binary inhomebridge.service
with:sudo sed -i 's,/usr/local/bin/homebridge,'"$(which homebridge)"',' /etc/systemd/system/homebridge.service
Create a new user:
useradd --system homebridge
Per the camera setup instructions, add the new user to the
video
group:sudo adduser homebridge video
For convenience, I added the
pi
user to thehomebridge
group as well, so it can edit the configuration files:sudo adduser pi homebridge
Create a new directory for the configuration files:
sudo mkdir /var/lib/homebridge
Give the new user ownership of the configuration files:
sudo chown -R homebridge:homebridge /var/lib/homebridge/
Give the group write permissions for the configuration files:
sudo chmod -R 775 /var/lib/homebridge/
Log out and log back in (still as
pi
) to pick up the new permissions.Duplicate the configuration file in the new folder:
cp .homebridge/config.json /var/lib/homebridge/config.json
Make sure the ownership and permissions for
config.json
are set:sudo chown homebridge:homebridge /var/lib/homebridge/config.json
sudo chmod 664 /var/lib/homebridge/config.json
Have the system read the new configuration:
sudo systemctl daemon-reload
Enable it, start it up, and confirm it’s running:
sudo systemctl enable homebridge sudo systemctl start homebridge systemctl status homebridge
And with that, you can now just plug in the Raspberry Pi and it will boot and start up homebridge with your new camera! This is the cheapest way I’ve seen to get a HomeKit camera up and running.