home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
72.67k stars 30.42k forks source link

Loss of HomeKit control of white channel of RGBW light #65529

Closed Tugzrida closed 2 years ago

Tugzrida commented 2 years ago

The problem

After updating to 2022.2.0, I can't seem to control the white channel of an ESPHome light via HomeKit.

My use case is an RGBW LED strip connected via ESPHome, and as the strip has separate white and RGB chips, it looks weird if both are illuminated at the same time. Hence, separate RGB and White colour modes make the most sense for the light.

Achieving these separate colour modes in ESPHome is done via the color_interlock: true option, however I wasn't previously using this as it didn't allow me to control the white channel via HomeKit, so I left it in the combined RGBW mode.

The behaviour I was seeing via HomeKit with HA <= 2021.12.10 (with ESPHome in the combined RGBW mode) was as follows:

Now in HA 2022.2.0, any colour choice(including white) I make in HomeKit is only rendered with the RGB chips. I have tried this with the ESPHome light set in both the combined RGBW and separate RGB+White modes and experience the same behaviour via HomeKit regardless.


From the changelog, and the fact that I can still control the white channel from Lovelace, it seems likely this change in behaviour is related to the HomeKit integration, specifically the changes in #63948

I am aware that HomeKit has rather limited colour modes and capabilities, but as a suggestion, I think that adding a special case for RGB+White lights to switch to the White mode when the HomeKit commanded colour is exactly white would be fairly reasonable. When asking Siri to make a light white, I imagine most users would expect only the white channel of the light to be used.

For combined RGBW lights, I think the pre-2022.2 behaviour I described above makes sense. In my opinion, the current behaviour is also not ideal here as there is an attribute of the device that can't be controlled via HomeKit.

What version of Home Assistant Core has the issue?

core-2022.2.0

What was the last working version of Home Assistant Core?

core-2021.12.10

What type of installation are you running?

Home Assistant Container

Integration causing the issue

HomeKit

Link to integration documentation on our website

https://www.home-assistant.io/integrations/homekit/

Example YAML snippet

No response

Anything in the logs that might be useful for us?

No response

Additional information

No response

probot-home-assistant[bot] commented 2 years ago

homekit documentation homekit source (message by IssueLinks)

probot-home-assistant[bot] commented 2 years ago

Hey there @bdraco, mind taking a look at this issue as it has been labeled with an integration (homekit) you are listed as a code owner for? Thanks! (message by CodeOwnersMention)

bdraco commented 2 years ago

There was a bug fix where white channel control was unexpectedly happening when an HS color was set in HomeKit that was fixed in 2022.2

HomeKit only has support for controlling HS color or Temp. White channels are not indented to be controlled via HS color.

Currently the device needs to support color temperature for HomeKit to be able to control the white channels.

It sounds like that bug was a feature for you. Unfortunately it was not intentional behavior.

You may be able to get white control back by adding color temp support to your esphome device with a single temperature

Tugzrida commented 2 years ago

Thanks for the info @bdraco

I've spent quite a while this morning trying all the options of the RGBWW and RGBCT ESPHome profiles, and I was able to achieve control of the white channel through the Temperature tab of the Home app, however when using Siri to "make the strip white" or using a preset in the Home app colour picker, it did not use the white profile and just mixed white with the RGB LEDs.

It really does seem like there needs to be a special case if homeKitSaturation == 0: setColor(0, 0, 0, 255) for it to work the way I would expect. That sounds like something I might be able to achieve with an automation, but that seems like it could be a bit janky. I'll see how I go.

bdraco commented 2 years ago

Sadly light support in HomeKit is a bit limited, especially with siris. Hopefully Apple adds proper RGBW/RGBWW support in the future.

The current specs even disallows color temp support when color support is present but even certified devices do it... so we do as well.

We explored adding additional services to the light accessory in the past for more control but it didn't go over well and we had to remove them since it made the ui require two touches to control it wasn't received well.

Tugzrida commented 2 years ago

I can see why the multiple accessories option didn't go down well. I guess it's just about choosing which type of imperfect behaviour is more tolerable.

I've been able to get the behaviour I want with ESPHome set for RGBW with color_interlock: true (which creates a light with separate RGB and White profiles), plus this HA automation:

alias: Window Strip HomeKit White
trigger:
  - platform: state
    entity_id: light.window_strip
    attribute: rgb_color
condition:
  - condition: template
    value_template: '{{ state_attr("light.window_strip", "rgb_color") == (255, 255, 255) }}'
action:
  - service: light.turn_on
    data:
      white: '{{ state_attr("light.window_strip", "brightness") }}'
    target:
      entity_id: light.window_strip
