Setup Homebridge to Start on Bootup

I’ve recently been playing with Homebridge on my Raspberry Pi. I’ve setup my Harmony Hub and my wireless power outlets to be controlled by Siri on my iPhone. Overall it has been pretty simple to setup but I did run into an issue trying to get Homebridge to start on bootup. Homebridge suggest 3 different methods

I decided to use systemd to start Homebridge on bootup. I prefered this method because it will restart if an error occurs. I followed the gist setup step by step but ran into some problems.

My main issues were:

  • The location of my homebridge binary. Step 2
  • Permissions were not correct and the service failed to load. Step 7
  • I needed the persist folder in /var/homebridge directory. Step 6

Here are the steps that worked for me:

  1. sudo nano /etc/default/homebridge and paste this gist
  2. sudo nano /etc/systemd/system/homebridge.service and paste this gist
    1. I had to remove local from:  ExecStart=/usr/local/bin/homebridge $HOMEBRIDGE_OPTS  because my homebridge installed in /usr/bin/
  3. Create a user to run service: sudo useradd --system homebridge
  4. sudo mkdir /var/homebridge
  5. sudo cp ~/.homebridge/config.json /var/homebridge/
    1. This copies your current user’s config. This assumes you have already added accessories etc.
  6. sudo cp -r ~/.homebridge/persist /var/homebridge
  7. sudo chmod -R 0777 /var/homebridge
  8. sudo systemctl daemon-reload
  9. sudo systemctl enable homebridge
  10. sudo systemctl start homebridge

Type systemctl status homebridge to check the status of the service.

Hopefully this helps anyone who is having trouble with Homebridge starting on boot on a Raspberry Pi. Please comment below if you have any questions.


Also published on Medium.

