jason0x43 / hacs-hubitat

A Hubitat integration for Home Assistant
MIT License
199 stars 47 forks source link

RGB to CT transition not updating in Home Assistant #72

Closed DanielWinks closed 3 years ago

DanielWinks commented 4 years ago

I've got 5 Inovelli Ilumin bulbs connected to Hubitat in a group. This is exposed to Home Assistant via the Maker API and this integration.

Everything works for the most part, but unlike when these bulbs were connected using Zwave2MQTT or qt-OZW, transitioning from RGB to CT mode doesn't update properly.

So what happens is this:

I click on my light, change the temp with RGB at 0,0,0 (in the center of the color picker). I can move cooler/warmer, everything works.

I can then click anywhere on the color wheel, switching the bulbs from CT to RGB mode in Hubitat and selecting that color. Again, this works, click red, lights turn red, blue and they're blue, etc.

Now, if I click back on the color temp slider the bulbs go back to CT mode in Hubitat and switch to that color temp... The RGB color picker however stays where it was at last, and the bulb icon in Home Assistant remains colored. When doing the same actions with either Zwave2MQTT or qt-OZW, if the bulbs were blue and I click on the color temp slider, the RGB color picker moves back to the center (0,0,0) and the bulb icon in Home Assistant turns to the non-RGB yellow color.

Am I missing some sort of setting somewhere to fix this? Is this known behavior? Is it how it's supposed to work?

It's a bit jarring seeing a bunch of colored bulb icons in Home Assistant when everything is actually set to "2700K incandescent white". I can work around this by manually issuing a RGB to center (0,0,0) transition by clicking in the center of the color wheel prior to selecting a color temp, but this is definitely less than ideal.

jason0x43 commented 4 years ago

No, that doesn't sound right. I just don't have any RGB + CT bulbs accessible through Hubitat (I have Hues, but the Hue hub talks directly to HA), so it's never come up before. 😄

If possible, could you enable debug logging for the Hubitat integration, change colors (between CT and RGB) with your bulbs, and post the resulting messages that show up in the HA log?

DanielWinks commented 4 years ago

Red RGB to 2700K CT: https://pastebin.com/AXL1heJ0

From 2700K to 0,0,0 RGB (prior to this click it was still showing as red on the color wheel, light itself was 2700K): https://pastebin.com/4WJnKBNe

From 0,0,0 RGB and 2700K to 6500K: https://pastebin.com/eT8PaWEN

From 2700K to 255,0,0 RGB: https://pastebin.com/ACQZpmh0

Let me know if you need any other color change combos.

jason0x43 commented 4 years ago

Thanks! I just published v0.5.9. Give that a try and see if the lights behave any better.

DanielWinks commented 4 years ago

No difference I could tell. I did notice I get this error sometimes as well:

Logger: homeassistant.components.websocket_api.http.connection.140021319105312
Source: custom_components/hubitat/device.py:253
Integration: Home Assistant WebSocket API (documentation, issues)
First occurred: 8:46:40 AM (3 occurrences)
Last logged: 8:47:10 AM

