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
sshaccess by creating an empty file namedsshat the root of the SD card. To allow the Pi onto my home network, I created a file named
wpa_supplicant.confat 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
piaccount password with thepasswdcommand. - I selected my time zone and set the locale to
en_us.UTF-8viasudo 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
apton 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 | bashFrom Running Homebridge on a Raspberry Pi, Homebridge will require
gitto be installed:sudo apt-get install gitThose instructions also indicate that
avahimust be installed:sudo apt-get install libavahi-compat-libdnssd-devFinally, we can actually install
homebridge:sudo npm install -g homebridgeAs well as
homebridge-pi(which will provide thermal measurements from the Pi in Homekit):sudo npm install -g homebridge-piBefore installing
homebridge-camera-rpi(which will expose the camera to Homekit), we need to:- Activate the camera via
raspi-config - Edit
sudo nano /etc/modulesand 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-rpiAnd 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
homebridgeto my path viaexport PATH=/opt/nodejs/bin:$PATH.- Now, you can run
homebridgeand 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:
-
homebridgeto/etc/defaultvia this command:sudo wget -O /etc/default/homebridge https://gist.github.com/johannrichard/0ad0de1feb6adb9eb61a/raw/1cf926e63e553c7cbfacf9970042c5ac876fadfa/homebridgehomebridge.serviceto/etc/systemd/systemvia this command:sudo wget -O /etc/systemd/system/homebridge.service https://gist.github.com/johannrichard/0ad0de1feb6adb9eb61a/raw/1cf926e63e553c7cbfacf9970042c5ac876fadfa/homebridge.service
Fix path to the
homebridgebinary inhomebridge.servicewith:sudo sed -i 's,/usr/local/bin/homebridge,'"$(which homebridge)"',' /etc/systemd/system/homebridge.serviceCreate a new user:
useradd --system homebridgePer the camera setup instructions, add the new user to the
videogroup:sudo adduser homebridge videoFor convenience, I added the
piuser to thehomebridgegroup as well, so it can edit the configuration files:sudo adduser pi homebridgeCreate a new directory for the configuration files:
sudo mkdir /var/lib/homebridgeGive 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.jsonMake sure the ownership and permissions for
config.jsonare set:sudo chown homebridge:homebridge /var/lib/homebridge/config.jsonsudo chmod 664 /var/lib/homebridge/config.json
Have the system read the new configuration:
sudo systemctl daemon-reloadEnable 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.