[OBSOLETE] Hello, Home HomeKit (and Siri!) control via homebridge

Ok, after struggling all day with this, these are my adapted instructions that are completely up to date for running Homebridge on a Raspberry Pi 2 Model B. If you run on other systems, you may have to adapt the installation of nodejs.

Instructions:
noobs clean install Raspbian

Connect using Terminal (on Mac):
SSH pi@xx.x.x.xx
copy key (in MAC terminal)
nano /Users/xxxx/.ssh/
paste key
SSH pi@xx.x.x.xx

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install git-core make

Install Node.js

wget https://nodejs.org/dist/v6.2.1/node-v6.2.1-linux-armv7l.tar.gz
tar -xvf node-v6.2.1-linux-armv7l.tar.gz
cd node-v6.2.1-linux-armv7l
sudo cp -R * /usr/local/
cd /usr/local/
node –v

Install Other Dependent Packages & Finally, Homebridge

sudo npm install npm -g
sudo apt-get install libavahi-compat-libdnssd-dev
sudo apt-get install libkrb5-dev
sudo npm install --unsafe-perm -g homebridge
sudo npm install -g homebridge-smartthings

Install json SmartApp:


Goto the ‘My SmartApps’ tab
Click ‘+ New SmartApp’ button top right
Click ‘From Code’
paste json-complete-api.groovy
Click ‘Create’
Click ‘App Settings’
Click ‘OAuth’
Click ‘Enable OAuth in Smart App’ leave all settings as defaults
Click ‘Update’
Finally, under the json-complete-api.groovy app, click “Publish”

On iPhone:
Open Smartthings app.
Go to Marketplace - Smartapps - My apps - JSON Complete API
Select all my devices
Go to the Config screen
Send the text to my laptop

Now SSH back into the Pi:
nano /home/pi/.homebridge/config.json
(Paste the lower part from text sent from iPhone)

{
"bridge": {
"name": "Homebridge",
"username": "D0:00:00:00:00:00",
"port": 51826,
"pin": "031-45-154"
},

"description": "JSON API",
"platforms": [{
"platform": "SmartThings",
"name": "SmartThings",
"app_url": "https://graph.api.smartthings.com:443/api/smartapps/installations/",
"app_id": “INSERT APP_ID HERE“,
"access_token": “INSERT ACCESS_TOKEN HERE“
}]
}

Exit & Save

Homebridge

Back on the Phone:
Open EVE (or any HomeKit app or Home on iOS 10) on iPhone and enter PIN number from Homebridge program.
Note: If you want Homebridge to auto-start, you should follow the auto startup instructions BEFORE configuring it on the phone, as it seems to create a new instance of Homebridge.

**Auto Startup (**More advanced)
On newer Raspberry Pi and Debian systems, managing of services with init.d is (transparently) replaced with systemd. If you wish to use systemd for running Homebridge on boot, you can follow these instructions.
As you can see, the service definition is much shorter than a comparable init.d script.

(1) Place homebridge under /etc/default
sudo nano /etc/default/homebridge
copy and past homebridge code and save.

homebridge:

# 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/homebridge

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

(2)Place homebridge.service under /etc/systemd/system on your Raspberry Pi.
sudo nano /etc/systemd/system
copy and past homebridge.service code and save.

homebridge.service:

[Unit]
Description=Node.js HomeKit Server 
After=syslog.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

(3) Create a system user named homebridge. You can easily create this user with
useradd --system homebridge

(4) Create a directory called /var/homebridge, writable by the user created above, and a corresponding config.json file in that directory.

sudo chmod 777 /var/homebridge
sudo nano /var/homebridge/config.json

copy and paste config.json file here

Homebridge by default looks for its configuration in/home/<username>/.homebridge. This is unsuitable for services and the -U /var/homebridge flag ensures the config is read from a different place.

(5) Enable and run the service (first time) with the following commands:

systemctl daemon-reload
systemctl enable homebridge
systemctl start homebridge

You can check the status of the service by calling
systemctl status homebridge
On subsequent reboots, it should start automatically, if not, use the journalctl -u homebridge to check the error cause.
Notes

  • The service will restart after 10 seconds if it fails for any reason (or if you kill it for example with kill -s SIGSEGV )

Resources:


7 Likes