How to use your Raspberry Pi Camera in Apple Homekit with Homebridge

 

Hardware needed

- Raspberry Pi Model A or B, gen 2, 3 or 4
- SD Card with capacity of 4GB or higher
- Raspberry Pi compatible camera with flatband cable
    - Raspberry Pi Camera Module v2
    or
    - Raspberry Pi HQ Camera
- Raspberry Pi Enclosure
- Poolside Factory Camera Mount
    - Tilt-Adjustable Mount for Camera Module v1/v2/PiNoir
    or
    - Universal Tilt-Adjustable Mount for v1/v2/PiNoir or HQ camera

Instructions

If you already have an SD card with a working Raspberry Pi image, you can use that one, otherwise you can follow these steps to create a fresh one without needing a screen or keyboard for your Raspberry Pi.

Log in to your Raspberry Pi and activate the camera driver by running:

sudo raspi-config


Select '3 Interface Options'


Select 'P1 Camera'


... and set to <Yes>.  After that, raspi-config will ask you to reboot the Raspberry Pi. 

Once you logged back in after the reboot, run the following commands:

curl -sL https://deb.nodesource.com/setup_15.x | sudo -E bash - 

sudo apt-get update && sudo apt-get install -y nodejs libavahi-compat-libdnssd-dev
sudo npm install -g --unsafe-perm homebridge homebridge-config-ui-x sudo npm install -g homebridge-camera-ffmpeg

sudo hb-service install --user homebridge
sudo chmod a+rw /dev/vchiq
sudo usermod -aG video $USER
sudo usermod -aG video pi
sudo usermod -aG video homebridge
sudo usermod -aG video root sudo systemctl restart homebridge

Look up the current ip address of your Raspberry Pi with

sudo ifconfig wlan0 

Using this ip address, open the webpage served by homebridge from the Raspberry Pi with your computer's web browser by going to http://the-ip-address-you-just-located:8581 and log in using these default values:

Login:  admin
Password: admin

Click on Config in the top right and update the configuration to look like this one while keeping your "bridge" section, but replace the other sections with the ones from this configuration file:


{
    "bridge": {
        "name": "Homebridge South Lawn",
        "username": "B8:27:EC:DB:86:0A",
        "port": 51889,
        "pin": "377-43-606"
    },
    "description": "This is an example configuration file",
    "platforms": [
        {
            "name": "Config",
            "port": 8581,
            "platform": "config"
        },
        {
            "platform": "Camera-ffmpeg",
            "cameras": [
                {
                    "name": "PiCam South Lawn",
                    "uploader": true,
                    "videoConfig": {
                        "source": "-re -f video4linux2 -i /dev/video0",
                        "stillImageSource": "-re -f video4linux2 -ss 0.9 -i /dev/video0 -vframes 1",
                        "maxFPS": 15,
                        "maxBitrate": 1000
                    }
                }
            ]
        }
    ],
    "accessories": []
}

 

When your Apple device requests the video stream from your homebridge camera, the resolution that is requested depends on the device that is requesting the stream:

iPad requests are 1920 x 1080, 802kbps
iPhone requests are 1280 x 720, 15fps, 299kbps

So no matter what settings you configure in the configuration above, you can't go beyond these limits.  It does make a lot of sense though to reduce the frame rate for some camera placements, which will result in the video feed being much sharper, as it doesn't need to be compressed as much. 

Then click 'Save' and hit the restart button that looks like the TV off button in the top right. Once Homebridge restarted, you should see a screen like this one:

 

Now grab your phone, go to the Home app, click the + and then 'Add Accessory' and scan the 2D barcode displayed in the browser.  

Your phone will first add the bridge and let you choose a room and name for it. Once the bridge is added, iOS will automatically ask you for room and name again, this time for the camera. What you enter for the bridge matters less as it won't be displayed in the regular home app, only the camera will show up. 

Done, the Raspberry Pi camera should now be visible in your Home app. 

Attach your Raspberry Pi camera module or HQ camera directly to the Raspberry Pi case using one the Poolside Factory mounts:

       

 

Leave a comment

Please note, comments must be approved before they are published