0, message='Attempt to decode JSON with unexpected mimetype: text/html;charset=utf-8', url=URL('http://192.168.3.3/apps/api/68/devices/265/on?access_token=xxxxxxxxxxxxxxxxxxxxxxxxxxx')
0, message='Attempt to decode JSON with unexpected mimetype: text/html;charset=utf-8', url=URL('http://192.168.3.3/apps/api/68/devices/265/setLevel/10?access_token=xxxxxxxxxxxxxxxxxxxxxxxxxxx')
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 137, in handle_call_service
    await hass.services.async_call(
  File "/usr/src/homeassistant/homeassistant/core.py", line 1315, in async_call
    task.result()
  File "/usr/src/homeassistant/homeassistant/core.py", line 1350, in _execute_service
    await handler.func(service_call)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 204, in handle_service
    await self.hass.helpers.service.entity_service_call(
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 459, in entity_service_call
    future.result()  # pop exception if have
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 655, in async_request_call
    await coro
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 490, in _handle_entity_call
    await result
  File "/usr/src/homeassistant/homeassistant/components/light/__init__.py", line 249, in async_handle_light_on_service
    await light.async_turn_on(**params)
  File "/config/custom_components/hubitat/light.py", line 172, in async_turn_on
    await self.send_command(CMD_ON)
  File "/config/custom_components/hubitat/device.py", line 389, in send_command
    await self._hub.send_command(self.device_id, command, arg)
  File "/config/custom_components/hubitat/device.py", line 253, in send_command
    await self._hub.send_command(device_id, command, arg)
  File "/usr/local/lib/python3.8/site-packages/hubitatmaker/hub.py", line 139, in send_command
    return await self._api_request(path)
  File "/usr/local/lib/python3.8/site-packages/hubitatmaker/hub.py", line 248, in _api_request
    json = await resp.json()
  File "/usr/local/lib/python3.8/site-packages/aiohttp/client_reqrep.py", line 1026, in json
    raise ContentTypeError(
aiohttp.client_exceptions.ContentTypeError: 0, message='Attempt to decode JSON with unexpected mimetype: text/html;charset=utf-8', url=URL('http://192.168.3.3/apps/api/68/devices/265/on?access_token=xxxxxxxxxxxxxxxxxxxxxxxxxxx')
DanielWinks commented 4 years ago

So I get the above JSON error repeatedly whenever I click around in the color wheel. Seems to pop up every couple clicks. Seems to pop up more often if I click between colors more quickly, too.

jason0x43 commented 4 years ago

Hmmm...that implies that commands are failing (well, that Hubitat is rejecting them). Could you try sending commands from a command line, like:

$ curl 'http://192.168.3.3/apps/api/68/devices/265/on?access_token=xxxxxxxxxxxxxxxxxxxxxxxxxxx'

Do that a few times and see what kind of response you get. Ideally, you should get a JSON message back. If you're getting HTML, which seems to be the case, there should be an error message in there somewhere.

DanielWinks commented 4 years ago

I'm just getting JSON. If I put the exact URL from the logs that states it got back html I'm also just seeing JSON returned. All are 200 OK.

jason0x43 commented 4 years ago

Ok, that's something. If you add a -vv to the curl command, you should see headers. Is the Content-Type set to application/json?

DanielWinks commented 4 years ago

I tossed this into Postman. It's definitely JSON every time.

I fired up a bash script and had it do curl a few times in rapid succession. Everything was JSON. I ran a couple copies of this script simultaneously, all JSON.

DanielWinks commented 4 years ago

Also, some feedback on the recent update you made. So on v0.5.9 when I'm on CT mode and select Red, the bulb changes as expected, and the color wheel goes back to the center and the bulb icon in Home Assistant remains the usual "yellow/on" color. If I revert back to v0.5.8 and go from CT mode to Red RGB then the bulb itself changes as expected AND the icon in Home Assistant turns red and the color wheel selection dot remains at the point I clicked (on red).

So basically 0.5.9 makes it go back to 0,0,0 in the color wheel right after selecting an RGB color, rather than after selecting a CT color.

jason0x43 commented 4 years ago

Hmmm...ok, I'll have to look into that a bit more. The change in 0.5.9 was to have the integration pay attention to the color mode (it wasn't before), and only report color or color temp if the light was in the right mode (RGB or CT). So in theory, when you're in CT and select an RGB color, the color mode should change to RGB (which appears to be the case in the logs you posted), and the light should only report a hue-sat color, and not a color temp. It sounds like that's not working quite like I expected, though.

DanielWinks commented 4 years ago

So I just got a bit to look through what you changed here and noticed that you referenced constants in the hubitatmaker package, which was updated at the same time. It looks like those updates aren't in Home Assistant, so my install was failing when attempting to reference them. I replaced these constants with "RGB" and "CT" to work around my version of hubitatmaker lacking them and everything is working now. I'd expect the changes you made to work properly once the version of hubitatmaker is updated.

DanielWinks commented 4 years ago

Also, if I use [0, 0] instead of None here, the color wheel immediately returns to center when changing to CT mode. Using None also works, but it requires closing the light dialog before it updates.

@property
    def hs_color(self) -> Optional[List[float]]:
        """Return the hue and saturation color value [float, float]."""
        mode = self._color_mode
        if mode and mode != "RGB":
            return [0, 0]
DanielWinks commented 4 years ago

Still getting some random Attempt to decode JSON with unexpected mimetype messages. What can I do to have the debug logs output what it's trying to decode? I can't get it to display anything other than JSON via curl/postman. Is there somewhere I can toss a log command in the python temporarily to log these errors?

jason0x43 commented 4 years ago

In /usr/local/lib/python3.8/site-packages/hubitatmaker/hub.py around line 248, insert a call to log the text content, like:

if resp.status >= 400:
    if resp.status == 401:
        raise InvalidToken()
    else:
        raise RequestError(resp)

# Read response as text rather than JSON
text = await resp.text()
_LOGGER.debug("Got response: %s", text)

# Use Python's json.loads to parse JSON from the text content.
# You'll need to add an "import json" at the top of this file.
json = json.loads(text)
# json = await resp.json()

if "error" in json and json["error"]:
    raise RequestError(resp)
return json
jason0x43 commented 3 years ago

Any update?

DanielWinks commented 3 years ago

Sorry, no. I ended up just moving everything back to Zwave2MQTT to avoid further troubles. My Hubitat C-7 had all sorts of other Z-wave issues. I had hopes it'd be more responsive than Zwave2MQTT (which can be a bit laggy when sending multiple commands quickly), but the Hubitat was way way worse. I had to "stop changing the lights" or household grief would have ensued...

Your GitHub says "Ohio"... if that's CBus, I have some extra RGBW bulbs, so I could get you one if you want to have one for fixing this. Or if you just want to close, that's fine with me, as I'm not currently using the Hubitat.

jason0x43 commented 3 years ago

I had to "stop changing the lights" or household grief would have ensued...

I know that feeling 😆

Your GitHub says "Ohio"...

Dayton, so not super far. I'll close this for now, but we can certainly reopen it if comes up again in the future.