Skip to content

Instantly share code, notes, and snippets.

@SFrost007
Last active March 18, 2018 17:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SFrost007/40d9fca1a030dc4832aa816de22687b0 to your computer and use it in GitHub Desktop.
Save SFrost007/40d9fca1a030dc4832aa816de22687b0 to your computer and use it in GitHub Desktop.
Raspberry Pi Homebridge Setup

Based on the Raspberry Pi instructions here

First install dependencies:

Switch to newer GCC as default:

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.9 60 --slave /usr/bin/g++ g++ /usr/bin/g++-4.9

Install LibAvahi-dev:

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

Install Homebridge itself

sudo npm install -g --unsafe-perm homebridge node-gyp

Install common dependency for bluetooth plugins

sudo apt-get install bluetooth bluez libbluetooth-dev libudev-dev
npm install -g noble

We also need to grant Node permission to control Bluetooth LE advertising without sudo:

sudo setcap cap_net_raw+eip $(eval readlink -f `which node`)

Or when using the python version, grant bluepy-helper permission:

cd /usr/local/lib/python3.4/dist-packages/bluepy
cd /srv/homeassistant/lib/python3.4/site-packages/bluepy
sudo setcap 'cap_net_raw,cap_net_admin+eip' bluepy-helper

Install Superlights package

npm install -g homebridge-superlights

Install Bluetooth package and dependencies (TODO: WIP)

npm install -g homebridge-bluetooth

Reverse-engineering bluetooth messages to lightbulb

First, use the official application to control the bulb while examining the characteristics in a tool such as:

Note down the readable characteristics before/after changing a value. Repeat until a single characteristic is identified for the desired property.

$ sudo hcitool lescan
LE Scan ...
68:9E:19:05:2D:2D (unknown)
68:9E:19:05:2D:2D (unknown)
51:57:2F:16:E9:35 (unknown)
51:57:2F:16:E9:35 (unknown)

Pick out bluetooth address of bulb

$ sudo gatttool -I
> connect 68:9E:19:05:2D:2D
> primary
attr handle: 0x0001, end grp handle: 0x000b uuid: 00001800-0000-1000-8000-00805f9b34fb
attr handle: 0x000c, end grp handle: 0x000f uuid: 00001801-0000-1000-8000-00805f9b34fb
attr handle: 0x0010, end grp handle: 0x0022 uuid: 0000180a-0000-1000-8000-00805f9b34fb
attr handle: 0x0023, end grp handle: 0xffff uuid: 0000ffb0-0000-1000-8000-00805f9b34fb
Notification handle = 0x002e value: 21 04 98 1e 37 00 72

> characteristics
[snip]
handle: 0x0024, char properties: 0x0e, char value handle: 0x0025, uuid: 0000ffb1-0000-1000-8000-00805f9b34fb
handle: 0x0026, char properties: 0x1e, char value handle: 0x0027, uuid: 0000ffb2-0000-1000-8000-00805f9b34fb
[...]

Now:

  • Look for the uuid matching line from spreadsheet
  • Get char value handle for that characteristic (0x0027)
> char-write-cmd 0x0027 d0ff0000
> disconnect
$ exit

Set up Homebridge config files

mkdir ~/.homebridge
cp /opt/nodejs/lib/node_modules/homebridge/config_sample.json ~/.homebridge

Create an example config file

The homebridge-bluetooth repository contains some examples which show how to configure Bluetooth accessories. A simple example for an RGB LED strip is:

{
  "bridge": {
    "name": "Raspberry Pi Zero",
    "username": "CC:22:3D:E3:CE:30",
    "port": 51826,
    "pin": "012-34-567"
  },
  "description": "Raspberry Pi Zero Homebridge",

  "platforms": [
    {
      "platform": "Bluetooth",
      "accessories": [
        {
          "name": "Desk Arduino",
          "name_note": "Arduino on the desk connected to the RGB light strip",
          "address": "12:34:56:78:90:AB",
          "services": [
            {
              "name": "Desk Lights",
              "name_note": "RGB light strip along the back of the desk, providing monitor backlighting",
              "type": "Lightbulb",
              "UUID": "A7B10010-EEEE-5377-FF6C-D104768A1214",

              "characteristics": [
                {
                  "type": "On",
                  "UUID": "57E54BF1-8574-47BE-9C1D-A0DBFC8FA183"
                }, {
                  "type": "Brightness",
                  "UUID": "57E54BF2-8574-47BE-9C1D-A0DBFC8FA183"
                }, {
                  "type": "Saturation",
                  "UUID": "857E54BF3-8574-47BE-9C1D-A0DBFC8FA183"
                }, {
                  "type": "Hue",
                  "UUID": "857E54BF4-8574-47BE-9C1D-A0DBFC8FA183"
                }
              ]
            }
          ]
        }
      ]
    }
  ]
}

Setting Homebridge to run at startup

All the above should be tested by manually starting homebridge until the desired config is reached. Once configured, see here or here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment