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.

291 thoughts to “Setup Homebridge to Start on Bootup”

  1. Hi Tim, I to am a newbie, but was able get through your instructions with no issues. Thank you. Just one question… Where do I go to find the output of the executing homebridge?

    Thanks john

  2. Tim,

    Thanks so much for this tutorial.

    I ran into one issue on Step 9

    Once i entered: sudo systemctl enable homebridge
    I got this response: Failed to enable unit: Invalid argument

    All the commands I entered up to step 9 worked fine.

    Any idea what caused the Invalid Argument? i’m using a newer Rpi with the latest software.
    I have homebridge running well and just wanted it to boot on launch.

    Any help is appreciated. Regards,

  3. Anybody ever tried to save every data from homebridge accessories (temperature, door open/close/ motion) and save them on a sheet or on a server ?

  4. Hello! small question if you don’t mind regarding the point5:

    sudo cp ~/.homebridge/config.json /var/homebridge/

    Does it mean that each time an accessory is added to the ~/.homebridge/config.json file, the config file in /var/homebridge/ has to be updated manually as well??

    Thx!

  5. On reboot the “Smartthings” accessory not working but nest is working.

    after I reboot, if I disable these and enable again then working
    sudo systemctl enable homebridge
    sudo systemctl start homebridge

    any help please?

  6. Everything works great, but when I want to add additional plug ins or update the config.json, do I update both config.json locations or just /var/homebridge? Do I add plugins the normal way (i.e. npm – g install homebridge-plugin)? Thanks

  7. I’m a total NOOB when it comes to this stuff, but hopefully you can help me figure out what’s wrong… I’m getting some errors… It’s failing “with result ‘exit-code'”

    ● homebridge.service – Node.js HomeKit Server
    Loaded: loaded (/etc/systemd/system/homebridge.service; enabled; vendor preset: enabled)
    Active: activating (auto-restart) (Result: exit-code) since Sun 2018-04-22 19:51:23 PDT; 6s ago
    Process: 11501 ExecStart=/usr/bin/homebridge $HOMEBRIDGE_OPTS (code=exited, status=1/FAILURE)
    Main PID: 11501 (code=exited, status=1/FAILURE)

    Apr 22 19:51:23 raspberrypi systemd[1]: homebridge.service: Unit entered failed state.
    Apr 22 19:51:23 raspberrypi systemd[1]: homebridge.service: Failed with result ‘exit-code’

    Any chance you would have any advice?

      1. Thank you! I tried deleting the user entirely after attempting to fix the permissions, but it may not have worked all the way because when I got down to step 4 it said it existed… Anyway, I was able to remove the folder completely and start again from there. My last resort was to completely wipe the SD card and start from scratch… Luckily it didn’t have to come to that.

  8. I am having issues with getting this fully working. The steps above get homebridge to start on reboot, I get the following from the systemctl status:

    $ systemctl status homebridge
    ● homebridge.service – Node.js HomeKit Server
    Loaded: loaded (/etc/systemd/system/homebridge.service; enabled)
    Active: active (running) since Fri 2018-04-27 21:20:05 UTC; 4s ago
    Main PID: 2155 (homebridge)
    CGroup: /system.slice/homebridge.service
    └─2155 homebridge

    So all looks fine, but within Homekit all devices state “Not Responding”. However if I run:

    sudo systemctl stop homebridge

    then just run homebridge manually from the terminal then the devices in Homekit all work as expected.

    Any ideas on what the issue may be?

      1. Thanks Tim, I have figured it out. The setup was correct following your guide above, the issue I had was in my config.json file. Specifically with syntax in the accessory section. I had a rogue character that once removed, I rebooted and all worked fine as expected.

  9. I followed your guide but bI’m getting this error when I check the status of the service. What have I done wrong?

    [[email protected]:~ $ systemctl status homebridge

    ● homebridge.service – Node.js HomeKit Server

    Loaded: loaded (/etc/systemd/system/homebridge.service; enabled; vendor preset: enabled)

    Active: activating (auto-restart) (Result: exit-code) since Thu 2018-05-03 17:49:23 BST; 8s ago

    Process: 592 ExecStart=/usr/local/bin/homebridge $HOMEBRIDGE_OPTS (code=exited, status=203/EXEC)

    Main PID: 592 (code=exited, status=203/EXEC)

    May 03 17:49:23 raspberrypi systemd[1]: homebridge.service: Unit entered failed state.

    May 03 17:49:23 raspberrypi systemd[1]: homebridge.service: Failed with result ‘exit-code’

      1. Thanks for the reply the Tim. I managed to solve the problem shortly after posting, it turned out I had to remove ‘local’ from the gist info at Step 2 – ExecStart=/usr/local/bin/homebridge $HOMEBRIDGE_OPTS

        Once I’d done that and re-ran the commands in Steps 8-10 the service started perfectly and has ran ever since.

        Thanks for the great and simple guide from someone with no previous linux experience.

  10. hi Tim,

    Followed your instructions. I am not sure on step 2.1; My homebridge was by default installed under /home/pi/.homebridge (at least that’s where the config.json shows up) but when I changed
    ExecStart=/usr/local/bin/homebridge $HOMEBRIDGE_OPTS to ExecStart=/home/pi/.homebridge something goes wrong at the end. I was expecting this to be wrong but what is the correct path?
    regards,
    Paul

  11. hi Tim,
    i am getting this error, after manual running of home-bridge after adding Fibaro plug in… please give me solution

    [email protected]:~ $ homebridge
    [5/6/2018, 6:23:25 PM] Plugin /usr/local/lib/node_modules/homebridge-fibaro-hc2 requires Node version of >7.0.0 which does not satisfy the current Node version of v4.7.0. You may need to upgrade your installation of Node.
    [5/6/2018, 6:23:28 PM] Loaded plugin: homebridge-fibaro-hc2
    [5/6/2018, 6:23:28 PM] Registering platform ‘homebridge-fibaro-hc2.FibaroHC2’
    [5/6/2018, 6:23:28 PM] —
    [5/6/2018, 6:23:28 PM] There was a problem reading your config.json file.
    [5/6/2018, 6:23:28 PM] Please try pasting your config.json file here to validate it: http://jsonlint.com
    [5/6/2018, 6:23:28 PM]
    /usr/local/lib/node_modules/homebridge/lib/server.js:207
    throw err;
    ^

    SyntaxError: Unexpected token “
    at Object.parse (native)
    at Server.str.replace.Server._loadConfig (/usr/local/lib/node_modules/homebridge/lib/server.js:201:19)
    at new Server (/usr/local/lib/node_modules/homebridge/lib/server.js:57:38)
    at module.exports (/usr/local/lib/node_modules/homebridge/lib/cli.js:26:16)
    at Object. (/usr/local/lib/node_modules/homebridge/bin/homebridge:17:22)
    at Module._compile (module.js:409:26)
    at Object.Module._extensions..js (module.js:416:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Function.Module.runMain (module.js:441:10)

  12. Hi Tim,
    thanks for the guide. Unfortunately, I had some troubles running homebridge at the startup when I finally realize where was the mistake: the right path in the steps 4, 5, 6 and 7 (at least for me) is /var/lib/homebridge/ and not /var/homebridge.
    After I created the folder, moved the file and assign the right permissions I got HomeBridge to start.
    I hope that will help other users.

  13. Hi there, I am really new to this as well, but I can’t get pass the adding the device bit. I added my Homebridge to the iOS Home app but it say:
    “Additional setup required. Add related accessories with home assistant in the manufacturer’s app”
    I tried looking on the Nest app with no luck, also tried using apps such as Insteon+ and Ezzi Home but they can’t find any new devices, although Ezzi Home did find my Homebridge, but I don’t see any options to get it working, just that Homebridge is running and the version history. Anyone got any ideas?
    Thanks!

  14. My Soma smart shades plugin is not working under systemctl start homebridge but works when I start Homebridge manually. It uses control.py. Any ideas what I can do?

    1. Usually, this is a file or folder permission issue. Make sure the homebridge user has the correct permissions to access the folders it needs for the application.

  15. Hello there, thanks for the tutorial! I have a little problem, every time I boot the Raspberry home bridge starts without any problem but it keeps asking me to push the link button on the bridge in order to create a user! If I do, it all starts perfectly. How can I solve this problem? Thanks 🙂

  16. I total noob on this, but I’m gettin this error – Process: 1739 ExecStart=/usr/bin/homebridge $HOMEBRIDGE_OPTS (code=exited, status=1/FAILURE)
    Any help?
    Thanks

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.