Home Assistant and Hue - a perfect example of integration done right.
I've been having fun rolling out Philips Hue lights around the house. Obviously, Home Assistant plays a vital role in gluing it all together, but there's more than one way to do it. This post explains some notes and discoveries I have made along the way and I explain how my integrations work.
This is a LONG post. It turns out there's a lot of nuances with all this. Or, there can be, if you think about things quite as thoroughly as I do.
Some pictures on this page are from the Hue website and screenshots from the official Hue Android app.
Getting the Hue
Philips have done a simply excellent job with Hue. The lights are bright and colourful (if you get the coloured ones) and there is a nice range to choose from including spotlights, candle bulbs, old-style filament-looking bulbs designed to be seen and regular-style light bulbs designed to blend in. There are LED strips and all sorts of shapes and sizes of feature fittings.
The way lights gracefully fade up and down and from one colour to another is simple but really elegant. I know this is a simple trick, and not exclusive to Hue by any means, but it really makes the system feel swanky.
On a techie side they've managed to position the ecosystem bang in the middle between being easy to use yet allowing enough fiddling and configuration complexity to let me use it more or less exactly as I want, with some caveats around the accessories.
They're not cheap and I took advantage of some generous Black Friday deals. Various bundles of lights and accessories exist so it's worth planning your deployment up front and doing a bit of spreadsheeting to work out the best way to buy all the bits you want.
There are three categories of light from the range. Cost goes up as the list goes down.
White - a fixed colour ('white' but can be from cold or warm depending on the light).
White Ambience - White but with a changeable colour temperature from cold to warm.
White and Colour Ambience - White, with changeable colour temperature, or any colour you could ever want. These are the most expensive.
All can be dimmed.
Hue Basics
The system either works under direct Bluetooth control, or with the addition of a Hue Bridge, the system operates as its own Zigbee mesh. Bluetooth control is decidedly small-scale and is really only designed for a couple of lights and a switch. I didn't even consider it for my purposes and purchased the Hue Bridge from the outset.
Setting up a new light is straightforward: You add a light through Zigbee discovery (or by serial number): Turn the light on, tell Hue to search and it will* appear in the app. You tell Hue where the light is, give it a name and presto - the app can control the light within seconds.
A nice little thing is that when you select a light in the app, e.g. to adjust it, the light gives a little fade down/up to show you which one you've picked. This simple idea makes setting up multiple lights very much easier. Good one, Hue.
Adding a new accessory is similar. Press-and-hold the button until a little LED flashes then tell Hue to search for it. Once found*, place into a room, configure what you want the buttons to do and you're good to go.
* I have added over a dozen lights and a bunch of accessories to my Hue system and all of them were discovered without trouble. I imagine this isn't always the case which is why Hue lets you add by serial number. When I added four lights at once the app's discovery screen did take a little while to count up to four; after it found the first one the app gave me the button to continue with setup but by waiting a little while before moving off the discovery screen the process found all four lights. So the tip here is to be patient during discovery.
Lights and accessories are placed into room and zone groups. These are hierarchical - a room (top level) can have multiple zones (secondary level) within it. A light or accessory can only be in one room and one zone, which sounds limiting but practically I have found this to be fine and obviously reflects how you're likely to have things installed in your house.
Rooms, Zones and Scenes
The hierarchical grouping of zones into rooms is important when it comes to scenes and accessory control. Scenes are defined in, and accessories are placed into, a room or a zone which restricts the extent of their control.
A Scene is a preset look for all the lights in it. Some of these lights can be off, but that's as in 'turn off', not 'do nothing to this light'. So a scene defined in a room will control all the lights in the room. A scene defined in a zone will only control the lights in that zone and will leave other lights in the room untouched.
Example
I have a Sitting Room (room) in which I have defined two zones:
Dining Zone
Sofa Zone
Most scenes are defined in the respective zones so I can control the lights in the Dining Zone separately to the Sofa Zone.
Certain scenes (e.g. "watch a film") are defined in the room (not the zone) so recalling the scene configures every light at the same time - even turning the Dining Zone lights off.
I also have one dimmer switch configured in the room, so rolling the dimmer down dims the lights in the Dining and Sofa Zones. Although the dimmer is physically by the sofa, if I'd placed it into the Sofa Zone the dimmer would not be able to control the Dining Zone light.
Internal Hue or Third-Party Integration
The Hue system is flexible and with its rooms, zones and scenes, lights and accessories (buttons and dimmer switches) you can create highly complicated setups completely within the system. Indeed, anyone with Hue lights but no Home Assistant would be very happy with what they could do with it. While I'm absolutely all for third-party control, keeping important functions (like lights coming on when you press a button) within the Hue system feels slightly safer to me and is also less likely to annoy the other members of the household if something were to cause Home Assistant to fail.
So: my lights and accessories live in Hue. That's all fine. BUT I've got some non-Hue lights - not the main lights in room, but the odd side light on a Shelly relay, that sort of thing - that I want to have switched at the same time as my Hue lights and by the same Hue button(s).
That's where Home Assistant comes in.
Hue Bridge
Although the Hue lights can work directly under Bluetooth control, for any decent control, and any integration with third-party systems, the Hue Bridge is required. This is the Zigbee hub for the Hue mesh network and hosts the API for the app and Home Assistant control.
Networking the bridge
The Hue Bridge has a wired Ethernet connection. It is connected to my 'user' VLAN and is assigned a static IP address by DHCP. My phone connects to the same subnet which is required so the phone app can discover the bridge. If my Home Assistant server was connected to the same VLAN I believe it would similarly discover the bridge, however in my house I have Home Assistant on a different VLAN so it couldn't. Instead, I opened the firewall between the subnets to let Home Assistant reach out to the Hue Bridge and added the Hue Bridge by its (known, static) IP address. This works fine.
Home Assistant opens a persistent TCP/IP connection to the Hue Bridge and is perfectly happy being routed through the firewall. Events (e.g. button clicks) in Hue appear in Home Assistant with zero delay, and Home Assistant has no trouble controlling the scenes and lights in Hue.
Home Assistant Integration
I'm using the official Hue Integration. They have done a great job of this. Everything in the Hue system appears in Home Assistant as a device: lights, switches/buttons, rooms and zones. Scenes in the Hue system are added as - you guessed it - Home Assistant scenes. Note that rooms and zones only appear in Home Assistant when there is a light assigned to them in the Hue app.
There was a tiny gremlin in the discovery: I noticed the integration needed a manual reload to add a room device when you first add a light to the room.
This level of access to the parts of the Hue system means you can get Home Assistant to reach in at whatever level you need to achieve a perfect integration.
Hue in Home Assistant
Device State
The state of Hue devices - on/off, level, colour - is reflected immediately in Home Assistant. For a single light this is obvious.
For rooms and zones it's slightly nuanced:
A room or zone will show as 'on' in Home Assistant when one or more light in that room/zone is turned on.
The level shown will be the highest level of any of the lights.
The colour shown will be the last colour selected on a light.
Adjusting the level or colour on the room/zone from Home Assistant will apply the setting to all lights in the zone which can cause some jumps in brightness.
It is advised to have Home Assistant interact with Hue at the highest group possible to minimise traffic to the bridge. While it might be tempting to have Home Assistant address every Hue light individually, that could lead to issues, says the Internet. Practically I have found using Home Assistant to control the rooms and zones gives me enough control, so that's all good.
Control
Lights can be turned on either by toggling the switch on the room or zone or by activating a scene. State is only available from the room or zone - you can't see that a particular scene is "on". Turning a room or zone on switches the lights to whatever state (level, colour) they were when they were last on, which isn't necessarily what you want. For example, if you have a dim scene at bed time but then want a bright scene next time the lights are turned on in the morning.
The optimum way of tackling this is by turning the lights on using scene-activation only. That way, you always know what you're going to get.
Turning the lights off could be either by activating an 'off' scene, or could be by toggling the switch on the room/zone. I generally prefer the latter because by exposing the room/zone switch to the Home Assistant dashboard, you also get an indication of whether the light(s) are on, and indeed the icon colour reflects the colour of the room/zone as reported by Hue.
Accessories
Accessories appear in Home Assistant as devices. Events on the device, e.g. button pushes, come through instantaneously and the integration has defined events including button press, button held down (which is triggered once a second as long as the button is held), and release after long- or short-press. By using a Home Assistant Automation triggered on the Hue accessory device, and configured to act on specific button action(s), the Hue accessories can become a powerful manual control point into Home Assistant.
When adding an accessory to the Hue system you are given the choice to Configure in Other App or to set the accessory up directly.
Configure in Other App tells Hue you plan to use the accessory to drive a third-party system (Home Assistant in my case) and not to configure any actions within the Hue system itself. The accessory 'belongs' to Hue in terms of the Zigbee mesh but other than that Hue takes no interest in it.
Fully setting an accessory up in Hue lets you assign the accessory to a room or zone and to set what scenes are recalled when buttons are pressed. In this mode, Home Assistant still gets all the button actions but scenes are actioned directly within Hue.
Hue Accessories Setup
As mentioned, I like to keep the button interaction with Hue lights within the Hue system where possible. So in most rooms I've chosen to fully set the accessories up. Buttons recall scenes and dimmer functions work directly on the lights, all without needing Home Assistant.
Of course, Hue accessories have some tricks up their sleeves.
A button can recall a single scene. I use this to have a button that always turns the lights on bright - the 'I just want light' button (good for visitors).
A button could recall a different scene at different times of day (the times are configurable). I use this to turn lights on to a warmer and dimmer scene in the evening.
A button could recall different scenes in a sequence so each button press selects the next scene in a loop. Limited to five scenes.
I have three types of accessories:
The simple Smart Button (one button)
The four-button Dimmer Switch (two buttons for dim up/down, two for light/scene control)
The Tap Dial Switch (four configurable buttons plus an overall rotatable ring around the outside)
Cost and complexity go up as you go down this list. Of all of these the Tap Dial switch is my favourite but it does command a premium price.
Smart Button
The simplest one. A single button that can either recall a different scene at different times of day, or cycle through scenes. The button is placed in a single room/zone.
Dimmer Switch and its Configuration Limitation
This is the middle ground. It has four-buttons with two buttons always dedicated to dimming. One button is labelled as a power button and the last is labelled "Hue" which is a bit vague. The accessory (i.e. all four of its buttons) is placed in a single room/zone.
In a bid, I suspect, to keep configuration simple, the control mode of the two not-dimmer buttons is limited to either time-based OR scene-based. You can't (within the Hue system) have one button doing a time-based scene recall and the other button doing a scene-by-scene cycle - which is what I wanted! I'll revisit this limitation later when I talk you through my case studies.
Tap Dial Switch
The best and most flexible of the lot. Philips seem to acknowledge you won't have so many Tap Dials - they're expensive - so have gone all-out with the configuration flexibility.
Each button can be independently configured in a different room/zone and can work as a scene-recall, time-based or scene-cycle button. The dimmer dial can be configured in yet another room/zone.
Case Studies
As we've seen, there are so many accessories, configuration options and Home Assistant integration possibilities! The best way for me to explain what I've done is through the use of some case studies.
Case Study 1: Child Bedroom
A simple room with only Hue lights.
1 Hue pendant light (a White and Colour Ambience Smart Bulb)
1 Hue Dimmer Switch
Config
The dimmer switch and the light are placed into a room in the Hue app. The dimmer is configured to work in scene mode where the 'Power' button always recalls the 'bright' scene and the 'Hue' button cycles through five pre-set scenes.
Conclusion
This simple set-up works perfectly for my daughter. I would have liked the 'power' button to pick different scenes at different times of day, but this wasn't possible with the dimmer switch in 'scene-cycle' mode (see limitations, above.)
Case Study 2: Sitting and Dining Room
A large room with multiple zones and some non-Hue lights on relays.
Hue Tap Dial switch
Sofa Zone
2 stylish Hue lights on floorstanding fittings by the sofa (G93 Globe Filament Lights)
2 Hue pendant lights (White and Colour Ambience Smart Bulbs)
2 wall-mounted Hue uplighters (E14 Candle Bulbs)
1 jar of fairy lights on a Sonoff relay switch
Dining Zone
Hue Smart Button
1 Hue pendant light (White Ambience Smart Bulb)
Picture and furniture accent lights on a single Shelly relay switch
Dimmer dial
The Tap Dial dimmer ring is placed in the Sitting Room room, so dims any lights that are turned on. This gives me a way to knock the overall brightness of the room down a little, including the Dining Zone.
Sofa scenes
The four Tap Dial buttons are configured to recall a single scene in the Sofa Zone. This gives the most user-friendly experience for the less technically-minded occupants of the house;
Button 1 always recalls the 'side lights' scene.
Button 2 always recalls the 'bright' scene (albeit a warmer scene in the evening).
Buttons 3 and 4 recall specific or colourful scenes e.g. the 'cinema mode'
These scenes are configured in the Sofa Zone so don't do anything to the lights in the Dining Zone. A long press on any button turns all the lights in the room off.
Fairy lights jar
The jar of fairy lights provides a little accent light in the corner of the room and is considered to be a side light that we always have on. I use a Home Assistant automation triggered on the Sofa Zone's on/off status to switch the Sonoff relay on/off accordingly. So the jar lights turn on as soon as any light in the Sofa Zone turns on. And off again when the last Sofa Zone light goes off.
Dining Zone button
The Smart Button is set to activate a scene in the Dining Zone, again, a warmer scene during the evening. These scenes are configured in the Dining Zone so don't do anything to the lights in the Sofa Zone. A second press, or a long press, turns the Dining Zone lights off.
Picture and furniture accent lights
These provide some added interest and are simply slaved off the Dining Zone's on/off status with another Home Assistant automation.
Conclusion
For the most-used room in the house, keeping the light control within the Hue system was desirable so I was keen to fully configure the Tap Dial and Smart Buttons within the Hue system. Slaving the accent lights off the applicable Hue zones with Home Assistant brings them under control - not through Hue directly but Home Assistant's access to the Hue zone device state glues them together seamlessly.
Case Study 3: Another Child Bedroom
A complicated room with Hue lights, a Shelly dimmer and some Shelly and Sonoff relay-driven lights.
1 Hue pendant light (a White and Colour Ambience Smart Bulb)
1 Hue Dimmer Switch
1 Shelly Dimmer connected to an LED strip around the ceiling perimeter
4 channels of Shelly and Sonoff switched side, desk and night lights
Shelly Dimmer
The complexity of this room all comes back to the presence of the Shelly Dimmer. I wanted to be able to dim these lights at the same time as dimming the Hue lights. I also wanted to be able to store scenes involving both the Hue light and the Shelly Dimmer.
The point at which the control for the Shelly and Hue lights meet is in Home Assistant. So for this room I broke my policy of keeping control within Hue, and configured the Hue dimmer switch 'in another app' - handing its functionality wholly over to Home Assistant. I then configured a Home Assistant automation for each of the four buttons individually:
Button 1 activates a typical 'bright' scene, setting the Hue pendant to bright and white, and the Shelly dimmer lights to bright. A second press turns them both off.
Button 2 and 3 dim lights up and down. The Automation dims the Hue and the Shelly Dimmer together.
If the 'dim up' button is pressed while the lights are off (the state being taken from the Hue room device), the first click of the 'dim up' actually activates a 'dim' scene to set the light to an appropriate colour.
Button 4 toggles the Shelly Dimmer lights on/off, because my son likes to have independent control of these.
I also created further scenes with specific looks - e.g. a cosy scene and a 'space' (blue) scene. These can't be recalled by the Hue Dimmer switch because I ran out of buttons, instead buttons on the Home Assistant dashboard have to be used.
Automation
Here's the Home Assistant automation for the 'dim up' button. It uses both the single-press and the held-press button on the Dimmer switch device as a trigger. The dimming function leverages the brightness_step_pct parameter of the light.turn_on service, which adds 10% to the light each time it's called.
alias: "Switch: Ted Dimmer Button 2"
trigger:
- device_id: d0467fc00b0dc3ce0f6bde6ef28ac48c
domain: hue
platform: device
type: initial_press
subtype: 2
unique_id: 57864363-a938-495b-90ad-7328dead6bfb
- device_id: d0467fc00b0dc3ce0f6bde6ef28ac48c
domain: hue
platform: device
type: repeat
subtype: 2
unique_id: 57864363-a938-495b-90ad-7328dead6bfb
condition: []
action:
- if:
- condition: state
entity_id: light.ted_s_bedroom
state: "off"
then:
- service: scene.turn_on
target:
entity_id: scene.ted_s_ha_morning
metadata: {}
else:
- service: light.turn_on
data:
brightness_step_pct: 10
target:
entity_id:
- light.shelly_ted_perimeter
- light.ted_s_bedroom
mode: single
Alexa..?
We have Amazon Echo devices in almost every room of the house so, of course, it was necessary to integrate the Hue lights with them. Hue can be integrated directly, but that's not how I chose to do it so I can't comment on how well it works, though from what I've seen of the rest of the Hue system, they will have done a good job.
All my Echo integration comes through Home Assistant. I'm a paying subscriber to the Nabu Casa cloud service primarily for access to my Home Assistant while away from home, but it also provides a very well-featured interface into Alexa through the Home Assistant skill.
I adopted the same policy for my Alexa integration as I did for Home Assistant:
Control Hue devices by room or zone wherever possible, not by individual lights
If Alexa is required to operate individual lights then they do need to be exposed individually. This is the case in my son Ted's room in the configuration snippet below. He likes to get Alexa to operate his individual lights on request.
Most light interaction should be through scene activation
In the cloud configuration for Home Assistant I configured it to always expose scenes (from Alexa's POV it won't matter if these are Home Assistant scenes or Hue scenes), and also to expose Hue rooms on a light-by-light opt-in basis.
alexa:
filter:
include_entities:
- light.study
- light.sitting_room
- light.elody_s_bedroom
- light.ted_s_bedroom
- light.shelly_ted_perimeter
- switch.ted_under_bed
- switch.ted_s_bedroom_desk
- switch.ted_s_bedroom_reading_light
- switch.ted_s_bedroom_star_light
- switch.sw21
include_domains:
- scene
Alexa needs to have at least one light in every room so she knows what to toggle when you say "Alexa, lights on". This has the same limitation as Home Assistant, in that the lights will come 'on' to whatever colour/brightness they were previously, but it's good enough. Most lighting changes are achieved by saying "Alexa, activate 'scene name'" which is a reliable way of both turning lights on to a known state, and also changing the look. You can also say "Alexa, turn the lights purple" which gives the kids endless hours of fun and does come up with some nice looks (which I sometimes then save as a scene).
In the Alexa app I then added scenes to my room groups and renamed things to require more natural utterances. For example, "Alexa activate sofa cosy" would indeed activate the 'sofa cosy' scene but as a human all you really want is cosy lights while you're sitting down on the sofa, so Alexa now knows this as just 'cosy'.
There is some juggling of scene names required to ensure similar scenes in different rooms can be requested correctly. Some scene names also seemed to clash with built in Alexa 'magic' where she tries to change colours at the same time as recalling your scene - names like 'warm' seem to be particularly prone to this. The challenge has become remembering what various scenes are called in each room!
With a pleasingly small amount of trial and error I've now got Alexa activating both Home Assistant and Hue scenes accurately, she can change light colours where it's supported and even "Alexa, dim the lights" works a treat - again, all thanks to Home Assistant!
Switch Guards
With smart lighting extensively deployed as a retrofit into existing light fittings with regular light switches, I needed a way to ensure those light switches remain switched on.
The solution was simple - little 3D printed plastic barriers from eBay, which came white and I spray-painted as needed. These also let you operate the switch underneath in an emergency; perhaps the Hue Bridge or Home Assistant has failed - turning a Hue light on at the mains switch always brings it on in a default state so you can at least see.
Conclusion
The Philips Hue system and its Home Assistant integration gives you a hugely flexible system for controlling your home's lighting. The integration is a toolkit of parts, there are many ways to achieve the same thing and the 'right' solution for you will depend on many factors including what lights and accessories you have. Extending this into the world of Alexa with the Home Assistant cloud is the icing on the cake.
Personally, I love it, and I'm off to buy as many more Hue lights as I can. When's the next sale..?
Commenti