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.

95 thoughts on “Setup Homebridge to Start on Bootup

    1. Tim, I need your help again. Home bridge was not found a couple hours after your help the other day; I started fresh to see if I missed something yesterday. and it took a couple hours to stop again. I also disabled power management for wifi to keep it from going to sleep. it says that it is active, yet homebridge will not show up once removed. Please look below.
      [email protected]:~ $ systemctl status homebridge
      ● homebridge.service – Node.js HomeKit Server
      Loaded: loaded (/etc/systemd/system/homebridge.service; enabled)
      Active: active (running) since Wed 2017-01-11 00:24:29 UTC; 4min 34s ago
      Main PID: 562 (homebridge)
      CGroup: /system.slice/homebridge.service
      └─562 homebridge
      [email protected]:~ $ sudo systemctl status homebridge
      ● homebridge.service – Node.js HomeKit Server
      Loaded: loaded (/etc/systemd/system/homebridge.service; enabled)
      Active: active (running) since Wed 2017-01-11 00:24:29 UTC; 4min 44s ago
      Main PID: 562 (homebridge)
      CGroup: /system.slice/homebridge.service
      └─562 homebridge

      Jan 11 00:27:30 raspberrypi homebridge[562]: [1/11/2017, 12:27:30 AM] [Fan] …]
      Jan 11 00:28:16 raspberrypi homebridge[562]: [1/11/2017, 12:28:16 AM] Update…d
      Jan 11 00:28:16 raspberrypi homebridge[562]: [1/11/2017, 12:28:16 AM] Away f…e
      Jan 11 00:28:16 raspberrypi homebridge[562]: [1/11/2017, 12:28:16 AM] Temper…t
      Jan 11 00:28:16 raspberrypi homebridge[562]: [1/11/2017, 12:28:16 AM] Curren…9
      Jan 11 00:28:16 raspberrypi homebridge[562]: [1/11/2017, 12:28:16 AM] Curren…0
      Jan 11 00:28:16 raspberrypi homebridge[562]: [1/11/2017, 12:28:16 AM] Curren…2
      Jan 11 00:28:16 raspberrypi homebridge[562]: [1/11/2017, 12:28:16 AM] Target…2
      Jan 11 00:28:16 raspberrypi homebridge[562]: [1/11/2017, 12:28:16 AM] Target…4
      Jan 11 00:28:33 raspberrypi systemd[1]: Started Node.js HomeKit Server.
      Hint: Some lines were ellipsized, use -l to show in full.
      [email protected]:~ $

      REPLY

  1. Hi Tim,
    I followed your guide and now my homebridge works like a charm!
    Just a question: what’s the config.json that have to be modified now? The one in ~/.homebridge or the other in /var/homebridge ?

      1. Everything works perfect using this guide! however not sure how to change / update config.json I changed a few items but they are not reflected in the Homekit. Do i need to stop process and reload? Reboot does not help.

  2. once I try to log in to homebridge it just goes in a loop, back to login. I can log in to PI fine, yet not homebridge. it goes blank and ask for my login again. I have ran in to this twice now, the first time I sent it in to recovery and loaded a new Jessie on my rpi3. Is there a way to do steps 4-10 logged in as Pi? Thank you for your help.

  3. Tim, you are the smartest guy around. This was a simple process thanks to you. I wasted an half a day on that other site, and a an hour on google trying to find the fix. Thank you Sir.

  4. Jan 09 03:55:50 RazHome homebridge[2588]: at Module._compile (module.js:571:32)
    Jan 09 03:55:50 RazHome homebridge[2588]: at Object.Module._extensions..js (…)
    Jan 09 03:55:50 RazHome homebridge[2588]: at Module.load (module.js:488:32)
    Jan 09 03:55:50 RazHome homebridge[2588]: at tryModuleLoad (module.js:447:12)
    Jan 09 03:55:50 RazHome homebridge[2588]: at Function.Module._load (module.j…)
    Jan 09 03:55:50 RazHome homebridge[2588]: at Module.runMain (module.js:605:10)
    Jan 09 03:55:50 RazHome systemd[1]: homebridge.service: main process exited…RE
    Jan 09 03:55:50 RazHome systemd[1]: Unit homebridge.service entered failed …e.
    Hint: Some lines were ellipsized, use -l to show in full.

    any ideas what im doing wrong?

  5. Hi, i have tested this and I end up with a error when i try to enable homebridge..

    [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
    perl: warning: Setting locale failed.
    perl: warning: Please check that your locale settings:
    LANGUAGE = (unset),
    LC_ALL = (unset),
    LC_CTYPE = “UTF-8”,
    LANG = “en_US.UTF-8”
    are supported and installed on your system.
    perl: warning: Falling back to a fallback locale (“en_US.UTF-8”).
    Executing /usr/sbin/update-rc.d homebridge enable
    perl: warning: Setting locale failed.
    perl: warning: Please check that your locale settings:
    LANGUAGE = (unset),
    LC_ALL = (unset),
    LC_CTYPE = “UTF-8”,
    LANG = “en_US.UTF-8”
    are supported and installed on your system.
    perl: warning: Falling back to a fallback locale (“en_US.UTF-8”).
    [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 Mon 2017-01-09 20:38:48 UTC; 13min ago
    Main PID: 524 (homebridge)
    CGroup: /system.slice/homebridge.service
    └─524 homebridge
    [email protected]:~ $

    Any clue?

  6. Tim, I need your help again. Home bridge was not found a couple hours after your help the other day; I started fresh to see if I missed something yesterday. and it took a couple hours to stop again. I also disabled power management for wifi to keep it from going to sleep. it says that it is active, yet homebridge will not show up once removed. Please look below.
    [email protected]:~ $ systemctl status homebridge
    ● homebridge.service – Node.js HomeKit Server
    Loaded: loaded (/etc/systemd/system/homebridge.service; enabled)
    Active: active (running) since Wed 2017-01-11 00:24:29 UTC; 4min 34s ago
    Main PID: 562 (homebridge)
    CGroup: /system.slice/homebridge.service
    └─562 homebridge
    [email protected]:~ $ sudo systemctl status homebridge
    ● homebridge.service – Node.js HomeKit Server
    Loaded: loaded (/etc/systemd/system/homebridge.service; enabled)
    Active: active (running) since Wed 2017-01-11 00:24:29 UTC; 4min 44s ago
    Main PID: 562 (homebridge)
    CGroup: /system.slice/homebridge.service
    └─562 homebridge

    Jan 11 00:27:30 raspberrypi homebridge[562]: [1/11/2017, 12:27:30 AM] [Fan] …]
    Jan 11 00:28:16 raspberrypi homebridge[562]: [1/11/2017, 12:28:16 AM] Update…d
    Jan 11 00:28:16 raspberrypi homebridge[562]: [1/11/2017, 12:28:16 AM] Away f…e
    Jan 11 00:28:16 raspberrypi homebridge[562]: [1/11/2017, 12:28:16 AM] Temper…t
    Jan 11 00:28:16 raspberrypi homebridge[562]: [1/11/2017, 12:28:16 AM] Curren…9
    Jan 11 00:28:16 raspberrypi homebridge[562]: [1/11/2017, 12:28:16 AM] Curren…0
    Jan 11 00:28:16 raspberrypi homebridge[562]: [1/11/2017, 12:28:16 AM] Curren…2
    Jan 11 00:28:16 raspberrypi homebridge[562]: [1/11/2017, 12:28:16 AM] Target…2
    Jan 11 00:28:16 raspberrypi homebridge[562]: [1/11/2017, 12:28:16 AM] Target…4
    Jan 11 00:28:33 raspberrypi systemd[1]: Started Node.js HomeKit Server.
    Hint: Some lines were ellipsized, use -l to show in full.
    [email protected]:~ $

  7. Hello Tim
    Thanks for the article.
    It works for me but I am not able to stop home bridge.
    Which commands do I need to simply stop home bridge if I temporary need to start it manually?
    thanks
    Fab

  8. Tim, I need your help again. Home bridge was not found a couple hours after your help the other day; I started fresh to see if I missed something yesterday. and it took a couple hours to stop again. I also disabled power management for wifi to keep it from going to sleep. it says that it is active, yet homebridge will not show up once removed. Please look below.
    [email protected]:~ $ systemctl status homebridge
    ● homebridge.service – Node.js HomeKit Server
    Loaded: loaded (/etc/systemd/system/homebridge.service; enabled)
    Active: active (running) since Wed 2017-01-11 00:24:29 UTC; 4min 34s ago
    Main PID: 562 (homebridge)
    CGroup: /system.slice/homebridge.service
    └─562 homebridge
    [email protected]:~ $ sudo systemctl status homebridge
    ● homebridge.service – Node.js HomeKit Server
    Loaded: loaded (/etc/systemd/system/homebridge.service; enabled)
    Active: active (running) since Wed 2017-01-11 00:24:29 UTC; 4min 44s ago
    Main PID: 562 (homebridge)
    CGroup: /system.slice/homebridge.service
    └─562 homebridge

    Jan 11 00:27:30 raspberrypi homebridge[562]: [1/11/2017, 12:27:30 AM] [Fan] …]
    Jan 11 00:28:16 raspberrypi homebridge[562]: [1/11/2017, 12:28:16 AM] Update…d
    Jan 11 00:28:16 raspberrypi homebridge[562]: [1/11/2017, 12:28:16 AM] Away f…e
    Jan 11 00:28:16 raspberrypi homebridge[562]: [1/11/2017, 12:28:16 AM] Temper…t
    Jan 11 00:28:16 raspberrypi homebridge[562]: [1/11/2017, 12:28:16 AM] Curren…9
    Jan 11 00:28:16 raspberrypi homebridge[562]: [1/11/2017, 12:28:16 AM] Curren…0
    Jan 11 00:28:16 raspberrypi homebridge[562]: [1/11/2017, 12:28:16 AM] Curren…2
    Jan 11 00:28:16 raspberrypi homebridge[562]: [1/11/2017, 12:28:16 AM] Target…2
    Jan 11 00:28:16 raspberrypi homebridge[562]: [1/11/2017, 12:28:16 AM] Target…4
    Jan 11 00:28:33 raspberrypi systemd[1]: Started Node.js HomeKit Server.
    Hint: Some lines were ellipsized, use -l to show in full.
    [email protected]:~ $

    Any thoughts

  9. Hi Tim,
    Ive done everything you mentioned except when i hit sudo systemctl enable home bridge i get the following error:
    [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
    insserv: Script homebridge is broken: incomplete LSB comment.
    insserv: missing valid name for `Provides:’ please add.
    insserv: Script homebridge is broken: incomplete LSB comment.
    insserv: missing valid name for `Provides:’ please add.
    insserv: Script homebridge is broken: incomplete LSB comment.
    insserv: missing valid name for `Provides:’ please add.
    insserv: Script homebridge is broken: incomplete LSB comment.
    insserv: missing valid name for `Provides:’ please add.
    insserv: Script homebridge is broken: incomplete LSB comment.
    insserv: missing valid name for `Provides:’ please add.
    insserv: Script homebridge is broken: incomplete LSB comment.
    insserv: missing valid name for `Provides:’ please add.
    insserv: Script homebridge is broken: incomplete LSB comment.
    insserv: missing valid name for `Provides:’ please add.
    insserv: Script homebridge is broken: incomplete LSB comment.
    insserv: missing valid name for `Provides:’ please add.
    Executing /usr/sbin/update-rc.d homebridge enable
    insserv: Script homebridge is broken: incomplete LSB comment.
    insserv: missing valid name for `Provides:’ please add.
    insserv: Script homebridge is broken: incomplete LSB comment.
    insserv: missing valid name for `Provides:’ please add.
    insserv: Script homebridge is broken: incomplete LSB comment.
    insserv: missing valid name for `Provides:’ please add.
    insserv: Script homebridge is broken: incomplete LSB comment.
    insserv: missing valid name for `Provides:’ please add.
    insserv: Script homebridge is broken: incomplete LSB comment.
    insserv: missing valid name for `Provides:’ please add.
    insserv: Script homebridge is broken: incomplete LSB comment.
    insserv: missing valid name for `Provides:’ please add.
    insserv: Script homebridge is broken: incomplete LSB comment.
    insserv: missing valid name for `Provides:’ please add.
    insserv: Script homebridge is broken: incomplete LSB comment.
    insserv: missing valid name for `Provides:’ please add.

    thoughts?

  10. I have 2 things to helpout with.
    to see journal logs I have to run the following hopefully this can help others
    sudo journalctl -u homebridge -f

    Second if anyone is having couldn’t connect to this accessory from device to homebridge verify how many accessories you have, I have one platform openHAB but every accessory created in it or item is concidered an accessory. there is no error for over 100 accessories and 100 is the max per homebridge. For the openhab to homebrige addon there is a skipitem true function you can add to your config.json which will not sync the items you do not need. This will take time to sync mine took around 24 hours before I could access the accessories just use the journal line above and once it starts showing your accessories getting data not resgitering you will be good.
    Hope this helps anyone with this issue

  11. I struggled with NFarinas and the main guide too. had to reinstall RPI from scratch! Twice… so I am nervous about following your process.
    I have homebridge up and running manualy with 2 plugins (Smartthings and nest) working fine.
    If I now install following your process:
    Your approach has some subtle differences.
    1. Nfarina’s guide suggests /var/lib/homebridge as the directory …you and others seem to be using just var/homebridge.. Is there a reason for this?
    2. This means we would have to edit the homebridge file in etc/defaults/because it references var/lib/homebridge. Is this correct?
    3. on my previous attempts it wouldn’t find the plugins or the accessories… \I read posts about copying the persist folder but it didn’t seem to work 100% . Any thoughts?

    1. Folder structure is most likely bc of different operating systems. Are you installing it on a raspberry pi? You should be fine modifying the steps if your directories are different.

      1. I was installing on fresh RPI with noobs
        Followed farina process all the way through and RPI and Homebridge working perfectly on RPI manually

        I know I “should” be safe to do this but I’ve done it twice and it’s not worked. Would it matter which version of nodejs etc? (I am running 7.5.0)

  12. Hi!

    I’m having a little trouble.

    Just running the homebridge binary works flawlessly, the service on the other hand does not.

    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 tis 2017-02-28 22:26:57 CET; 2s ago
    Process: 7989 ExecStart=/usr/bin/homebridge $HOMEBRIDGE_OPTS (code=exited, status=1/FAILURE)
    Main PID: 7989 (code=exited, status=1/FAILURE)
    [email protected]:~ $

    Any ideas?

      1. Thanks, and by the way, thanks for a great guide!

        Haven’t had the opportunity to test yet but I’m curious as to why there’s $HOMEBRIDGE_OPTS in the service when it’s not needed when starting manually, shouldn’t be necessary?

          1. Ok, makes sense!

            Got it working now, went step by step again and it turned out I’d forgotten the “-R” flag when copying the “persist” directory so it was just an empty folder!

            Thanks a bunch!

  13. Hi, firstly thanks for posting this run through, so much clearer than the official documentation. I ran into a problem at step 9 though, after typing “sudo systemctl enable homebridge” i get an ERROR: Invalid argument response. Any idea why?

      1. I found my problem. I hadn’t copied the whole gist, I had left out the last t from the end of the word “target” in homebridge.service, once I edited the file I could run the enable command no problem. Now homebridge runs all the time, every time! Thank you so, so much for posting these instructions.

  14. I’m sorry, I have a silly question. Once I paste the gists into the files, how do I exit and save them. In a separate tab, I subsequently get:

    [email protected]:~ $ sudo systemctl enable homebridge
    Failed to execute operation: No such file or directory

    I must therefore have failed to create the directory.

  15. Hi, my apologies. I managed to save the gists.

    I am now getting this message:

    i:~ $ 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 Wed 2017-03-22 17:48:28 UTC; 2s ago
    Process: 19091 ExecStart=/usr/bin/homebridge $HOMEBRIDGE_OPTS (code=exited, status=1/FAILURE)
    Main PID: 19091 (code=exited, status=1/FAILURE)

    Would anyone please be able to help me?

      1. Hi Tim, thank you but I realised that I had a typo in one of the files. All working now! Thank you very much.

  16. Tim,
    Just found this page. I have been struggling to set up Homebridge on my PI. This looks really helpful. Think I will start again from scratch rather than try and overlay onto what does not work now. Just need a couple of hours over next few days. Hopefully will not need to comeback to you!

    Regards Tony

Leave a Reply

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