[Tutorial] Homebridge for Nest

Guides and tutorials for various stuff. Posted by DietPi users.
Post Reply
Posts: 1
Joined: Tue Feb 27, 2018 1:35 am

[Tutorial] Homebridge for Nest

Post by benb » Tue Feb 27, 2018 1:47 am

Wanted to share the steps I used to get setup with Homebridge for Nest working as a service (starts automatically on boot).

Flash your pi with DietPi
After initial setup (network, etc.), use dietpi-software to install:
  • build-essentials
  • avahi-daemon
  • node.js
  • python
Install homebridge
http://github.crookster.org/Extending-H ... pberry-Pi/
^ I couldn't get the steps listed here to work verbatim, so I roughly used these steps:

Code: Select all

# apt-get install -y libavahi-compat-libdnssd-dev
# npm install -g --unsafe-perm homebridge hap-nodejs node-gyp
# npm which default
# cd /usr/local/lib/node_modules/
# npm install --unsafe-perm bignum
# node-gyp BUILDTYPE=Release rebuild
# which node-gyp BUILDTYPE=Release rebuild
https://github.com/nfarina/homebridge/b ... stallation
^ Then finish up with the rest of these steps to install homebridge.

Basically launch homebridge once:

Code: Select all

# homebridge
You should see a QR code and a Homekit code logged to console. You can use the Home app on your iOS device to "add" the homebridge device, now. Just make sure you set the same Homekit code in your config.json later (below).

Install nest module for homebridge
^ Follow the instructions here on how to setup your Nest Developer account, which allows the nest module to communicate with your thermostat through the Nest APIs.

Once you have your Nest Dev. account setup, edit the config.json, populating it with info from your Nest Dev. account:

Code: Select all

# nano ~/.homebridge/config.json
Here's a sample of my config.json prior to adding the "code" value (see below about the code). I set the "username" to match my Pi's MAC address (run ifconfig from the Pi console to get network adapter info, including the MAC address of your Ethernet/WiFi adapter). The port is dynamically generated the first time you launch homebridge, but it seems you can also just force a specific port like 35565. The pin value is also dynamically generated on first time launch. You can copy the pin from the console into your config.json.

Code: Select all

    "bridge": {
        "name": "Homebridge",
        "username": "B8:27:EF:34:3D:6F",
        "port": 35565,
        "pin": "032-64-154"

    "description": "Homebridge for Nest automation.",

    "accessories": [

    "platforms": [
        "platform": "Nest",

        "token" : "",

        "clientId": "yourNestDevId",
        "clientSecret": "yourNestDevSecret",
        "code": "yourNestPinCodeFromNestAuthUrl"
Note there's also a sample config.json here: https://github.com/nfarina/homebridge/b ... ample.json

Now run homebridge again, and if it works properly you should see your code value dumped to the console. Copy/paste that into the config.json as the "token" value, save, and then relaunch homebridge one more time. You should be in business! Check the Home app on your iOS device.

Setup homebridge to run on boot (after power cycle)
https://timleland.com/setup-homebridge- ... on-bootup/
^ I tried the older init.d method, but it didn't work at boot. The (newer?) systemctl method linked above worked.

These are my steps. Stop homebridge before proceeding, if its running.

Code: Select all

# nano /etc/default/homebridge
Paste in:

Code: Select all

# 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

Code: Select all

# nano /etc/systemd/system/homebridge.service
Paste in:

Code: Select all

Description=Node.js HomeKit Server 
After=syslog.target network-online.target

ExecStart=/usr/local/bin/homebridge $HOMEBRIDGE_OPTS

The finish up by adding the homebridge system user, setting up the system config for homebridge, and enabling/starting your new homebridge service:

Code: Select all

useradd --system homebridge
mkdir /var/lib/homebridge
cp ~/.homebridge/config.json /var/lib/homebridge/
cp -r ~/.homebridge/persist /var/lib/homebridge
chmod -R 0777 /var/lib/homebridge
systemctl daemon-reload
systemctl enable homebridge
systemctl start homebridge
Check service logs
If you need to check the logs for the homebridge service this command will output the entire log to console:

Code: Select all

journalctl -u homebridge --no-pager
I accidentally removed the homebridge's API access while using the Nest iOS app. To re-enable access, login to the Nest Developer site and use the same Authorization URL as we used previously to generate a new PIN. Update the /var/lib/homebridge/config.json file, removing the "token" and updating the new PIN in the "code" value.

Restart the homebridge service and check the logs using the above command. You'll find an entry in the logs providing you with a new token value - just copy that token and edit the config.json again, adding in the new token. The same format we used in the previous steps in this guide works.
Last edited by benb on Sun Mar 11, 2018 5:21 am, edited 7 times in total.

User avatar
Posts: 416
Joined: Sun Feb 28, 2016 4:28 pm

Re: Homebridge for Nest

Post by k-plan » Tue Feb 27, 2018 3:16 pm

Hi benb,

nice write up, thanks.
Will move this over to Community Tutorials, be surely a better place for it.

If you find our project or support useful, then we’d really appreciate it if you’d consider contributing to the project however you can.
Donating is the easiest – you can use PayPal and Bitcoin.

Posts: 1
Joined: Tue Sep 04, 2018 3:38 pm
Location: Mississauga, ON

Re: Homebridge for Nest

Post by victoriabam » Tue Sep 04, 2018 4:56 pm

Thanks for sharing these useful tips. This would be very helpful.

Posts: 14
Joined: Tue Jun 06, 2017 7:02 pm

Re: Homebridge for Nest

Post by helio58 » Mon Oct 22, 2018 7:43 pm

Thank you. Great

Post Reply