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
74.02k stars 31.05k forks source link

Unable to add Philips Hue Bridge #125546

Open skenmy opened 2 months ago

skenmy commented 2 months ago

The problem

An error appears in the logs after adding a Hue Bridge, and the bridge is not usable within HA.

What version of Home Assistant Core has the issue?

core-2024.9.1

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant OS

Integration causing the issue

Philips Hue

Link to integration documentation on our website

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

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

Logger: homeassistant.components.hue.bridge
Source: components/hue/bridge.py:78
integration: Philips Hue (documentation, issues)
First occurred: 22:43:17 (2 occurrences)
Last logged: 22:48:11

Unknown error connecting to Hue bridge
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/hue/bridge.py", line 78, in async_initialize_bridge
    await self.api.initialize()
  File "/usr/local/lib/python3.12/site-packages/aiohue/v2/__init__.py", line 108, in initialize
    await self.fetch_full_state()
  File "/usr/local/lib/python3.12/site-packages/aiohue/v2/__init__.py", line 252, in fetch_full_state
    await asyncio.gather(
  File "/usr/local/lib/python3.12/site-packages/aiohue/v2/controllers/base.py", line 80, in initialize
    await self._handle_event(EventType.RESOURCE_ADDED, item)
  File "/usr/local/lib/python3.12/site-packages/aiohue/v2/controllers/base.py", line 209, in _handle_event
    raise exc
  File "/usr/local/lib/python3.12/site-packages/aiohue/v2/controllers/base.py", line 200, in _handle_event
    cur_item = self._items[item_id] = dataclass_from_dict(
                                      ^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiohue/util.py", line 244, in dataclass_from_dict
    field.name: _parse_value(
                ^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiohue/util.py", line 202, in _parse_value
    raise KeyError(f"`{name}` of type `{value_type}` is required.")
KeyError: "`Light.owner` of type `<class 'aiohue.v2.models.resource.ResourceIdentifier'>` is required."

Additional information

No response

home-assistant[bot] commented 2 months ago

Hey there @balloob, @marcelveldt, mind taking a look at this issue as it has been labeled with an integration (hue) you are listed as a code owner for? Thanks!

Code owner commands Code owners of `hue` can trigger bot actions by commenting: - `@home-assistant close` Closes the issue. - `@home-assistant rename Awesome new title` Renames the issue. - `@home-assistant reopen` Reopen the issue. - `@home-assistant unassign hue` Removes the current integration label and assignees on the issue, add the integration domain after the command. - `@home-assistant add-label needs-more-information` Add a label (needs-more-information, problem in dependency, problem in custom component) to the issue. - `@home-assistant remove-label needs-more-information` Remove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.

(message by CodeOwnersMention)


hue documentation hue source (message by IssueLinks)

calvinrw commented 2 months ago

Thanks for reporting this. I've encountered a very similar issue on my instance:

What version of Home Assistant Core has the issue?

2024.9.2

What was the last working version of Home Assistant Core?

2024.6.4

What type of installation are you running?

Home Assistant OS 13.1

Logger: homeassistant.components.hue.bridge
Source: components/hue/bridge.py:78
integration: Philips Hue (documentation, issues)
First occurred: 21:17:24 (1 occurrences)
Last logged: 21:17:24

Unknown error connecting to Hue bridge
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/hue/bridge.py", line 78, in async_initialize_bridge
    await self.api.initialize()
  File "/usr/local/lib/python3.12/site-packages/aiohue/v2/__init__.py", line 108, in initialize
    await self.fetch_full_state()
  File "/usr/local/lib/python3.12/site-packages/aiohue/v2/__init__.py", line 252, in fetch_full_state
    await asyncio.gather(
  File "/usr/local/lib/python3.12/site-packages/aiohue/v2/controllers/base.py", line 336, in initialize
    await resource_control.initialize(initial_data)
  File "/usr/local/lib/python3.12/site-packages/aiohue/v2/controllers/base.py", line 80, in initialize
    await self._handle_event(EventType.RESOURCE_ADDED, item)
  File "/usr/local/lib/python3.12/site-packages/aiohue/v2/controllers/base.py", line 209, in _handle_event
    raise exc
  File "/usr/local/lib/python3.12/site-packages/aiohue/v2/controllers/base.py", line 200, in _handle_event
    cur_item = self._items[item_id] = dataclass_from_dict(
                                      ^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiohue/util.py", line 244, in dataclass_from_dict
    field.name: _parse_value(
                ^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiohue/util.py", line 202, in _parse_value
    raise KeyError(f"`{name}` of type `{value_type}` is required.")
KeyError: "`GroupedLight.owner` of type `<class 'aiohue.v2.models.resource.ResourceIdentifier'>` is required."
calvinrw commented 2 months ago

This thread appears to discuss the same aiohue issue and a possible fix in a different project: https://github.com/diyhue/diyHue/issues/1032

kotylo commented 2 months ago

weird that it started yesterday for me too without any updates from my side. And now the Phillips Hue integration won't start with the same exception. Updated to 2024.9.3 just now, but same thing.

Seems like the Aug 2 Pull Request in the diyHue fixed it with this commit diyhue/diyHue@7c757d984a6f5d104522610d0f9abd544791acc3 . They have added some owner to the Group in V2 API, whatever that means. Could someone take a look if we can do it here too?

marcelveldt commented 2 months ago

Do you have an actual/real Philips Hue bridge or an emulated one like diyHue ?

If diyHue, you need to update that to the latest version (or file an issue report).

If a real Hue Bridge V2, check if there are any updates available.

kotylo commented 2 months ago

I have the real one, is up to date BSB002 | 1.66.1966117030

kotylo commented 2 months ago

Just wanted to let you know that today I don't get the same error anymore

DEBUG (MainThread) [aiohue.v2[192.168.86.x]] Got 503 or 429 error from Hue bridge, retry request in 0.5 seconds
INFO (MainThread) [aiohue.v2[192.168.86.x]] Connection to bridge closed.

so it is some other issue with Hue Bridge connection that should not be discussed here. Maybe it's not reachable from my docker container. I'll try to scratch my head in the evening again. Thanks for taking a look, though!

upd.: a pity, but i had to delete my Hub from Integration and readd it again. Then it worked. Now i have to fix the ids of the entities and scene entities are not available :\ upd2.:: seems like the core.config_entries are changed and api_version: 1 instead of 2 (as it was before) appeared. That's probably why I don't see the scenes and switch buttons...

skenmy commented 2 months ago

I've finally had the chance to try this all again.

I performed a full reset (using the hardware reset switch) of the Hue Bridge (it's a v2) and fully set it up again using the Hue app. It did perform a software update, and then I was able to set up the integration flawlessly.

I suspect something changed somewhere along the line, or that my bridge just got into a state where it couldn't update.

kotylo commented 2 months ago

If someone else has issue that after readding bridge (the scenes and switch buttons are gone), reboot the hue bridge (mine was rate limiting with 429 errors) and readd integration or edit .storage/core.config_entries file and check which api_version do you have for the bridge now.

Mine has added itself as api_version: 1 for some reason (i suppose v1 API was not rate limited and v2 API was, tested with Rest Client).

{
        "created_at": "2024-09-25T19:59:29.291417+00:00",
        "data": {
          "host": "192.168.86.100",
          "api_key": "x6jIAguyWx...",
          "api_version": 1
        },
...
      }

Switching here manually to api_version: 2 caused 429 error, but rebooting the hue bridge (again) helped and now the requests are working again.

hdehaseleer commented 1 month ago

I had also a problem after upgrading Home Assistant.

HA could no longer connect to my V2 Hue bridge. But my "Hue android app" could still connect. When trying to make a firmware update of the V2 bridge, my app said "update failed". So I upgraded my Hue app (which I never use) on my android. I had to add again the bridge, but the app found it automatically. And the firmware was automatically upgraded. And all the devices were automatically recovered.

After the upgrade of the firmware of the V2 bridge, HA connected automatically with the Hue bridge and everything worked again

A suggestion: I like HA, but it would be great when we could upgrade any integration separately and only when we find the need to upgrade an integration. I could have avoided this problem (and another with Opentherm integration)