mode: single

Needing an automation like this for every light is obviously not ideal, though in my case I only have the one light. I'm sure in the case of ESPHome it could also be done on the ESPHome side, but that can be my project for another day.

It also feels like this could be built in to the HomeKit integration, though I suppose it might not work well with all devices, so I understand if that's not something you want to do.

bdraco commented 2 years ago

This one is particularly difficult to figure out how to get working with HomeKit. I think the color temp characteristic might be tolerate a fixed value to allow controlling the W brightness so that might be one possible solution.

Unfortunately every HomeKit change seems to break someone's workflow so I'm almost afraid to make any changes since the system is so inflexible on how the accessory is presented.

bdraco commented 2 years ago

I gave it a shot, but since I don't have an esphome device without color temp support to test with I have no idea if it works

I uploaded the changes here if you want to give it a try

mkdir /config/custom_components
cd /config/custom_components
git clone https://github.com/bdraco/homekit

restart

bdraco commented 2 years ago

I ordered a few devices I can flash with esphome for testing. They are coming from China so it might be a while before they show up

bdraco commented 2 years ago

@Tugzrida

I managed to flash an old tuya device I had lying around for testing and I pushed up changes to that repo.

Please make sure you try it with 2022.2.2 or later.

The last commit should be

Author: J. Nick Koston <nick@koston.org>
Date:   Fri Feb 4 16:54:40 2022 -0600

    fixes
Tugzrida commented 2 years ago

Thanks so much @bdraco

Apologies, as I did see your post mentioning the patch, but I became fairly busy yesterday afternoon. I should be able to try it within the next few hours.

Tugzrida commented 2 years ago

Ok, with bdraco/homekit@9158e1e29acceac21e80fbcf95829297ea52a1da, this is the behaviour I'm seeing

bdraco commented 2 years ago

How are you selecting the color?

Are you using the temperature tab?

Tugzrida commented 2 years ago

I tried Siri, the colour tab, and the temperature tab.

