Setting up a Raspberry-Pi, with Pi-Hole, Home-Assistant, Homebridge, Siri and Alexa. Part 3: Installing Homebridge and using Siri and Apple Home

This is part 3 of my multi-post of setting up a Pi with HomeAssistant, Homebridge, Siri and Pi-Hole.

If you want the previous parts here they are:
Part 1, Setting up a Pi in headless mode
Part 2, Installing Pi-Hole, Home-Assistant and setting up Limitless-LED (Milight) bulbs

So now onto the fun part, you want to control the lights you’ve setup previously with Siri, either by talking to your IOS device, or using the favourites option on your slide up menu, which you probably didn’t know existed!

Installing Homebridge

Lets crack on. SSH via terminal into your Pi (Putty if you’re a Windows user) and install homebridge:
Install git and make:
sudo apt-get install git make

Now to install Node, this is on a Pi3, if you’re on a lower pi refer to this site for installing homebridge.
curl -sL | sudo -E bash - sudo apt-get install -y nodejs
Prepare to press enter half way through this install.

Install Avahi:
sudo apt-get install libavahi-compat-libdnssd-dev

Install Homebridge:
sudo npm install -g --unsafe-perm homebridge

Time to make a config file for homebridge, this is called config.json:
sudo nano /home/pi/.homebridge/config.json
Paste this info to it:


Make sure you edit out the and replace with the API password from your HomeAssistant installation, the one you type to access the web gui, it’s in configuration.yaml file. Make a note of the pin too.

So now it’s installed we want to make Home-Assistant talk to Homebridge, so we need to install the homebridge plugin to HA:
sudo npm install -g homebridge-homeassistant
Restart HA:
sudo systemctl restart home-assistant.service

So you can now run homebridge by typing homebridge and watching what it does in console:

We don’t want to have to type a command to make it run though, we want it to run on boot with no outside influence, this involves a few steps, making a couple of folders, putting in several files and making a user and file permissions. I’m following the expert guidance of Johann Richard here.

Create the homebridge file in /set/default/
sudo nano /set/default/homebridge
Paste in these details:

# Defaults / Configuration options for homebridge
# The following settings tells homebridge where to find the config.json file and where to persist the data (i.e. pairing and others)
HOMEBRIDGE_OPTS=-U /var/lib/homebridge

# If you uncomment the following line, homebridge will log more
# You can display this via systemd’s journalctl: journalctl -f -u homebridge

ctrl-x and then y to save as usual with nano.

Next make homebridge.service file:
Sudo nano /etc/system/system/homebridge.service
Add this code:

Make sure to check and potentially change the /etc/default/homebridge in this file as this might be different in your install, check by typing and seeing where homebridge is installed:
which homebridge

Now make a user called homebridge
sudo useradd -M --system homebridge

You need to make a directory and place the config.json you wrote earlier into it, so basically the previous config.json is only used when you manually start homebridge with the ”homebridge” command, due to the way systemd works, this can’t be referenced. We need to place it somewhere it can be and make the directory readable by the correct users.

Create the directory:
sudo mkdir /var/lib/homebridge

Copy the config.json file you wrote previously into this folder:
sudo cp /home/pi/.homebridge/config.json /var/lib/homebridge/config.json

Now make this folder and files accessible:
sudo chmod –R 777 /var/lib/homebridge

Now time to start it with three commands:
systemctl daemon-reload
systemctl enable homebridge
systemctl start homebridge

You can check it’s status just like checking homeassistant’s status by using:
systemctl status homebridge

So that’s installed, now the fun begins!

Using Siri and Apple Home

So this whole process is really about automation and generally being a little lazy. Homebridge allows for the lazy, Home-Assistant allows for the automation! When I goto bed I just want to say, “Hey Siri, turn the lights off” and they go off. I’ve got two lights currently in my rented apartment, one is a RGBW LED strip behind the TV to give it some backlight, and the other is an E27 bulb in a floor standing lamp which provides ample light in the lounge. So lets get going.

Get out your ios device, in my case I’m using an iphone 6s plus so the screenshots are rather large. Find the app “home” either by searching or locating it. Open the app, it’ll probably look like this as you won’t have used it before:

Click add accessory.

Your Homebridge installation should be shown:

If Homebridge isn’t found by Apple Home:

A good first attempt is to delete two folders, /accessories and /persist that are located in /etc/default/homebridge by doing sudo rm -r /etc/default/homebridge. If this doesn’t fix it then you need to do some fault finding.

So click Homebridge, click add anyway as it’s not Apple approved. Type in the pin that you wrote down earlier, more than likely 031-45-154. I now put Homebridge in it’s own room, in my case called RaspberryPi:

Click next and it’ll present each of the items that Homebridge has shown to Apple Home, in my case the lamp, the backlight and the scenes that act as switches. I’ve put my lights and scenes into a room called the Lounge and included them all in my favourites:

Now if you click rooms at the bottom of the app and select Lounge, you’ll see all those devices listed:

If you go to your home screen and swipe up from the bottom, and across, you’ll find them there too:

Now you can click on the buttons to turn them off or simply say:
“Hey Siri, turn on the lounge lamp”
“Hey Siri, turn the lights on”
“Hey Siri, turn the lounge green on” for your scene.
“Hey Siri, turn the lights off”

Woohoo! Have a play about with the room background images and Home. Obviously you can add more lamps/lights to other places in the house, change the rooms etc. This guide isn’t suppose to be a definitive resource, but simply a helping hand as I struggled along with little knowledge, I hope I can share some.

In the next blog posts I’ll centre on adding items to Home-Assistant and then get into Alexa.

Leave a Reply

Your email address will not be published.