HomeBridge installation and configuration

Installation of HomeBridge

First of all, nodeJS has to bee installed. Please look for the last stable version. my used version (10.41) is outdated! Take a look here: https://nodejs.org/dist/latest/ and insert the path in the wget line:

sudo apt-get install git
wget https://nodejs.org/dist/latest/node-v10.4.1-linux-armv7l.tar.gz
tar xf node-v10.4.1-linux-armv7l.tar.gz
sudo cp -R node-v10.4.1-linux-armv7l/* /usr/local/
sudo npm install -g n

Homebridge as a service:

sudo useradd -m -c "Homebridge Service" -s /bin/bash homebridge

With vi or nano create the file /etc/sudoers.d/homebridge

homebridge ALL=(root) SETENV:NOPASSWD: /usr/local/bin/npm, /bin/systemctl restart homebridge, /bin/journalctl, /usr/local/bin/node

Set the permissions:

sudo chmod 640 /etc/sudoers.d/homebridge

This is important to give the right permissions to the home bridge process. More permissions are not needed. (Security reason!)

If more permissions are needed, add the following line:

homebridge ALL=(ALL) SETENV:NOPASSWD: ALL

With this line you install a software that makes sure, that HomeBridge will be restarted after a crash.

sudo apt-get install libavahi-compat-libdnssd-dev

Now it is time to install HomeBridge:

sudo npm install -g --unsafe-perm homebridge
sudo mkdir -p /var/homebridge

Create the config.json file:  “sudo vi /var/homebridge/config.json”

{
	"bridge": {
		"name": "Homebridge",
		"username": "CC:22:3D:E3:CE:30",
		"port": 51826,
		"pin": "031-45-154"
	},
	"description": "Home Smart Home",
	"platforms": [],
	"accessories": []
}

Correct the permissions:

sudo chown -R homebridge:homebridge /var/homebridge

That is it! Now you should install HomeBridge as a service:

sudo nano /etc/systemd/system/homebridge.service

Insert the following:

[Unit]
Description=Node.js HomeKit Server
After=syslog.target network-online.target
[Service]
Type=simple
User=homebridge
EnvironmentFile=/etc/default/homebridge
ExecStart=/usr/local/bin/homebridge $HOMEBRIDGE_OPTS
Restart=on-failure
RestartSec=10
KillMode=process
[Install]
WantedBy=multi-user.target

And create these file:

sudo nano /etc/default/homebridge

Insert this:

# 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=-I -U /var/homebridge
# If you uncomment the following line, homebridge will log more
# You can display this via systemd's journalctl: journalctl -f -u homebridge
# DEBUG=*

That’s it! – Nearly!!!

sudo systemctl daemon-reload

and the last line:

sudo systemctl enable homebridge

You can find the whole Installation guide here: Running Homebridge on a Raspberry Pi · nfarina/homebridge Wiki …https://github.com/…/homebridge/…/Running-HomeBridge-on-a-…

Troubleshooting

If you have the problem that home bridge is executed but you can not integrate it in the Home-App, try the following:

  1. stopp the HomeBridge service. (kill -p P-ID)
  2. Delete the folders: /.homebridge/persist ~/.homebridge/accessories.
  3. In the ~/.homebridge/config.json, modify one letter of the “username”. Note:  The Name us hexadezimal!
  4. Restart the HomeBridge service and start the pairing with the Home-App.