Using a Hue dimmer remote with Home Assistant
I now have a Hue dimmer remote pulling double-duty by directly controlling some Hue bulbs and triggering events in Home Assistant (including short- and long-presses!). This post covers how I set it up; there are several options out there, and I think I found the best one.
First, a few words about Phillips Hue…
Many people have used Phillips Hue for years, and they’re one of the most recognizable and widely-available “smart home” product lines out there. But even though I’ve been dabbling in home automation for almost 5 years, until recently I never bought any Hue products, mainly because I don’t like the idea of not being able to use wall switches to control lights, like we all learned to do as soon as we were tall enough to reach said switches with a bathroom stool and annoy the crap out of parents.
With Hue bulbs, the wall/lamp switch has to always be on, or else it’s a dumb bulb. In other words, it goes against my policy of keeping legacy control options available (in other words, a switch in a smart home should still work like a normal switch).
But for some situations — namely, lamps that aren’t connected to wall switches — I realized Hue bulbs and a remote could be a great fit. I personally find the user experience of lamps highly annoying. On most of them you have to reach up under the shade, grope around awkwardly until you find the little knob thing, twist it once — no, twice? — maybe the wrong way, then try the other way…it’s just not a great experience. It’s even worse when I’m comfortably in bed and have to awkwardly lever myself halfway out of the bed in order to reach the lamp knob to turn it off for the night.
But with the Hue dimmer, you can mount the wall plate wherever you want with a little double sided tape, and the remote itself is magnetically attached to the mounting plate. This lets you put it in easy reach wherever you want it — a wall that doesn’t have a switch already there, a coffee table, or in my case my bedside table.
I had one important additional requirement for deploying Hue bulbs/remotes, however: the remote had to be able to be used for more than just controlling the bulbs in our two bedside lamps. I wanted to be able to use it to activate my “Night Mode” script in Home Assistant, for example, that powers down everything in the house.
Happily, someone has created a Hue Sensor component for Home Assistant, which allows Home Assistant to detect button presses on the Hue dimmer remote. And, unlike some other methods of “hijacking” the Hue remote for Home Assistant, this method still allows the Hue remote to be used “natively” for controlling the bulbs the way Phillips intended — so you don’t have to write additional automation rules in Home Assistant just to handle the stuff Hue already does out of the box. Win-win!
Let’s dive in.
Setting up Hue remote with Home Assistant
I can’t take any credit for this, I just pieced together things others have done. But I’m writing this guide because (a) it wasn’t easy to find out if this was even possible, so I’m trying to spread the word, and (b) I got confused when I first tried to implement this, so I’m offering my own take in the hopes that it helps somebody else.
- Home Assistant (I’m running Hass.io 0.57.3 at time of writing)
- A Phillips Hue hub and dimmer remote, with the hub already setup on your network as per Phillips’ normal instructions and the remote paired to the hub
- A downloaded copy of robmarkcole’s Hue Sensors HASS code
- Basic knowledge of how to edit Home Assistant configuration files
- If you haven’t already, configure your Phillips Hue hub with Home Assistant. You should do this via the automatic “discovery” method — if discovery is enabled, HA will show you a config card for your Hue hub when it detects it on the network.
- Connect to your Home Assistant server via SSH, SFTP, or SMB; in your HA config directory, create a directory called custom_components if one doesn’t already exist.
- Take the files in the custom_components directory of robmarkcole’s Hue Sensors HASS code and copy them into your HA server’s custom_components directory. This should result in two new files added to your server:
[path to hass]/config/custom_components/hue.py [path to hass]/config/custom_components/sensor/hue.py
- Add to your HA configuration file, at the “root” level (not nested inside anything else):
- Also add to your HA config, in the “sensor:” section:
sensor: - platform: hue
Now restart Home Assistant, and if there are no errors, you should be able to detect button presses from the Hue remote and use them to trigger automations! The remote will be listed as a sensor, with its name based on what you named it when you set it up in the Hue app. I called mine the very unimaginative hue_dimmer_1, so when I started up Home Assistant after following the above steps I saw this in my devices list:
You simply watch for state changes on that sensor, and do whatever you need to do.
The second column is the device’s current state; in that shot you see that my last action with the remote was to hold down button the “bright” button. The buttons are identified in Home Assistant with numbers 1-4 from top to bottom, and you’ll get events like 1_click or 1_hold depending on whether you just tapped the button or held it.
And that’s it!
I have this setup to control my two Hue bulbs next to the bed “normally,” through the Hue app, and I have it integrated into several automations in Home Assistant:
- If 1_hold, run Morning script
- If 4_hold, run Night script
- If 4_click when in Evening mode, disable motion-activated lights in the bedroom for the rest of the evening (this is to accommodate when one of us goes to be before the other; when I come into the bedroom after my wife is already asleep, I don’t want the lights coming on automatically)
Performance-wise, I’m mostly impressed. The response time is very quick — state changes are detected almost instantly, which I’ve heard is not the case with some other lighting systems like Ikea’s Tradfri (although I haven’t used it myself). One niggle is that periodically the lights seem to just…disconnect from the Hue hub and don’t respond right away. But that is rare and usually resolves itself within a minute.
I hope this was helpful to anyone looking to integrate Hue into Home Assistant. For me, having this integration with the remote was the tipping point that led me to buy some Hue products.