[Release] Advanced Hue Bridge Integration

I present for your use, my new Advance Hue Bridge Integration for integrating the Philips Hue hub with the Hubitat Elevation hub.

Download from GitHub, or install it through the Hubitat Package Manager application and be kept updated on my changes as they are published.

Overview

This project is the result of a desire to expose features and capabilities not yet available in the built-in Hue Bridge provided by Hubitat. The initial goal of this project was to provide support for Hue features that were not already available. I was not able to activate scenes, and dimmer control from HE was poor behaving at best. Capturing state was difficult, since HE could fall out of sync with Hue, and this could lead to capturing the wrong state. And since the HE integration does not support per-device, or per-group refresh, attempting to refresh the state of a single bulb, or group was time consuming.

Objectives

  • Use built-in Generic Component drivers wherever possible
  • Support for refresh by Bulb
  • Support for refresh by Group
  • Support for Hue Scenes
  • Support for start/stop level change
  • Proactive devices state updates
    • When a scene is active, refresh the state of all affected rooms, zones, and bulbs
    • When a group is modified, refresh the state of all member bulbs, and impact zones
  • Avoid network saturation
    • Any refresh, cancels and reschedules the auto-refresh
    • Multiple stacked refresh commands are reduced to just one.
    • A forced refresh is scheduled to run after a slight delay, making canceling the refresh possible.

Implementation Goals
I created this driver to satisfy some automation desires. It is currently being used as my only Hue integration.

  • Want to transition to scenes organically, with all hue bulbs at once.
  • Want to fix HE scene transition limitation of one bulb / group at a time.
  • Want to be able to use a Z-Wave dimmer to control dimming level of Hue Bulbs/Groups
    • The dimmer should feel natural
    • While holding up / down, the bulb should smoothly transition up / down
    • When releasing the dimmer, the bulb transitioning should stop immediately
  • Want to be able to issue a refresh, then wait for refresh to complete in RM before executing next action
    • This feature could make it possible to refresh a bulb/group, wait for refresh to complete, then capture state of the bulb/group
  • Want to define any refresh interval I desire, rather than being locked into a pre-defined list of intervals.

Advanced Hue Bridge Integration Application
The application is the backbone of the Hue bridge integration. All of the Hue API calls are through the app. This app was made to mimic the built-in Hue integration wherever possible.

Use the app to find, and link to your Hue Bridge. Once linked, the app makes it easy to add your Hue Zones and Rooms as Groups, your Hue Scenes as child devices to your Groups, and your Hue Bulbs.

AdvancedHueBridge Device
This device requires the Advanced Hue Bridge Integration application to work. It is created by the parent application after linking to your Hue Bridge. This device functions as the All On/All Off switch for all of your Hue lights, as well as the scheduled coordinator for hub refresh events.

AdvancedHueGroup Device
This device requires the Advanced Hue Bridge Integration application to work. It is created by the parent application. This device serves as the Scene device container. The goal of this project was to avoid custom drivers were possible, however, for management of scenes, it was decided that it would be more manageable to create scenes as a child device of the groups to avoid naming conflicts, and make to keep the scenes with the groups that they are defined in Hue as. This device emulates an RGBW bulb, with configurable refresh schedules, and on-demand refresh though the refresh command.

Scenes and Bulbs Generic Component Devices
To implement the Scenes, I use a Generic Component Switch, that I have programmed to behave as a momentary switch. Since Hue does not maintain state for Scenes, neither do I. I do not try to guess which scene(s) is(are) active. If you command the scene on, the state will change to on after confirming the Hue Bridge received the request, then it will change back to off state after a few moments.
To implement the Hue Bulbs, I parse each device type in Hue, and match that device type, based on capabilities, to the best matching Generic Component device. I do not have all the different types of bulbs that Hue offers, but I do have some color bulbs, spot floods, CT bulbs, and GE+Link dimmers, so I have enough to ensure basic functionality is correct.

Advanced Hue Dimmer Sensor Device
Advanced Hue Tap Sensor Device
Advanced Hue Motion Sensor Device
Advanced Hue Light Sensor Device
Advanced Hue Temperature Sensor Device
These sensor drivers only work effectively if used with the new Hue Push notifications. The Motion, Light, and Temperature sensors can be used in polling mode if so desired. The Dimmer, and Tap button devices cannot be used in polling mode due to the nature of the devices. If any of these sensors are added to Hue without assigning to a room or zone, then Hubitat can use the devices just like any other push button devices. If assigned to a room or zone in the Hue app, the devices can still be used, but the Hue hub will use them to turn lights on/off as well.

The recommended implementation for these devices is to associate them with rooms or zones, and let Hue use them to manage the target grouped devices in the Hue app, and to use the Hubitat to monitor and supplement the Hue features.

