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.

237 thoughts to “Setup Homebridge to Start on Bootup”

  1. Noobee here… Thanks for publishing… After completing my initial Homebridge instill and using your proceedure to run Homebridge after boot, I’ve been swapping out plugins to try to find one that works properly with my Chamberlain garage door opener which has been a challenge. So, I’ve been removing plugins and changing config.json file info accordingly. Do I need to be moving these changes to the files under the homebridge user that was created by following the exact same steps? Seems that I have 2 different instances of homebridge running now based on executing homebridge command from the root user and then running the “systemctl status homebridge” command based on the fact that there are 2 different homekit codes being shown. Your help would be appreciated!

    1. One other point I forgot to mention… I am not able to connect to homebridge from the home app on any of my devices..

      1. Correct. I ran successfully but I can’t connect to homebridge from my ios device. That said, it seems that I have 2 instances of homebridge running at the same time under root and then var/homebridge. So, any changes made need to be moved to the homebridge user folder correct?

          1. So, needed to come back to this issue this morning…
            – So I restarted the rpi3 and logged in.
            – Ran “systemctl status homebridge” command – See below – everything came back as running – gave me key of 031-45-154 to connect my ios devices with
            – changed directory to “/var/homebridge” and ran homebridge command and it came back and gave me a key of 123-45-678

            Would this suggest that my config.json file is screwed up. Not sure how you would get the 2 different keys

            As you can see when I run homebridge command manually from the /var/homebridge director it loads the homebridge-chamberlin plugin and everything seems normal except for the DNS error. Any suggestions?

            ssh session window copy below

            ——————————————————————
            login as: pi
            [email protected]‘s password:
            Linux raspberrypi3 4.9.59-v7+ #1047 SMP Sun Oct 29 12:19:23 GMT 2017 armv7l

            The programs included with the Debian GNU/Linux system are free software;
            the exact distribution terms for each program are described in the
            individual files in /usr/share/doc/*/copyright.

            Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
            permitted by applicable law.
            Last login: Tue Feb 6 06:19:27 2018 from 10.0.1.107
            [email protected]:~ $ systemctl status homebridge
            ● homebridge.service – Node.js HomeKit Server
            Loaded: loaded (/etc/systemd/system/homebridge.service; enabled; vendor prese
            Active: active (running) since Mon 2018-02-05 19:49:49 UTC; 1 day 22h ago
            Main PID: 372 (homebridge)
            CGroup: /system.slice/homebridge.service
            └─372 homebridge

            Feb 05 19:49:55 raspberrypi3 homebridge[372]:
            Feb 05 19:49:55 raspberrypi3 homebridge[372]:
            Feb 05 19:49:55 raspberrypi3 homebridge[372]:
            Feb 05 19:49:55 raspberrypi3 homebridge[372]: Or enter this code with your HomeK
            Feb 05 19:49:55 raspberrypi3 homebridge[372]:
            Feb 05 19:49:55 raspberrypi3 homebridge[372]: ┌────────────┐
            Feb 05 19:49:55 raspberrypi3 homebridge[372]: │ 031-45-154 │
            Feb 05 19:49:55 raspberrypi3 homebridge[372]: └────────────┘
            Feb 05 19:49:55 raspberrypi3 homebridge[372]:
            Feb 05 19:49:55 raspberrypi3 homebridge[372]: [2018-2-5 19:49:55] Homebridge is

            [email protected]:~ $ ls
            Desktop Documents Downloads Music oldconffiles Pictures Public python_games Templates Videos
            [email protected]:~ $ cd /var/homebridge
            [email protected]:/var/homebridge $ ls
            accessories config.json package-lock.json persist
            [email protected]:/var/homebridge $ cd /
            [email protected]:/ $ cd /var/homebridge
            [email protected]:/var/homebridge $ homebridge
            *** WARNING *** The program ‘node’ uses the Apple Bonjour compatibility layer of Avahi.
            *** WARNING *** Please fix your application to use the native API of Avahi!
            *** WARNING *** For more information see
            *** WARNING *** The program ‘node’ called ‘DNSServiceRegister()’ which is not supported (or only supported partially) in the Apple Bonjour compatibility layer of Avahi.
            *** WARNING *** Please fix your application to use the native API of Avahi!
            *** WARNING *** For more information see
            [2018-2-7 18:23:22] Loaded plugin: homebridge-chamberlain
            [2018-2-7 18:23:22] Registering accessory ‘homebridge-chamberlain.Chamberlain’
            [2018-2-7 18:23:22] —
            [2018-2-7 18:23:22] Loaded config.json with 1 accessories and 0 platforms.
            [2018-2-7 18:23:22] —
            [2018-2-7 18:23:22] Loading 1 accessories…
            [2018-2-7 18:23:22] [Garage Door] Initializing Chamberlain accessory…
            Setup Payload:
            X-HM://0023OA632HANI
            Scan this code with your HomeKit app on your iOS device to pair with Homebridge:

            Or enter this code with your HomeKit app on your iOS device to pair with Homebridge:

            ┌────────────┐
            │ 123-45-678 │
            └────────────┘

            /usr/lib/node_modules/homebridge/node_modules/mdns/lib/advertisement.js:56
            dns_sd.DNSServiceRegister(self.serviceRef, flags, ifaceIdx, name,
            ^

            Error: dns service error: name conflict
            at new Advertisement (/usr/lib/node_modules/homebridge/node_modules/mdns/lib/advertisement.js:56:10)
            at Object.create [as createAdvertisement] (/usr/lib/node_modules/homebridge/node_modules/mdns/lib/advertisement.js:64:10)
            at Advertiser.startAdvertising (/usr/lib/node_modules/homebridge/node_modules/hap-nodejs/lib/Advertiser.js:47:30)
            at Bridge.Accessory._onListening (/usr/lib/node_modules/homebridge/node_modules/hap-nodejs/lib/Accessory.js:661:20)
            at emitOne (events.js:116:13)
            at HAPServer.emit (events.js:211:7)
            at HAPServer._onListening (/usr/lib/node_modules/homebridge/node_modules/hap-nodejs/lib/HAPServer.js:190:8)
            at emitOne (events.js:116:13)
            at EventedHTTPServer.emit (events.js:211:7)
            at EventedHTTPServer. (/usr/lib/node_modules/homebridge/node_modules/hap-nodejs/lib/util/eventedhttp.js:65:10)
            [email protected]:/var/homebridge $ ^C

      2. here is what I got when I ran the systemctl command from root

        [email protected]:~ $ systemctl status homebridge
        ● homebridge.service – Node.js HomeKit Server
        Loaded: loaded (/etc/systemd/system/homebridge.service; enabled; vendor prese
        Active: active (running) since Mon 2018-02-05 19:49:49 UTC; 10h ago
        Main PID: 372 (homebridge)
        CGroup: /system.slice/homebridge.service
        └─372 homebridge

        Feb 05 19:49:55 raspberrypi3 homebridge[372]:
        Feb 05 19:49:55 raspberrypi3 homebridge[372]:
        Feb 05 19:49:55 raspberrypi3 homebridge[372]:
        Feb 05 19:49:55 raspberrypi3 homebridge[372]: Or enter this code with your HomeK
        Feb 05 19:49:55 raspberrypi3 homebridge[372]:
        Feb 05 19:49:55 raspberrypi3 homebridge[372]: ┌────────────┐
        Feb 05 19:49:55 raspberrypi3 homebridge[372]: │ 031-45-154 │
        Feb 05 19:49:55 raspberrypi3 homebridge[372]: └────────────┘
        Feb 05 19:49:55 raspberrypi3 homebridge[372]:
        Feb 05 19:49:55 raspberrypi3 homebridge[372]: [2018-2-5 19:49:55] Homebridge is
        lines 1-17/17 (END)…skipping…
        ● homebridge.service – Node.js HomeKit Server
        Loaded: loaded (/etc/systemd/system/homebridge.service; enabled; vendor preset: enabled)
        Active: active (running) since Mon 2018-02-05 19:49:49 UTC; 10h ago
        Main PID: 372 (homebridge)
        CGroup: /system.slice/homebridge.service
        └─372 homebridge

        Feb 05 19:49:55 raspberrypi3 homebridge[372]:
        Feb 05 19:49:55 raspberrypi3 homebridge[372]:
        Feb 05 19:49:55 raspberrypi3 homebridge[372]:
        Feb 05 19:49:55 raspberrypi3 homebridge[372]: Or enter this code with your HomeKit app on your iOS device to
        Feb 05 19:49:55 raspberrypi3 homebridge[372]:
        Feb 05 19:49:55 raspberrypi3 homebridge[372]: ┌────────────┐
        Feb 05 19:49:55 raspberrypi3 homebridge[372]: │ 031-45-154 │
        Feb 05 19:49:55 raspberrypi3 homebridge[372]: └────────────┘
        Feb 05 19:49:55 raspberrypi3 homebridge[372]:
        Feb 05 19:49:55 raspberrypi3 homebridge[372]: [2018-2-5 19:49:55] Homebridge is running on port 34725.
        ~
        ~
        ~
        ~
        ~
        ~
        ~
        ~
        ~
        ~
        ~
        ~
        ~
        ~
        lines 1-17/17 (END)
        ● homebridge.service – Node.js HomeKit Server
        Loaded: loaded (/etc/systemd/system/homebridge.service; enabled; vendor preset: enabled)
        Active: active (running) since Mon 2018-02-05 19:49:49 UTC; 10h ago
        Main PID: 372 (homebridge)
        CGroup: /system.slice/homebridge.service
        └─372 homebridge

        Feb 05 19:49:55 raspberrypi3 homebridge[372]:
        Feb 05 19:49:55 raspberrypi3 homebridge[372]:
        Feb 05 19:49:55 raspberrypi3 homebridge[372]:
        Feb 05 19:49:55 raspberrypi3 homebridge[372]: Or enter this code with your HomeKit app on your iOS device to pair with Homebridge:
        Feb 05 19:49:55 raspberrypi3 homebridge[372]:
        Feb 05 19:49:55 raspberrypi3 homebridge[372]: ┌────────────┐
        Feb 05 19:49:55 raspberrypi3 homebridge[372]: │ 031-45-154 │
        Feb 05 19:49:55 raspberrypi3 homebridge[372]: └────────────┘
        Feb 05 19:49:55 raspberrypi3 homebridge[372]:
        Feb 05 19:49:55 raspberrypi3 homebridge[372]: [2018-2-5 19:49:55] Homebridge is running on port 34725.
        ~
        ~
        ~
        ~
        ~
        ~
        ~
        ~
        ~
        ~
        ~
        ~
        ~
        ~

      1. Hey Tim,

        not really … attached you will find a screenshot before and after the cmd_on command of cmdswitch2. As you can see, it starts the mplayer but the mplayer will be closed within a couple of second. Afterwards it looks like the first status report.

        Screenshot: http://awi.myknack.de/cmd.png

        Any idea?

          1. hmm I have chown and chmod the location of the folder which contains the scripts. Do I need any other special settings? When I use homebridge without the service, everything works.

  2. I could really use some help. I am running into issues when this process when I have LiftMaster2 installed along with my Nest. If I do not have the LiftMaster2 plugin installed I am able to get this process working with just the Nest plugin. Here is the error I get when running the systemctl status homebridge command,

    [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 Tue 2018-02-13 01:08:15 UTC; 3s ago
    Process: 7086 ExecStart=/usr/bin/homebridge $HOMEBRIDGE_OPTS (code=exited, status=1/FAILURE)
    Main PID: 7086 (code=exited, status=1/FAILURE)

    Feb 13 01:08:15 raspberrypi systemd[1]: homebridge.service: Main process exited, code=exited, status=1/FAILURE
    Feb 13 01:08:15 raspberrypi systemd[1]: homebridge.service: Unit entered failed state.
    Feb 13 01:08:15 raspberrypi systemd[1]: homebridge.service: Failed with result ‘exit-code’.

    Any help would be greatly appreciated

      1. Hey, im having the exact same issue.
        And yes, it happens when I run “/opt/nodejs/lib/node_modules/homebridge/bin/homebridge”
        I can not run “.homebridge” or simply “homebridge” as stated in EVERY Tutorial…

        Thanks for your help…

        1. I Edited the ExecStart Part to “ExecStart=/opt/nodejs/lib/node_modules/homebridge/bin/homebridge $HOMEBRIDGE_OPTS” which now runs the Homebridge on Startup, now I will need to configure it somehow getting my 433MHz Outlets to run…

          Thank you!

    1. Hello. I was following Tim’s instructions in the article and encountered the same error as you do. The issue could be due to NPM trying to access the .config folder for user homebridge.

      Anyway, you can try the following steps, as it worked for me:

      1) sudo mkdir /home/homebridge
      2) sudo mkdir /home/homebridge/.config
      3) sudo chmod -R 0777 /home/homebridge

      And just to be sure:
      4) sudo chmod -R 0777 /home/homebridge/.config

      After the 4 steps, the homebridge service should run fine. Check your logs again to confirm.

  3. can´t get it to work. need help
    [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 Fri 2018-02-16 10:14:18 UTC; 8s ago
    Process: 1103 ExecStart=/usr/local/bin/homebridge $HOMEBRIDGE_OPTS (code=exited, status=203/EXEC)
    Main PID: 1103 (code=exited, status=203/EXEC)

    Feb 16 10:14:18 raspberrypi systemd[1]: homebridge.service: Failed with result ‘exit-code’.

  4. Hey, great guide and easy to follow. I’m an absolute n00b so please bear that in mind.

    I’ve gone through every step, although at step 5 onwards it appeared nothing was happening, the commands were being entered but it just took me to the next row to enter them in (that might be by design). When I got to the final step to check system status I get the following:

    [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 Fri 2018-02-16 10:37:44 UTC; 9s ago
    Process: 3778 ExecStart=/usr/local/bin/homebridge $HOMEBRIDGE_OPTS (code=exited, status=203/EXEC)
    Main PID: 3778 (code=exited, status=203/EXEC)

    I’m not sure what this means or how to correct that? Any assistance would be appreciated. Thank you.

    1. Actually, ignore that. I forgot to delete /local/ from step two. For anyone else who is having the same issue, here’s the n00b explanation.

      At step 2, enter ‘sudo nano /etc/systemd/system/homebridge.service’ and the gist you need to paste is below. What I hadn’t done is delete /local/ from ExecStart=/usr/local/bin/homebridge $HOMEBRIDGE_OPTS but the correct gist below has it removed.

      Thanks for this guide. It works a treat (if you read and understand it properly)

      [Unit]
      Description=Node.js HomeKit Server
      After=syslog.target network-online.target

      [Service]
      Type=simple
      User=homebridge
      EnvironmentFile=/etc/default/homebridge
      ExecStart=/usr/bin/homebridge $HOMEBRIDGE_OPTS
      Restart=on-failure
      RestartSec=10
      KillMode=process

      [Install]
      WantedBy=multi-user.target

  5. I have a similar but even complicated problem. My homebridge was running fine for a year and it stopped working since last week. In my attempt to fix it, upgraded homebridge to a later version, which in turn required me to upgrade node and npm. Now i can get homebridge fully functional when
    [email protected]:~ $ homebridge
    however cannot the life of me get it to auto start!

    hint to the problem could be
    [email protected]:~ $ which homebridge
    /home/pi/.nvm/versions/node/v4.8.7/bin/homebridge
    Doing same using su
    [email protected]:/home/pi# which homebridge
    /usr/local/bin/homebridge

    I have tried your steps with
    ExecStart=/usr/local/bin/homebridge $HOMEBRIDGE_OPTS
    and
    ExecStart=/home/pi/.nvm/versions/node/v4.8.7/bin/homebridge $HOMEBRIDGE_OPTS

    Gets following error
    [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 Sat 2018-02-17 23:17:54 ACST; 8s ago
    Process: 1809 ExecStart=/home/pi/.nvm/versions/node/v4.8.7/bin/homebridge $HOMEBRIDGE_OPTS (code=exited, status=1/FAILURE)
    Main PID: 1809 (code=exited, status=1/FAILURE)

Leave a Reply

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