This Instructable shows how to control the HomeBrite Bluetooth lightbulbs using the Philips HUE system. If you read my other instructable, you'll notice that this solution is much, much simpler.
In short, this is how it works - the code on the Raspberry Pi will query the Philips HUE bridge for the light level of an existing bulb, and then connect (over Bluetooth) to a HomeBrite bulbs and set its brightness level.
Background - I'm using the HUE system to control the lights in my apartment, and I've been looking for a way to control the candelabra bulbs in an Ikea chandelier. While there are all kind of hacks, I wanted a fully compatible solution so I can use the HUE dimming switch and Alexa.
After chickening out on playing with mains electric power, I decided that I need a simple, unintrusive solution. I looked into IR-controlled candelabra bulbs, but they weren't bright enough. The only alternative I found were the HomeBrite lights. However, the only way to control them was a really crappy (and slow) app.
So I did some digging, and I found that the bulbs are using a bluetooth chip from CSR, and the proprietary csrmesh protocol. I was about to try and figure out how to hack it by decompiling the apk file... but then I found out that this was already done! This guy, Nash Kaminski, saved my a couple of days already. You can read a detailed explanation about it on his website. Thanks Nash! You're the real hero of this story.
Oh, the other cool thing about these bulbs is that they do actually create some sort of a mesh network. We'll be using the broadcast feature to control all of the bulbs via one bulb.
Note - this solution is simple, but not perfect. Because of the implementation of the csrmesh library, there is some delay. I hope that sometime soon I can contribute an update that will solve this (but it will have to wait until after my PhD general exam...).
Step 1: What You'll Need
- A Philips HUE bridge + app
- An existing Philip HUE compatible bulb. We will "mirror" the light level of this bulb, so it can be any bulb you are already using
- HomeBrite Bluetooth Smart LED Light Bulb(s) (by Feit Electric). I used three B10 Candelabra that I got from EBay for cheap. Luckily for us, there bulbs are getting cheaper because of bad reviews of their app.
- Raspberry Pi. Any version should work, as long as it has Bluetooth and it's connected to the same network as the HUE bridge. I used a Raspberry Pi 2 with a Bluetooth dongle and connected it directly to the router (I have bad experience with Raspberry Pi and wifi)
Step 2: Setting Up Your Bulb(s)
This part is straightforward - setup your HUE and HomeBrite systems as usual. You can find the information here. Make sure your write down the 4 digit PIN used for configuring the HomeBrite Bulbs.
If the app can't find the bulb, you'll might need to reset it (for example, if it's a used bulb). To hard reset HomeBrite bulb(s), place the bulb(s) on a single power supply such as a light switch or a table lamp. Turn the bulb(s) on for 18 seconds then turn it back off for 1 second. Repeat the process 4 times. Yes, it's very annoying.
Also, I recommend restarting your phone (or at least killing the app and resetting Bluetooth) after setting up the bulbs. It appears that the app keeps an open connection to the bulbs (sometimes?) and that will prevent you from finding the MAC address and connecting to the bulb from your Raspberry Pi.
Step 3: Finding the MAC Address of a HomeBrite Bulb
In order to connect to the HomeBrite mesh, you need to know the MAc address of one of the bulbs. To do that, either use a phone app (I recommend nRF Connect) or the hcitool lescan command(see below). Look for a device called "Feit Bulb".
> sudo hcitool lescan
LE Scan ... 79:24:AD:C9:68:68 (unknown) 79:24:AD:C9:68:68 (unknown) 80:E4:DA:70:3A:CE f008cDrO 80:E4:DA:70:3A:CE (unknown) 00:00:C1:00:D9:A8 Feit Bulb 00:00:C1:00:D9:A8 (unknown)
Note - sometimes the bulb won't show up in the scan. I found that it is easier to find it right after powering up the bulb.
Step 4: Setting Up the Code on the Raspberry Pi
ssh into your raspberry box, then:
- Install python 2.7 (it you haven't already)
- Install required libraries: sudo apt-get install python-dev python-pip git
- Clone my repository: git clone https://github.com/OrenLederman/csrmesh-hue-bridge.git
- Install python dependencies: sudo pip install -r requirements.txt
- Create a .env file and setup the hub bulb name, PIN code, etc. You can use the env_template file as reference. The code will load this file automatically when it starts
- Try it out - python csrmesh-hue-bridge.py .
Important! The first time you try it, you will need to press the button on the HUE Bridge to register your Raspberry Pi.
If the script fails to connect to the bulb, make sure you exit the HomeBrite app, and perhaps even restart your phone. It seems that the app keeps an open connection to the bulb (sometimes?), and therefore blocks other connections.
Step 5: Optional - Loading Code on Boot With Supervisor
If you want the bridge code to start when the RasPi boots, you can use supervisor:
- Install supervisor: sudo apt-get install supervisor
- Create a config file: sudo touch /etc/supervisor/conf.d/csrmesh-hue-bridge.conf
- Edit the file and add the following lines:
I also recommend to add a process that will reset bluetooth every couple of minutes (it will sometimes get stuck...)
- Create another config file: sudo touch /etc/supervisor/conf.d/hcireset.conf
- Edit it and add the following lines:
command=sh -c "while sleep 300; do hciconfig hci0 reset & echo reset; done" directory=/tmp autostart=true autorestart=unexpected</p>
- Ask supervisor to start new services: sudo supervisorctl reread && sudo supervisorctl update
- Make sure the processes are up: sudo supervisorctl status
- The output should look like this:
bridge RUNNING pid 16625, uptime 0:05:12
hcireset RUNNING pid 16691, uptime 0:04:54