All sensor devices are included in Hubitat Package Manager as optional devices. Be sure to install them if you wish to use them. You only need to install the ones you want to use.

Limitations
The Hue hub API is a very responsive system with constantly growing capabilities. The hardware in the Hue hub is rather slow however. The Developer's documentation states that The Hue hub is only capable of changing the state of 1 Group Per Second, or 10 Device Per Second . Anything more will likely result in queue of requests. This applies to all hue integrations. Please consider this when adding hue groups/schene/lights to HE rules and groups, and scenes.

I am playing with work-arounds for this, but there is only so much we can do. At present, I have techniques to limit what is sent to Hue when the target device is in the off state, and then queue them with the on event, to handle turning on the target group / light and setting all states with a single command.

As of Version 1.6.1 published on Oct 16, 2021, when installed on hubitat 2.2.9, the refresh schedules now behave differently. This driver now supports experimental push notifications from the Hue hub. That means that when you control a room, or zone (aka, group) or a bulb directly on the hue device, the hue hub will notify my driver of the change. As such, when the event stream connection is open, the refresh will be repurposed as a health check on the event stream, and in the event the stream is down, and cannot be re-established, then a full hub refresh is used as a fall-back mechanism.

Hub push notifications is still experimental, but it is the default behavior now, to ensure a smooth transition, the driver will make all necessary device configuration changes for you upon upgrade, and if that fails, upon save settings call.

Disclaimer
This is a product of my own independent research. All code is entirely created by me, for my network, and my friends' networks. The results of my efforts have proven to meet our needs quite well. There are still some planned updates that are not yet implemented. Your results may differ.

If you find bugs, please submit a bug report on my GitHub project page.
If you would like enhancements, please submit the requests on my GitHub project page.

Enjoy!

21 Likes

For those that use Hue scenes, my implementation was updated today to allow a scene (implemented as a child of a group) to behave as a toggle switch, or a trigger (momentary switch). When operating as a toggle switch, the scene will remain in the on state until turned off. When the group is turned off, any scenes turned on will also be turned off. Only one scene may be in the in state at any one time. Turning on scene 1, then turning on scene 2, will result in scene 1 turning off.
Additionally, when the group is set to control scenes as a witches, another option can be toggled to track state. If track state is turned on, then making a change to the group’s color, level, temp, or other supported attribute, the scene will automatically turn off. If the track state option is off, then the scene will only turn off, if the group turns off, or another scene turns on.
And finally, if a scene is commanded off, then the group will turn off.

The reason for this behavior is to address a unique request: to be able to turn on a group Nd set the scene and be able to turn off the group, from a single button in the dashboard and SharpTools.

1 Like

Great work with the integration. I'm wondering whether it may do what I want, or perhaps you would consider including it.

I want to show a tile on a dashboard with the state of a group, i.e. a switch template showing whether any lights in the group are on or they are all off. When I switch the tile to off I want all the lights in the group to turn off, but when I turn the tile on I want a default scene activated for that group. I setup all my lighting rules on my hue bridge before purchasing my HE hub and have decided to keep them there. As I transition from day to night mode I capture a "current" scene in each room and that is the scene I refer to in all my rules. I would like to activate this scene in each room when I turn the room on.

Any thoughts...?

The group has a setting for Any On or All On. If set to Any On, then the group will report as on if any light in the group is on.

Is this what you are looking for?

That is one part of it, and good to know it can do that. The other part is when turning a group on I would like to activate a scene, rather than simply telling the hue bridge to turn the group on. Is that something you could do?

That one gets complicated. The reason is that there is no state for the scene, I just take a best guess at state assuming hue is managed entirely by HE.

I suppose I can add a setting for this. Check back tomorrow for it. The setting will be a drop-down list where you can pick any Hue scene to activate on power on. (No need to import the scene into HE). This might be a good solution for my buddy’s use case as well. Thanks for the idea!

2 Likes

Yes, I do remember tossing this one around in my head trying to work out how it could work given you want the state of the group represented in the device but turning it on to trigger something, not sure if you can bypass any built in setting of the relevant attributes. The only thing I could think of was to (inside the "on" method) make the call to the hue bridge to activate the scene then shortly after poll for the group state.

There is no easy way. The way I did it is to create a new devices, and to test them to make sure the functionality works correctly. Then when I was ready to bite the bullet, I used the old devices' "In Use By" section to replace every instance of the old device with the new one. Then I verified the new device worked as intended. Once confirmed, I deleted the old device. I made my transition one device at a time.

