Results 1 to 5 of 5

Thread: Installing Homebridge on a Raspberry Pi 2

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Automated Home Lurker
    Join Date
    Jan 2016
    Posts
    9

    Default Installing Homebridge on a Raspberry Pi 2

    Hi,

    Over Christmas I did a proof of concept and install Homebridge on a Debian virtual machine. That worked well and so bit the bullet and bought a Raspberry Pi 2 Model B. I thought you might like to see what I had to do to make it work. If you find any issues with this, let me know and I will try and clarify.

    Best wishes

    Michael

    This assumes you have got past the Noobs setup.

    I used these links to as a basic for my install

    http://www.automatedhome.co.uk/apple...mart-home.html

    https://gist.github.com/johannrichar...feb6adb9eb61a/

    My Raspberry Pi 2 is cabled and not using Wifi. I also gave the Raspberry Pi 2 a static ip address.

    I ran the commands below to get the latest updates.

    sudo apt-get update
    sudo apt-get upgrade


    Next I installed Node. Do this as Root.

    sudo su

    Type whoami to find out which user you are - you should be root

    I checked my Node version before I installed it with the command

    node -v

    It returned

    v0.10.29

    I ran the command below to install Node

    curl -sL https://deb.nodesource.com/setup_5.x | bash -

    apt-get install --yes nodejs


    I reran - node –v and got version v5.3.0

    Type Exit to get out of root

    Type whoami to find out which user you are - you should be your default user

    Homebridge wouldn’t install without me installing the below.

    sudo apt-get install libavahi-compat-libdnssd-devsudo apt-get install libavahi-compat-libdnssd-dev

    Install Homebridge

    sudo npm install -g homebridge

    Next install plugins. For me I installed the below.

    sudo npm install -g homebridge-wemo

    If you now run Homebridge you will get an error message about no config file being found.

    Make the config file

    cd ~/.homebridge/

    Make config file - I changed the username and pin. I just changed some of the characters, but kept the format. This is a default config from the Homebridge website

    {
    "bridge": {
    "name": "Homebridge",
    "username": "CC:22:3D:E3:CE:30",
    "port": 51826,
    "pin": "031-45-154"
    },

    "description": "This is an example configuration file with one fake accessory and one fake platform. You can use this as a template for creating your own configuration file containing devices you actually own.",

    "accessories": [
    {
    "accessory": "WeMo",
    "name": "Coffee Maker"
    }
    ],

    "platforms": [
    {
    "platform" : "PhilipsHue",
    "name" : "Hue"
    }
    ]
    }

    Type nano config.json – This will make the file in the ~/.homebridge folder. You can copy and paste the config straight into this file, but be careful it pastes correctly.

    You can test the file has been saved with - cat ~/.homebridge/config.json

    I would copy the output and paste it to this site. http://jsonlint.com. It will validate the configuration. If it fails, check the quotes are correct and look out for added spaces. You don’t want to see curly quotas. They should be straight.

    Type Homebridge and it should start. You can use the command

    ps -aux | grep [h]omebridge from another terminal session to check Homebridge is running.

    The [h] - stops the command itself from showing up in the result

    As it stands if you reboot the Raspberry Pi 2 , Homebridge won’t restart. To make Homebridge start on reboot do the following. I changed the instructions slightly by making the user homebridge_user. These instructions are based on these instructions - https://gist.github.com/johannrichar...feb6adb9eb61a/


    Make a new user - sudo useradd --system homebridge_user
    Make this folder - sudo mkdir /var/homebridge

    Now set up the permissions for the above folder

    sudo groupadd homebridge_group
    sudo usermod -a -G homebridge_group homebridge_user
    sudo usermod -a -G homebridge_group pi


    You can check users were added to the new group - grep homebridge_group /etc/group
    I’ve added the pi user and the homebridge_user

    sudo chown -R :homebridge_group /var/homebridge
    sudo chmod -R g+rwX /var/homebridge
    sudo chmod g+s /var/homebridge


    Log out of the terminal session and log back in so the permissions take effect

    Copy the Homebridge config to the folder made above - cp ~/.homebridge/config.json /var/homebridge/

    If you get a permissions error then revisit the above. If it doesn’t work this may effect the homebridge_user as well and it has to be able to write to the /var/homebridge folder

    Now you need to setup the config files to run the service on boot. I followed the instructions from here - https://github.com/nfarina/homebridg...a-Raspberry-Pi. Below is what I did.

    I copied homebridge and the homebridge.service files to the ~/home/pi/.homebridge with an sftp client. I then moved them to the correct folders. You can download them from here - https://gist.github.com/johannrichar...feb6adb9eb61a/

    Now move the files to the correct folders.

    sudo mv ~/.homebridge/homebridge /etc/default/homebridge
    sudo mv ~/.homebridge/homebridge.service /etc/systemd/system/homebridge.service


    sudo nano /etc/systemd/system/homebridge.service

    You will need to edit homebridge.service file. Change line 7 from

    User=homebridge

    To

    User=homebridge_user

    You can check the file with

    cat /etc/systemd/system/homebridge.service

    Now we need to make Homebridge run as a service

    Before you do that run this command - systemctl status homebridge

    This is a not working output

    homebridge.service - Node.js HomeKit Server
    Loaded: loaded (/etc/systemd/system/homebridge.service; disabled)
    Active: inactive (dead)

    sudo systemctl daemon-reload
    sudo systemctl enable homebridge
    sudo systemctl start homebridge



    Check the service is running

    systemctl status homebridge

    This shows it is working output

    ● homebridge.service - Node.js HomeKit Server
    Loaded: loaded (/etc/systemd/system/homebridge.service; enabled)
    Active: active (running) since Mon 2016-01-11 06:44:10 UTC; 38s ago
    Main PID: 345 (homebridge)
    CGroup: /system.slice/homebridge.service
    └─345 homebridge

    I renamed the user config file in ~/.homebridge so there is no confusion where the config file is running from. It is now in - /var/homebridge/

    Now reboot the Raspberry Pi 2 and run - systemctl status homebridge - to check it runs on reboot

    My only question now is, can you get the output from Homebridge like you would if you ran it manually. Is there a log you can tail?

  2. #2
    Automated Home Ninja Mavis's Avatar
    Join Date
    Oct 2014
    Location
    North East
    Posts
    322

    Default

    Thanks for this - it is good to get a step by step guide as it get so confusing trying to resolve problems when you don't know what you are doing! So will this resolve the problem that people are having where everything looks as if it is installed correctly but when you open Eve everything shows as being unreachable?

    I will try a total wipe (again) and give it a try at the weekend.

    I had everything installed and working to use Siri and SmartThings but it only worked a couple of times.

  3. #3
    Automated Home Lurker
    Join Date
    Jan 2016
    Posts
    9

    Default

    Hi Mavis,

    I first used MyTouchHome and then moved to Eve. I found Eve much better, but I had some issues when I moved. I just reset my HomeKit settings via my phone. I did read somewhere that it can take some time to sync/reset so I did it the night before I built the Pi.

    I would recommend you run Homebridge manually before trying to make it run as a service. I had problems with mine last night until I realised that I hadn't changed the user name in the .service file. I thought the service was running, it was, but said it was died. This was because it couldn't read the config file. Once it runs as a service it is hard to tell. You won't get that nice, no config file error.

    I tried to put some before and after examples in, and how to tell what is going on, like checking the users are in the security group etc.

    I hope it helps. Let me know how you get on.

    Best wishes Michael

  4. #4
    Automated Home Ninja Mavis's Avatar
    Join Date
    Oct 2014
    Location
    North East
    Posts
    322

    Default

    Quote Originally Posted by bazcurtis View Post
    Hi,


    My only question now is, can you get the output from Homebridge like you would if you ran it manually. Is there a log you can tail?
    Is this what you mean? (taken from this link - https://github.com/nfarina/homebridg...a-Raspberry-Pi)

    I now have mine running fine - the problem I had was caused, I think, using a wifi dongle. I connected with an ethernet cable and it hasn't dropped out in 3 days (I currently have Terminal open on the Pi.)

    I am still going to do a new install and follow your instructions on a new SD card (so if it goes wrong then I can put the old one in.) and I will also insert the code to keep it running.


    To view the running logs, you can tail the output log or error log:

    tail -f /var/log/homebridge.log
    tail -f /var/log/homebridge.err

  5. #5
    Automated Home Lurker
    Join Date
    Jan 2016
    Posts
    9

    Default

    That is what I wanted, but it didn't work for me. Let me know if it works for you. Maybe I need to turn on more logging in the config file, but let me know what you see.

    It might work as your is setup now, but it might change once you run it as a service.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •