Instructions and an OpenHAB2 rules file for setting up a Philips Hue Smart Dimmer Switch to work with non-Hue devices. It’s the secret instruction manual you never knew you didn’t have!
25 Jan. 2019 UPDATE: These instructions do not seem to work with release 2.5.0-M1 of OpenHAB. I believe a regression has been introduced to the dimmer event channel. Remote activity appears in the logs, but the channel event shows no activity, unlike version 2.4.0. I can’t find any documentation that any relevant component has been intentionally changed. So, for the time being, just stick with 2.4.0 if you use these instructions.
If you want to ignore some potentially useful, but also potentially tedious observations, and just get to the HOWTO component, then skip to “Prerequisites” down below.
I’ve been berzerking on wacky light bulbs since Black Friday 2018, when I got a Philips Hue starter kit for a seemingly reasonable price and started turning my apartment into a 1980s disco. The Hue bulbs are pretty nice, but they’re awfully expensive at the moment, so I filled out my home with “smart lights” from other brands. At this point I have 2 Hues and their Bridge, 7 TP-Link bulbs (having returned a 4-pack of Wiz Smart Lights to Costco because those lights are garbage, and then found Micro Center selling the TP-Links at $20/per), plus a colored LED strip driven by a mysterious Chinese wi-fi thingy, and a few Wemo smart switches.
Hue’s requisite Bridge communicates with the bulbs via a non-TCP/IP wireless transmission system called ZigBee, and won’t interact with non-Hue bulbs. Consequently it sidesteps a few problems with Wi-Fi, but it also threatens to lock the undiscerning customer into Hue’s ecosystem, and I’m not too crazy about that sort of thing. Google and Amazon, among others, have products that can unite all your miscellaneous smart home junk under one umbrella named Alexa or Echo or whatever, but I’m also not crazy about talking to my furniture, nor do I appreciate having all my private conversations transmitted to strangers. I think they should be paying customers to buy the damn things (well, they are artificially cheap and occasionally free but still). I could rant about that sort of thing at length, but in short, I’ve been working hard lately to unite all my smart junk into a system that doesn’t require me to talk when I’m alone, open any obvious security holes that turn my apartment into a Bulgarian botnet, or monetize my privacy for 12 cents a year. I’d say I’m nearly the right degree of paranoid.
So, at some point I bought a Hue Remote Dimmer (model RWL020) with four buttons. Unfortunately, by design, it can only interact with the Hue Bridge, meaning it can only control the two Hue lights in my hallway. It’s a nice design though, with a cradle about the size of an ordinary light switch wall plate, and using strong magnets as a clip for a remote that can be left in the cradle or removed. So, for a few weeks it became my only real light switch. In the meanwhile, during my aforementioned berzerker period, I wrote a Ruby script that allows me to use input devices to control my smart-whatzits via Linux, and set that up on a cheap, crummy old laptop I don’t use anymore (most people would use a Raspberry Pi). I wound up with two mini-remote keyboards, one of which I mounted by my front door (also using magnets) so I can shut off all my lights and stereo with one button when leaving the apartment.
But, having 70-button keyboard control panels in place of light switches can be a bit confusing for me and my guests. I had to put a cheatsheet on the wall. What I really want apparently doesn’t exist: a small panel of buttons, ideally in the form factor of a light switch wall socket (eliminating batteries and recharging), capable of sending arbitrary REST API requests on a wireless network. The closest I’ve found is the Amazon Dash Button, which is cheap–possibly free–but that will require some hacking unless I want to end up with a box of Depends whenever someone drops by. And I’ve got some coming but they haven’t arrived yet for me to mess around with. There are other similar products out there but as best as I could tell they all lock you into a product ecosystem (e.g. Leviton switches) and I wanted to avoid that. Plus they’re expensive and not as handy as the Hue ones.
So when I happened on a mild price reduction for the Hue Remote Dimmers at Best Buy, I thought I’d take a stab at getting them to work with my other bulbs, and picked up 3 more of them for $20/each. After much mucking about, I finally got the Hue Dimmers to work with my cheapo bulbs. I’ll explain how below if I haven’t lost you already.
The central component replacing Alexa/Echo/whatever-the-hell in my HA projects has been OpenHAB2. Like a thankfully deaf-mute Alexa, OpenHAB2 offers bindings for all the different smarty devices in my apartment, including Hue, the TP-Link bulbs, the Wemo switches, and even (with some limitations) my stereo. It also supports monitoring the Hue Remote Dimmers by querying the Hue Bridge itself. That seems like a recipe for slow responses, but it actually works with minimal lag. (Incidentally, another guy used Home Assistant to do the same thing I’ll describe here. While I didn’t follow his instructions, since I already had OpenHAB set up, I credit him with showing me that it’s possible and generating $60 for Best Buy.)
As a side-note, I tried using the remotes through HA-Bridge, a handy Hue emulator. In other words, it pretends it’s a Hue Bridge and that all your off-brand bulbs/switches/whatever are actually Hue bulbs/switches/whatever. It can interface with wi-fi devices, OpenHAB, Alexa, and I don’t know what else. So, it’s great if you want to use Hue Disco type apps with non-Hue lights. Most Hue apps will work with HA-Bridge, including the Philips Hue app itself– partially. HA-Bridge currently doesn’t support Hue’s sensors or “rooms”, so you can’t fully get things set up. It won’t operate without a room, and it currently dies while trying to save the first room. Even if it could handle rooms, you probably couldn’t pair the remotes using HA-Bridge since there’s no ZigBee device.
I also tried crossing the streams using the “All 4 Hue” app, and while I was able to get All4Hue to see both bridges (having paid $4 for an upgrade), it doesn’t currently offer a way to tie the remote from your real bridge to the lights on the fake bridge (that is, the HA-Bridge), so you can’t use all those nice remote control customizations it offers.
So you’ll have to write your own OpenHAB2 rules (see next paragraph). Actually, you just have to copy and edit mine.
Unfortunately, OpenHAB2 doesn’t make it obvious how to configure the remotes, and this is the only aspect of OpenHAB I haven’t been able to set up entirely through its Paper UI. The instructions for creating rules (pre-programmed automation instructions) are fairly confusing, to boot, causing me to waste a lot of time trying to determine syntax. But once I realized that the rules files are instantly reloaded when they are changed (saving a minute of OpenHAB2 restart time per change), I was able to cruise into success, and the result isn’t overly complicated. All that wasted time must explain why I wrote these instructions (i.e. to waste some more time).
I’m going to start with the assumption that you can set up OpenHAB2 since there are plenty of instructions for that. I’m using Linux Mint, which is kind of an offshoot of Ubuntu, so a few details might be different on different Linux distributions. My instructions might work on a Mac, but if you can afford to waste good money on a Mac you should probably just buy the Hue bulbs in the first place and then you won’t need these instructions. As for Windows, I guess it’s possible (OpenHAB2 runs under Java) but I don’t have anywhere near the patience to find out when every time I click anything a page pops up with stupid colored squares, NFL scores, celebrity gossip, and ads for Angry Birds or whatever is the 2018 equivalent. Windows 8 and above exist solely to ruin your productivity, monitor your activity, and sell ads, so use Linux if you have any say in the matter. Blah blah blah. Here are the instructions.
Prerequisites:
- If you’re me, start with about 60 oz. of coffee.
- Unfortunately, you’ll also need an actual Hue Bridge. You may be able to get around this if you have a computer (or Raspberry/Arduino/whatever) with a ZigBee interface of some sort, but I haven’t messed with that idea yet and I’ll leave that to a more sophisticated hardware hacker type person. I’m pretty sure the remote uses ZigBee though, so if you don’t have something that can receive that signal, you’re out of luck. For what it’s worth, you can probably get the Hue Bridge for cheap without buying the lights (or bundled with a cheap, non-colored light).
- You’ll need OpenHAB2 set up. Get the Hue binding and pair it with your actual Hue. You may as well get all your light “things” in order too. When OpenHAB2 is fully set up you should be able to control your cheapo lights with the built-in control panel.
- You’ll need at least one Hue Dimmer Remote, obviously.
Steps to Get the Remotes Working:
- Pair the remote dimmer(s) with your Hue Bridge using Hue’s app. You need to use your phone for this. Remotes fall under “Accessory setup.” Once the app finds the remote, don’t configure it–leave it disconnected from any rooms. The Bridge will still receive the signals and report them in its web API, which is all OpenHAB2 needs.
- Once they’ve been paired with your Hue Bridge, they can also show up under OpenHAB2. They’ll probably appear in your inbox immediately. At that point you can add them in as Things and they’ll have a unique sensor ID.
- Modify the script below in your favorite text editor, and save it as /etc/openhab2/rules/dimmer.rules. You need to replace two things: the dimmer’s event channel name and the light bulb’s color channel name (or the non-color equivalent). I’ve marked these with ZZZZZZ and XXXXXX respectively in the example. The real channel names can be found in OpenHAB’s control panel. The name for the dimmer’s event channel, at the top and in quotes, should include the colons (look in the OpenHAB control panel for this). The name for the bulbs (or whatever else you want to control) should be formatted with underscores where the colons are. I have TP-Link dummy examples in there, but the process would be the same for other lights–replace the whole name, not just the XXXXXX part. You might also want to replace the phrase “bedroom” with the actual room you’ll be using, if you care about what shows up in the logs. Or remove the log lines completely.
- Once you place the script in that directory (for which you’ll probably have to sudo), you should restart OpenHAB2. (This actually may not be necessary, but it can’t hurt.) Under Debian distros, if you’re running OpenHAB2 as a service, you’d run “sudo service openhab2 restart” and type in your password, then wait half a minute for OpenHAB to cycle.
Here’s the rules script. (I describe what the buttons do afterward.)
rule "bedroom dimmer"
when
Channel "hue:0820:001788ZZZZZZ:15:dimmer_switch_event" triggered
then
logInfo("Bedroom received event: ", receivedEvent.getEvent())
var myBulb = tplinksmarthome_lb130_XXXXXX_color
var String[] parts = myBulb.state.toString().split(",")
var hue = Integer.parseInt(parts.get(0))
var sat = Integer.parseInt(parts.get(1))
var bri = Integer.parseInt(parts.get(2))
switch (receivedEvent.getEvent()) {
case "1002.0": {
if (bri == 0)
{
logInfo("bedroom", "turning bedroom light on")
myBulb.sendCommand(ON)
}
else
{
logInfo("bedroom", "light is already on")
var Integer new_hue = (hue + 30) % 360
myBulb.sendCommand(new_hue.toString() + "," + sat.toString() + "," + bri.toString())
}
}
case "1003.0": {
logInfo("bedroom", "max white")
myBulb.sendCommand("0,0,100")
}
case "2002.0": {
logInfo("bedroom","brightening bedroom light")
var Integer new_bri = (bri + 20)
if (new_bri > 100)
new_bri = 100
myBulb.sendCommand(hue.toString() + "," + sat.toString() + "," + new_bri.toString())
}
case "3002.0": {
logInfo("bedroom","dimming bedroom light")
var Integer new_bri = (bri - 20)
if (new_bri < 0)
new_bri = 0
myBulb.sendCommand(hue.toString() + "," + sat.toString() + "," + new_bri.toString())
}
case "2003.0": {
logInfo("bedroom","de-saturating bedroom light")
var Integer new_sat = (sat - 20)
if (new_sat < 0)
new_sat = 0
myBulb.sendCommand(hue.toString() + "," + new_sat.toString() + "," + bri.toString())
}
case "3003.0": {
logInfo("bedroom","saturating bedroom light")
var Integer new_sat = (sat + 20)
if (new_sat > 100)
new_sat = 100
myBulb.sendCommand(hue.toString() + "," + new_sat.toString() + "," + bri.toString())
}
case "4002.0": {
logInfo("bedroom","turning off bedroom light")
myBulb.sendCommand(OFF)
}
}
end
Here’s what the buttons do in this example:
- Quickly pressing “ON” will turn on the light with its current settings. If it is already on, it will rotate 30 degrees around the color rainbow. (The default behavior for these remotes, when set up the normal way, is to flip through different color temperatures, but where’s the fun in that?)
- Holding down “ON” for a second or more, then releasing, will restore the light to white at max brightness.
- The dimmer buttons increment/decrement the brightness by 20%.
- Holding down the dimmer buttons for a second or more, then releasing, does the same for saturation (less saturation = more whiteness).
- “Off” just turns it off.
Further explorations:
- If you want to control multiple lights, just add “var myBulb2 = ….” and double/triple/etc. all the “myBulb” lines with the other bulbs you’re working with, assuming you’re not trying to do anything more complicated.
- If you want to add additional remotes for other rooms, you can copy the entire thing and add it at the end of the same file. Be sure to change the rule name (the first line), in addition to the remote channel and the bulb targets.
- The event codes in use are listed in the documentation for the OpenHAB2 Hue binding (except for the “.0” suffix, which I can’t explain). There are a few I didn’t use (e.g. holding down “Off”).
- I’ve left in debugging output. You can just do a “tail -f /var/log/openhab2/openhab.log” to see what’s going on (including errors if you’ve screwed up).
- You could get a lot crazier with this, of course, but ultimately this is a dimmer and a light switch, which is what you probably want. If you do implement something crazier, please share it!