In RGBW mode, selections from both the colour and temperature tabs were rendered as a mix of RGB and white unless the selection was a pure colour or pure white(which was at the centre of the colour wheel, and at about the 10 and 2 o'clock positions of the temperature circle)

In RGB+White mode, the white LEDs didn't activate for any selection from Siri, the colour tab, or the temperature tab

bdraco commented 2 years ago

I'll do some more testing to see if I can improve it with color_interlock: true

bdraco commented 2 years ago

Please pull again and restart

It should be at

commit 41f97dd4a33846a8d4cfd6e6d731aabbaa085864 (HEAD -> master, origin/master, origin/HEAD)
Author: J. Nick Koston <nick@koston.org>
Date:   Fri Feb 4 18:46:07 2022 -0600

    Make homekit aware of white attr
Tugzrida commented 2 years ago

It's now showing a plain white ring for the temperature selection, which sets the white LEDs as expected.

It however only uses the RGB LEDs when choosing white in the Home app from a preset without opening the colour picker, or asking Siri for white. It seems that the presets and Siri will only set it as a colour, even if the requested colour is white, and even if the preset was created from the correctly-behaving temperature tab.

The automation hack I made handled this behaviour as it forces the selection of white as a colour to the white mode.

bdraco commented 2 years ago

It however only uses the RGB LEDs when choosing white in the Home app from a preset without opening the colour picker, or asking Siri for white. It seems that the presets and Siri will only set it as a colour, even if the requested colour is white, and even if the preset was created from the correctly-behaving temperature tab.

Yeah thats expected as the left tab sets HS color and the right tab sets color temp.

If we made the HS color tab set the white value there would be no way to set mix white with the color leds. If the white leds and the white channel are the same color temp, thats probably not a problem, but with the RGB + WARM strips that leaves no way to get a bright white color since you would always get warm.

Tugzrida commented 2 years ago

Ah yes, I had neglected RGB+Warm strips. Perhaps my desired behaviour is best suited for individual implementation in automations given that can be easily altered for each light.

I think your patches are still helpful as they make it possible to control all aspects of the light from HomeKit, even if not via all input methods. Hopefully if Siri and presets are improved in the future, these patches will work perfectly and an automation override in HA or ESPHome won't be necessary.

bdraco commented 2 years ago

@Tugzrida

I pushed up the another set of cleanups.

If everything is still working, I'll work on a PR

Tugzrida commented 2 years ago

With bdraco/homekit@69e55bc8c84d2ad1eed4d3166b26155022e1e427, I'm seeing the same behaviours with color_interlock both on and off:

This means that for RGBW lights, the white channel isn't used in the rendering of less-saturated colours(which HomeKit did do prior to 2022.2). If a light is advertising a combined RGBW mode, that would say to me that it's intended for the white channel to be combined with the RGB and is therefore the correct temperature, but I don't know how common that is among different devices. Either way, just wanted to bring it up in case it wasn't intentional.

Besides that, it works fine 👍🏻

bdraco commented 2 years ago

Sounds like it's working as designed given HomeKit doesn't have a concept of RGBW/RGBWW only HS/Temp

bdraco commented 2 years ago

Thanks for testing.

bdraco commented 2 years ago

@Tugzrida One more commit to try

commit 12a27684d8815ebe53589e04cd7eb8ea2c55eb39 (HEAD -> master, origin/master, origin/HEAD)
Author: J. Nick Koston <nick@koston.org>
Date:   Sat Feb 5 21:13:33 2022 -0600

    one more try
bdraco commented 2 years ago

I tested the following setups. It took a while to assemble all of these devices so hopefully the result is good

DEVICE SUPPORTS HOMEKIT HS HOMEKIT COLOR TEMP TEST SETUP
TEMP   TEMP ESPHOME CCT, MAGIC HOME 0x1C TABLE LAMP
RGB HS  MAGIC HOME 0x33, MAGIC HOME 0xA3 SM16703
HS, TEMP HS TEMP LIFX Lightstrip
RGB, TEMP HS TEMP WIZ COLOR/CCT BULB, MAGIC HOME 0x35, MAGIC HOME 0x07 in RGB/CCT mode
RGB, W HS WHITE MAGIC HOME 0x44, ESPHOME RGBW with color_interlock: true
RGBW MIXED - 2 WHITE MAGIC HOME 0x04, MAGIC HOME 0x06 in RGB&W mode , ESPHOME RGBW
RGBW, W MIXED - 2 WHITE MAGIC HOME 0x06 in RGB&W mode (modified to add W)
RGBW, TEMP MIXED - 2 TEMP MAGIC HOME 0xA3 SK6812RGBW, MAGIC HOME 0x04 w/WARM STRIP
RGBW, W, TEMP MIXED - 2 TEMP MAGIC HOME 0xA3 SK6812RGBW (modified to add W)
RGBWW MIXED - 3 TEMP MAGIC HOME 0x07 in RGBWW mode, ESPHOME RGBWW
RGBWW, TEMP MIXED - 3 TEMP MAGIC HOME 0x07 in RGBWW mode
RGBWW, W, TEMP MIXED - 3 TEMP MAGIC HOME 0x07 in RGBWW mode (modified to add W)
Tugzrida commented 2 years ago

Behaviour is the same with color_interlock: true/RGB+W: the Colour/Temperature tabs only control the RGB/White LEDs respectively

With color_interlock: false/RGBW, the Color tab is back to the pre-2022.2 mixing behaviour. The Temperature tab only controls the white LEDs

Also tested a RGB+Temp light I have and it works as expected too.

Thanks for all your effort on this 😄

niorko commented 2 years ago

I have some RGB+CW light bulbs from Tuya and I also miss the "Bug" that was a feature for me.

I could try your improvements @bdraco. Is there any way to test it without removing the old HA integration? I am using HA integration with custom configuration.yaml on HASS system.

When I add your custom fork to integrations, how my configuration.yaml choose the right instance of the HA?

Thanks a lot, that's great news!

bdraco commented 2 years ago

Is there any way to test it without removing the old HA integration?

Follow the instructions here https://github.com/home-assistant/core/issues/65529#issuecomment-1029716422

When you are done delete the custom one and restart again to get the core one back

bdraco commented 2 years ago

After installing the repo, check that the last commit is this one with git log -1, if not run git pull

# git log -1
commit ea5078a87e1270ee3a571b2efa16b5b6711b6a2d (HEAD -> master, origin/master, origin/HEAD)
Author: J. Nick Koston <nick@koston.org>
Date:   Sun Feb 6 12:40:56 2022 -0600

    small fixes for changing color mode

cc @Tugzrida There were a few more fixes since yesterday. They shouldn't change the overall behavior besides fixing the brightness reporting.

niorko commented 2 years ago

It is working great (on https://github.com/bdraco/homekit/commit/ea5078a87e1270ee3a571b2efa16b5b6711b6a2d) :) the Temperature tab can set the correct color for these light bulbs:

Vendor: JunYu Model: ZB-RGBCW

But, Siri still sets the white color as RGB value, not as a 'temperature' color.

I am thinking about somehow translating the white spectrum on RGB mode to use white LEDs in case of white shades. Wouldn't it be a better idea to have only Color mode with RGBW bulbs and translating white colors into 'temperature' colors? Just an idea...

Anyway, great work and thanks.

bdraco commented 2 years ago

@niorko Which color modes are available on that light entity?

niorko commented 2 years ago

I could enable verbose debugging or something like that, but I would have to dig deeper on how to do it or where to look.

Can you please tell me on how to check color modes?

This might not be what you want, but I quickly dump some diagnostic info from that entity:

"23": {
  "colorcapabilities": 31,
  "ctmax": 500,
  "ctmin": 153,
  "etag": "62e30238bfe19415b8872860ef729167",
  "hascolor": true,
  "lastannounced": "2022-02-05T17:13:12Z",
  "lastseen": "2022-02-06T19:53Z",
  "manufacturername": "JunYu",
  "modelid": "ZB-RGBCW",
  "name": "Office standing light",
  "state": {
    "alert": null,
    "bri": 23,
    "colormode": "ct",
    "ct": 485,
    "effect": "none",
    "hue": 34816,
    "on": true,
    "reachable": true,
    "sat": 18,
    "xy": [
      0.323,
      0.329
    ]
  },
  "swversion": "2.0.1",
  "type": "Extended color light",
  "uniqueid": "00:12:4b:00:23:44:05:3d-01",
  "attr": {
    "colorcapabilities": 31,
    "ctmax": 500,
    "ctmin": 153,
    "id": "23",
    "lastannounced": "2022-02-05T17:13:12Z",
    "lastseen": "2022-02-06T20:26Z",
    "manufacturername": "JunYu",
    "modelid": "ZB-RGBCW",
    "name": "Office standing light",
    "swversion": "2.0.1",
    "type": "Extended color light",
    "uniqueid": "00:12:4b:00:23:44:05:3d-01"
  },
  "e": "changed",
  "id": "23",
  "r": "lights",
  "t": "event"
}

Edit: It might be it :)

min_mireds: 153
max_mireds: 500
effect_list:
  - colorloop
supported_color_modes:
  - color_temp
  - hs
  - xy
color_mode: color_temp
brightness: 23
color_temp: 485
hs_color:
  - 30.336
  - 91.331
rgb_color:
  - 255
  - 139
  - 22
xy_color:
  - 0.593
  - 0.384
is_deconz_group: false
friendly_name: Office standing light
supported_features: 44
bdraco commented 2 years ago

I am thinking about somehow translating the white spectrum on RGB mode to use white LEDs in case of white shades. Wouldn't it be a better idea to have only Color mode with RGBW bulbs and translating white colors into 'temperature' colors?

That is achieved in the linked PR if the device supports rgbw.

Unfortunately it looks like your device doesn't support rgbw only color_temp, hs, and xy.

niorko commented 2 years ago

But still, it would be possible to do it somehow. Using color_temp when rgb color is in a realm of white (warm of cold) otherwise use hs mode. Maybe I will try to find some time to do a prototype next weekend. This would really simplify my smart home life - to be able to use this bulbs fully with Siri.

Edit1:

Screenshot 2022-02-06 at 21 58 45

It woudl require to determine, if the value is within this range with certain threshold and if so, automatically switching to color_temp. Maybe...

Edit2: Next time I will be more cautious when ordering smart bulbs - to have rgbw support :(

Edit3: It might not be as hard as I thought. There is a function to convert Kelvin to RGB. I can just check, whether the desired color is in range let's say 2700-6500K (majority of those smart bulbs) and if it is, than use the color_temp.

bdraco commented 2 years ago

It is definitely possible, but realistically its better to get a device that supports it natively since we couldn't accept a change to do it in HomeKit because it would break the other use cases.

Tugzrida commented 2 years ago

cc @Tugzrida There were a few more fixes since yesterday. They shouldn't change the overall behavior besides fixing the brightness reporting.

Thanks @bdraco. That commit behaves the same for me.

@niorko it is difficult to fix in the HomeKit integration as @bdraco mentions, because the behaviour needs to be slightly different depending on the exact characteristics of the light. At the core, it's a bug with how Siri controls HomeKit devices: it always sets a HS colour even when asking for a temperature. Even if I ask it to set a HS+CT light of mine to cool white, it sets it to an HS cool white. You might be able to devise an automation similar to mine here, though to account for a range of colour temperatures instead of just white exactly will be quite harder.

bdraco commented 2 years ago

2022.2.3 is publishing now, after upgrading you should be able to remove the custom version