184 thoughts to “Setup Homebridge to Start on Bootup”

  1. My Homebridge works well on my Raspberry Pi 3, but I cannot get autostart to work using the guidelines.
    I have checked the location of homebridge and included it in the Gist with ‘local’

    [email protected]:~ $ which homebridge
    /usr/local/bin/homebridge

    I get an error when I use systemctl status homebridge

    [email protected]:~ $ systemctl status homebridge
    ● homebridge.service – Node.js HomeKit Server
    Loaded: loaded (/etc/systemd/system/homebridge.service; enabled)
    Active: activating (auto-restart) (Result: exit-code) since Thu 2017-09-21 15:44:26 UTC; 8s ago
    Process: 17090 ExecStart=/usr/local/bin/homebridge $HOMEBRIDGE_OPTS (code=exited, status=1/FAILURE)
    Main PID: 17090 (code=exited, status=1/FAILURE)

    1. I had the exact same problem, I figured out the user was the issue.
      When changing to my default PI user, the issue was gone and service is running.

      If anyone can suggest another approach of doing it correctly with the ‘homebridge’ user (which requires a password and that was the problem if i’m not wrong), please share.

      Thanks

    2. I had this issue as well – I’m using the Braoadlink RM plug in and I had to add the following line to the BroadlinkRM platform in /var/homebridge/config.json

      “homebridgeDirectory”:”/var/homebridge”,

      Hope this helps

  2. Hello,
    Just to say Thank you very much, I have some difficult to start my home bridge at startup and with your steps it’s works fine !!
    Thanks again!
    Morgane

  3. Hi TIM, I’ve done every step and I see the system is running
    homebridge.service – Node.js HomeKit Server
    Loaded: loaded (/etc/systemd/system/homebridge.service; enabled; vendor preset: enabled)
    Active: active (running) since Tue 2017-09-26 11:32:38 UTC; 14s ago
    Main PID: 692 (homebridge)
    CGroup: /system.slice/homebridge.service
    ├─692 homebridge
    ├─698 /bin/sh -c /bin/echo -n “$(npm -g prefix)/lib/node_modules”
    └─699 npm

    BUT when I go on my phone homekit doesn’t work, and in order to switch on my lights I have to start “homebridge” manually.
    What it can be?

          1. I don’t understand why create another user (called homebridge, too, to confuse ideas to noobs!).. should I do something with that user? If I try to switch from pi user to homebridge user, it asks me a password, which password?

            Thanks 🙂

    1. I had the same issue. I had to remove the bridge from my Home app and then re-pair it with the auto-started instance (even using the same HomeKit code) before it would work with the autostarted one.

  4. Hi, I’m new to all this and started out reading how to setup my homebridge on https://github.com/nfarina/homebridge/wiki/Running-HomeBridge-on-a-Raspberry-Pi#install-avahi-and-other-dependencies. The post refers to the post above in case you encounter some difficulties (aka troubleshooting). In the first post the homebridge config is stored in /var/homebridge, while in the post above the dir /var/lib/homebridge is used. Be sure the locations in you config are matching the directories you’ll be creating, so pick one or the other. After correcting the post above did the job for me, thanks!

  5. Hi Everybody,
    I’m new about “Raspberry PI” and homebridge application, I tried to apply Your tips, but unfortunately doesn’t work .
    It seem it start but after few seconds the status is FAILURE.
    My understanding is that if I start homebridge using “sudo systemctl start homebridge” do not load plug-in (I use Fibaro-HC2), but if I start homebridge by command line it works fine.
    Some ideas?
    Thanks in advance.

  6. Hi Tim.

    I have constantly crashes with home ridge.
    Can you help me out or give me any advice.

    I created the trouble by installing a third party app from iOS AppStore.
    This app installed homebridge to start up with Init.d I believe…

    But I installed homebridge with systemd.
    Now both are making my install unstable. How do I get rid of the Init.d boot Up?

    I believe that I should keep systemd??

    Hope you can help me!

    Greets marco

      1. Eadrinuse with a number or something.
        And a whole lot of text.
        Also I see in the cpu usage in the top bar (nearby the network logo) a constant returning peak! Every 10 sec. then I see in the task manager homebridge usage going to 25%. And I see to time homebridge process. By 2 usernames. Pi an homebridge.
        So that’s why I concluded it is trying to double start.

  7. [email protected]:~ $ sudo useradd –system homebridge
    useradd: user ‘homebridge’ already exists
    [email protected]:~ $ sudo mkdir /var/homebridge
    mkdir: cannot create directory ‘/var/homebridge’: File exists
    [email protected]:~ $
    [email protected]:~ $ sudo cp ~/.homebridge/config.json /var/homebridge/
    [email protected]:~ $ sudo cp -r ~/.homebridge/persist /var/homebridge
    [email protected]:~ $ sudo chmod -R 0777 /var/homebridge
    [email protected]:~ $ sudo systemctl daemon-reload
    [email protected]:~ $ sudo systemctl enable homebridge
    Synchronizing state for homebridge.service with sysvinit using update-rc.d…
    Executing /usr/sbin/update-rc.d homebridge defaults
    Executing /usr/sbin/update-rc.d homebridge enable
    [email protected]:~ $ sudo systemctl start homebridge
    [email protected]:~ $ systemctl status homebridge
    ● homebridge.service – Node.js HomeKit Server
    Loaded: loaded (/etc/systemd/system/homebridge.service; enabled)
    Active: active (running) since Sat 2017-11-11 16:01:50 CET; 3min 54s ago
    Main PID: 2233 (homebridge)
    CGroup: /system.slice/homebridge.service
    └─2233 homebridge
    [email protected]:~ $

    Yet no success, while all is running. Can’t get the Homebridge going.
    In the homebridge.service also this change: ExecStart=/usr/bin/homebridge $HOMEBRIDGE_OPTS

    So I am confused, why is it that my Homebridge is not running smoothly….

  8. This helped me a lot 🙂

    I had to remove local from: ExecStart=/usr/local/bin/homebridge $HOMEBRIDGE_OPTS because my homebridge installed in /usr/bin/

Leave a Reply

Your email address will not be published. Required fields are marked *