Understand before switching that my scenes are not HE scenes. HE see them as just regular switch devices. We (a friend and I) did not like how HE managed scenes. Everyone told us I was stupid, and this couldn't be done, and it would look horrible. I figured that managing the hue side of a scene in hue, and managing the non-hue side in HE scenes, then adding my hue scene as a switch to the HE scene would be enough to make the scene transitions seamless, and for us, it works. Also, my Hue devices are not "Hue" devices so far as the Alexa and other Hue aware applications are concerned, so the setting to ignore hue devices in the Alexa integration means nothing when it comes to my system.

But, I think the benefits far outweigh the restrictions. It's a huge risk to convert, so start small. Turn it on for a very small scale to play with and see. With my integration, now that I stopped the built in integration, I setup my Hue Hub to refresh every 5 seconds, and it doesn't seem to impact performance on my C-3 hub and V2 hue hub. I think the key benefit of my system from a performance perspective is that any command of a hue device immediately triggers a full refresh to occur after a 2 second delay (in the future this will be tunable), and cancels in previously scheduled refresh. This means you can command 15 changes w/o invoking 15 refresh events, and within 2 seconds of the last command, a full refresh will kick off keeping your groups (rooms and zones) and their member devices in sync.

One of the really cool things to do is to create a group of two lights. turn the group on, and set to 100% brightness. Now, turn one of the member bulbs down to 50%, within 2 seconds your group with be at 75% brightness -- this is possible because to the optimistic, yet friendly refresh. The way this works, the only reason I still have a 5 second refresh on the hub, is because I have a couple dimmers where I set the dimmer level and on/off state to match the state of the bulbs in hue, so that if I use a hue dimmer to turn on my lights (paired directly to hue), my dimmer will then turn on. This type of automation is not recommended, because you can get caught in an infinite cycle if you aren't careful.

Also, just added, the Hue Groups now allow you to define a default scene. When defined, turning on the group will instead activate the default scene, which in turn will turn on the group.

Plus you have the ability to activate any scene for a group, even if you don't import it, by entering the scene name (or number) and clicking on Activate Scene. This is nice for rules, if you want to activate scenes using Custom Action, instead of child switch devices.

1 Like

Okay, so this is done, and deployed to HPM. Just enter the scene name, or ID into the "Default Scene" property, and save. Next time you turn on the group, it will activate the scene instead.

1 Like

Wow, thanks so much for a quick turnaround. I'll install it later tonight and let you know how it goes.

I was thinking about it, and couldn't sleep.. better to get that out of my head..

1 Like

I know how you feel...:slightly_smiling_face:

If your still up, I keep getting a nullpointer error when trying to link my bridge, any ideas?

After I press the button on the bridge.

I haven't performed a link in ages. I will try it out and see what it's doing. I have touched that code, but maybe there is a bug that was accidentally added, or a regression due to one of the hub updates. The initial code I wrote over a year ago.. I only just wrapped it up to release it.

The error talks about line 895

Sorry @armand, just saw what time it is for you. No need to stay up later for me, happy for you to look at it later. Thanks again for your effort on this, really appreciated.

Click done, then go back in. after a couple tries the error goes away. I am looking at the code now though, to get to the bottom of it. Thanks.

1 Like

Thanks, I'm happy to play with it for now, perhaps you'll pick it after some sleep :slightly_smiling_face:

I have cocohue installed, I was wondering whether you can't have more than one app from the HE hub linked to the bridge..?

Fixed. The last thing I did recently was to add the lights, and then enhance the groups. The new light parser was being called while the hub device was being created. This lead to code parsing a state variable that was not yet defined. Only happens on new hub additions. I fixed that logic, and it works now.

Yes. Provided the device Network IDs are different. Hue can link to many devices at once. Hue has a limit of one (1) group update per second, and ten (10) bulb updates per second. More than that, and commands start queueing up on the Hub Hub -- according to their API documentation. So take care to not overload the hub.

As for CocoHue, I only just heard of it after adding mine. I am not familiar with it at all. I created mine for some very specific reasons, as listed at the top of the topic. I have been enhancing it since, and I just felt it was time to set it free, and see if I can get feedback for enhancements. Now that my Roku connect app is settling in quite well, I figured by pushing this out, I can see how it does. I certainly does not hurt my feeling if you choose not to use it. The whole point of these systems is choice, and customization.

On that note, I don't want to copy anyone's ideas from another system. I am happy to provide similar features, but what I implement is coded 100% from my head.. as rusty as some of it may be these days.. :slight_smile:
Play with it, and let me know what you think.

1 Like

I'm up and running, got past the error linking the bridge and starting to play with the groups. Not quite getting the scene change working, but I'll spend more time playing with it and let you know how I go.

Thanks again for taking the time to look at this for me