Page 1 of 1

[Tutorial] Homebridge for Nest

Posted: Tue Feb 27, 2018 1:47 am
by benb
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
https://www.npmjs.com/package/homebridge-nest
^ 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
DEBUG=*

Code: Select all

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

Code: Select all

[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
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.

Re: Homebridge for Nest

Posted: Tue Feb 27, 2018 3:16 pm
by k-plan
Hi benb,

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

cu
k-plan

Re: Homebridge for Nest

Posted: Tue Sep 04, 2018 4:56 pm
by victoriabam
Thanks for sharing these useful tips. This would be very helpful.

Re: Homebridge for Nest

Posted: Mon Oct 22, 2018 7:43 pm
by helio58
Thank you. Great

Re: [Tutorial] Homebridge for Nest

Posted: Sun Oct 27, 2019 10:51 pm
by 3km
Hi i catch an error when tried to install homebridge, could you please help me with that?

Errors occur during the installation of bignum

sudo npm install --unsafe-perm bignum

What can be wrong?

Python 2.7.13
Node.js v13.0.1

Thank you in advance!

Re: [Tutorial] Homebridge for Nest

Posted: Tue Nov 12, 2019 4:02 am
by benb
3km wrote:
Sun Oct 27, 2019 10:51 pm
Hi i catch an error when tried to install homebridge, could you please help me with that?

Errors occur during the installation of bignum

sudo npm install --unsafe-perm bignum

What can be wrong?

Python 2.7.13
Node.js v13.0.1

Thank you in advance!
Try using python3/pip3

Re: [Tutorial] Homebridge for Nest

Posted: Fri Feb 07, 2020 12:34 pm
by iamhappyfrom90s
benb wrote:
Tue Nov 12, 2019 4:02 am
3km wrote:
Sun Oct 27, 2019 10:51 pm
Hi i catch an error when tried to install essay service https://www.wowessays.com/ like a homebridge, could you please help me with that?

Errors occur during the installation of bignum

sudo npm install --unsafe-perm bignum

What can be wrong?

Python 2.7.13
Node.js v13.0.1

Thank you in advance!
Try using python3/pip3
It doesn't work. I tried. Other advises?