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.

67 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 ?

  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

Leave a Reply

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