Challenge: Create a template light with a Hue color light group

I am trying to create a template light that will copy/control the state of a Hue light group.

This is easy enough to do with Hue white lights (working example below). What I don’t know is how to do with with Hue color changing lights. I’m sure I will need to use color_template: and set_color: - I just don’t know how. Can anyone help?

  - platform: template
    lights:
      office_lights:
        friendly_name: "Office Lights"
        value_template: '{{ states("light.office") }}'
        turn_on:
          - service: light.turn_on
            entity_id: light.office
        turn_off:
          - service: light.turn_off
            entity_id: light.office

Not sure I understand your goal. The Philips Hue integration renders Hue light groups as light entities. Why would you also need to control them via a Template Switch?

Hi @123! I know, it sounds stupid. It’s really a workaround for a different issue.

I am passing the Hue groups and lights to HomeKit via a UI configured HomeKit Bridge. It works great 99% of the time. But once every couple of weeks, all of my Hue groups forget their room assignments in the Home app. Sometimes they are even totally missing until I reload the HomeKit Bridge integration or restart HA. The Hue lights are fine; only the groups have this issue.

SOOO… My idea was to create template lights for the Hue groups, and pass them into HomeKit rather than passing the groups directly. This way if the Hue integration has a temporary hiccup, I won’t lose all of my devices in HomeKit.

I’m unfamiliar with HomeKit Bridge. Is it like the HomeKit integration which makes Home Assistant’s entities appear as HomeKit accessories?

Multiple Hue lights → combined as a Hue light group → converted by Philips Hue integration → to a light entity → converted by HomeKit integration → to a HomeKit light accessory

I can’t say I have experienced any problems with it.

Yes, that is exactly what I am referring to. HomeKit Bridge

The issue just started recently for me. I’m not sure if it is something with the Hue integration or with my setup. But when an entity is missing - even if only temporarily - HomeKit seems to lose all memory of it. That’s why I was thinking I would create a set of template lights which will always be there. I’m sure there is a much better way to approach this, but it is beyond me.

Sheesh! There appear to be two different schools of thought regarding what to call this integration! The documentation’s title and the code’s manifest file refer to it as the HomeKit integration (which is the moniker I’m familiar with) but elsewhere it’s the HomeKit Bridge integration. :man_shrugging:

I imagine HomeKit Bridge helps to differentiate it from HomeKit Controller.

OK, back to your Template Switch. Before you delve into color_template, when the glitch, that you described, occurs does the Template Switch work as expected (meaning does the HomeKit Bridge continue to render it as a functional HomeKit accessory)? In other words, is this workaround successful?

Just to make sure we’re on the same page, I was planning to use template light rather than template switch. But to answer your question - I don’t know yet if it would work. It was an idea I wanted to try.

Another thing I might try first is switching to a yaml config rather than a UI config. Just to rule out the UI.

I think you might be right. That is always a source of confusion. I think the bridge nomenclature might have been introduced along with the ability to configure it in the UI.

Yes, it would be a Template Light.

Before tackling a Template Light, I would confirm the Template Switch is functional when the HomeKit Bridge hiccup occurs. If it fails to work, you will have saved time creating the more complex Template Light.

I have some Hue groups that are plain white lights, so I’ll give that a try with a simple template light first. If it does work, expect me to bug you for help with a more complicated color one! :grin:

Hey @123, remember this thread? Six months later, I finally figured it out!

Quick review:
Problem: Hue light groups (native from the Hue Bridge) do not have a unique ID in HA. When passing them through to HomeKit sometimes they temporarily disappear and reappear, which causes HomeKit to lose all room assignments.

Original (dumb) idea: Create a template light as a layer on top of the Hue light group, and pass the template light into HomeKit. Even if the native Hue groups disappeared, the template light would still exist and not cause HomeKit to lose the room assignments. The issue with that was that I then lost the ability to change colors and brightness. It was a simple on/off.

Solution: Today I learned that HA has its own Light Groups! I can ignore the Hue native light groups and then group the individual lights into new HA light groups. Then I pass the HA light group into HomeKit.

Super simple; I just didn’t know it was an option!

So instead of this:

light:
  - platform: template
    lights:
      office_lights:
        friendly_name: "Office Lights"
        value_template: '{{ states("light.office") }}'  # <------- Hue group
        turn_on:
          - service: light.turn_on
            entity_id: light.office
        turn_off:
          - service: light.turn_off
            entity_id: light.office

I am now using this:

light:
  - platform: group
    name: Office Lights
    entities:
      - light.office_hue_light_1
      - light.office_hue_light_2

As long as you understand that a Home Assistant Light Group doesn’t work the same way as a Philips Hue Group. The end-result may appear to be similar but, under the hood, they don’t use the same technique to achieve it.

  • A Hue group uses Zigbee’s native group feature. A single command can control the operation of all group members. The command is received at the same time by all members.

  • A Light Group sends separate commands to each group member. They receive it in the order the commands are transmitted.

  • If there are ten members in a group, a Light Group generates ten times the Zigbee traffic compared to a Hue Group.

1 Like

Thanks for the info. I suspected that would be the case, and you confirmed. But it shouldn’t be a big deal. All automations run through HA and use the Hue groups.

Since we are an Apple device family I just needed a way to display the groups in HomeKit as individual lights. In HomeKit, they will rarely be used.

I could pass in the individual lights and then group them in the Home app, but I much prefer to pass in one HA light group.