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
69.94k stars 29.03k forks source link

Unifi Network integration fails to setup #117158

Closed mck165 closed 1 week ago

mck165 commented 2 months ago

The problem

The integration has been working fine for over 2 years. Now I am not able to load the configuration even after creating a new local user in Unifi OS and using those login credentials

What version of Home Assistant Core has the issue?

2024.5.2

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

Unifi Network

Link to integration documentation on our website

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

Diagnostics information

home-assistant_unifi_2024-05-09T20-15-57.791Z.log

Example YAML snippet

No response

Anything in the logs that might be useful for us?

No response

Additional information

No response

home-assistant[bot] commented 2 months ago

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

Code owner commands Code owners of `unifi` 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 unifi` 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)


unifi documentation unifi source (message by IssueLinks)

Kane610 commented 2 months ago

With what change did you experience this. What version of Unifi app and os are you running

mck165 commented 2 months ago

With what change did you experience this

Unfortunately I am not sure when it happened as I do not rely on too many automations for Unifi

Kane610 commented 2 months ago

What version of Unifi app and os are you running

mck165 commented 2 months ago

What version of Unifi app and os are you running

Unifi OS v3.12.12 and Network 8.1.127

MackKaufmann commented 2 months ago

Same here (HA Docker):

Logger: homeassistant.components.unifi Source: components/unifi/hub/api.py:76 Error connecting to the UniFi Network at 192.168.1.1:

Seems like the port is missing after IP when connecting.

Connecting should be: 192.168.1.1:443

Justsomedong commented 2 months ago

I was / am having the same issue. Created new Local User on UDMSE after Early Access (I know, likely to break things!) install broke integration with needing new auth. New local account didn't solve after reboot of both devices.

Deleted integration, but on re-add using the new local account I receive "Unknown Error Occurred" or "Invalid Auth"

Network integration works perfect with same u/p.

Unifi OS: 4.0.3 Protect: 4.0.7 HA: 2024.5.3

Kane610 commented 2 months ago

Lets keep this issue to be about Network, protect has its own implementation

Kane610 commented 2 months ago

Based on this comment, does Network work for OP?

I was / am having the same issue. Created new Local User on UDMSE after Early Access (I know, likely to break things!) install broke integration with needing new auth. New local account didn't solve after reboot of both devices.

Deleted integration, but on re-add using the new local account I receive "Unknown Error Occurred" or "Invalid Auth"

Network integration works perfect with same u/p.

Justsomedong commented 2 months ago

Lets keep this issue to be about Network, protect has its own implementation

Sorry about that! Jumped in wrong repo!

mck165 commented 2 months ago

Based on this comment, does Network work for OP?

I was / am having the same issue. Created new Local User on UDMSE after Early Access (I know, likely to break things!) install broke integration with needing new auth. New local account didn't solve after reboot of both devices. Deleted integration, but on re-add using the new local account I receive "Unknown Error Occurred" or "Invalid Auth" Network integration works perfect with same u/p.

I have not upgraded to early access. Should I try deleting and then reinstalling the integration again?

mck165 commented 2 months ago

Just a random thought I had as I continue to research...starting to think that the issue may have started when I enabled MFA...

MackKaufmann commented 2 months ago

Just a random thought I had as I continue to research...starting to think that the issue may have started when I enabled MFA...

The integrations expect local accounts which are not required to have 2FA enabled. See this thread https://community.home-assistant.io/t/2fa-added-to-the-unifi-ubiquiti-component/293031/10

mck165 commented 2 months ago

Just a random thought I had as I continue to research...starting to think that the issue may have started when I enabled MFA...

The integrations expect local accounts which are not required to have 2FA enabled. See this thread https://community.home-assistant.io/t/2fa-added-to-the-unifi-ubiquiti-component/293031/10

Thanks. I just checked and I do have a local user setup for the integration

MackKaufmann commented 2 months ago

Hey @Kane610, did you check on this: https://github.com/home-assistant/core/issues/117158#issuecomment-2104938326?

janegilring commented 2 months ago

I faced the same issue when creating a user for Home Assistant and found the following workaround:

I would assume provisioning users via SSH/CLI could be an alternate approach when the legacy interface is removed at some point.

Kane610 commented 2 months ago

Same here (HA Docker):

Logger: homeassistant.components.unifi Source: components/unifi/hub/api.py:76 Error connecting to the UniFi Network at 192.168.1.1:

Seems like the port is missing after IP when connecting.

Connecting should be: 192.168.1.1:443

Good observation, the log could be clearer, the format of the log is <host>: <error message> so its not missing, only saying that the error message was empty

Kane610 commented 2 months ago

As most people have reported it is working on both 3 and 4 right now I would make sure to properly restart all equipment to make sure its back in a known state

MackKaufmann commented 2 months ago

As most people have reported it is working on both 3 and 4 right now I would make sure to properly restart all equipment to make sure its back in a known state

Done already: Pulled new HA Docker image, deactivated HACS and all its integrations. Restarted UDM Pro, deactivated any firewall rules. Same result:

ERROR (MainThread) [homeassistant.components.unifi] Error connecting to the UniFi Network at 192.168.1.1:

By the way: the same problem exists with @homeassistant/components/fritzbox

seracc commented 1 month ago

Having the same issue trying to set up the integration for the first time. Getting the following error message:

2024-05-16 09:36:38.035 ERROR (MainThread) [homeassistant.components.unifi] Error connecting to the UniFi Network at 192.168.36.1:

Running HA on a Raspberry Pi 4 Core 2024.5.3 Supervisor 2024.05.1 Operating System 12.3

Unifi Network is on 8.1.127 running on a UDM-Pro running OS version 3.2.12.

I have restarted the UDM-Pro, HA, and my Switch Pro 24 PoE and nothing changes. I can ping 192.168.36.1 from HA as well. Also tested the login credentials of the local admin I created and that works just fine.

Kane610 commented 1 month ago

By the way: the same problem exists with @homeassistant/components/fritzbox

Probably unrelated, but the issue is on your side as it can't connect to the address.

Kane610 commented 1 month ago

Having the same issue trying to set up the integration for the first time. Getting the following error message:

2024-05-16 09:36:38.035 ERROR (MainThread) [homeassistant.components.unifi] Error connecting to the UniFi Network at 192.168.36.1:

Running HA on a Raspberry Pi 4 Core 2024.5.3 Supervisor 2024.05.1 Operating System 12.3

Unifi Network is on 8.1.127 running on a UDM-Pro running OS version 3.2.12.

I have restarted the UDM-Pro, HA, and my Switch Pro 24 PoE and nothing changes. I can ping 192.168.36.1 from HA as well. Also tested the login credentials of the local admin I created and that works just fine.

Are you sure its the correct address, not too common using a high number as 36

seracc commented 1 month ago

Having the same issue trying to set up the integration for the first time. Getting the following error message: 2024-05-16 09:36:38.035 ERROR (MainThread) [homeassistant.components.unifi] Error connecting to the UniFi Network at 192.168.36.1: Running HA on a Raspberry Pi 4 Core 2024.5.3 Supervisor 2024.05.1 Operating System 12.3 Unifi Network is on 8.1.127 running on a UDM-Pro running OS version 3.2.12. I have restarted the UDM-Pro, HA, and my Switch Pro 24 PoE and nothing changes. I can ping 192.168.36.1 from HA as well. Also tested the login credentials of the local admin I created and that works just fine.

Are you sure its the correct address, not too common using a high number as 36

Yes, I use some odd numbers so I can tell what site is what and I don't end up accidentally making changes to the wrong site if I forget to switch between UDM consoles.

MackKaufmann commented 1 month ago

The error seemed to be related to QNAP Container Station (Docker), when running HA in Host mode docker (lxcbr0).

After the most recent firmware update, the connection can be re-established.

issue-triage-workflows[bot] commented 1 month ago

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

coreywillwhat commented 1 month ago

I've been having this issue for about the same amount of time as others here. Getting 403 Forbidden upon login attempt. Agree it also appeared around the same time I setup MFA for my cloud users. I have a super admin user setup with restrict to local access only for HA access.

Here is the log for integration reload:

2024-06-12 07:40:26.989 WARNING (MainThread) [homeassistant.components.unifi] Exception on update Call https://192.168.1.1:443/api/auth/login received 403 Forbidden
2024-06-12 07:40:26.990 WARNING (MainThread) [homeassistant.components.unifi] Exception on update Call https://192.168.1.1:443/proxy/network/api/s/default/rest/user received 401 Unauthorized
2024-06-12 07:40:26.990 WARNING (MainThread) [homeassistant.components.unifi] Exception on update Call https://192.168.1.1:443/proxy/network/api/s/default/stat/device received 401 Unauthorized
2024-06-12 07:40:26.990 WARNING (MainThread) [homeassistant.components.unifi] Exception on update Call https://192.168.1.1:443/proxy/network/api/s/default/rest/dpiapp received 401 Unauthorized
2024-06-12 07:40:26.990 WARNING (MainThread) [homeassistant.components.unifi] Exception on update Call https://192.168.1.1:443/proxy/network/api/s/default/rest/dpigroup received 401 Unauthorized
2024-06-12 07:40:26.990 WARNING (MainThread) [homeassistant.components.unifi] Exception on update Call https://192.168.1.1:443/proxy/network/api/s/default/rest/portforward received 401 Unauthorized
2024-06-12 07:40:26.990 WARNING (MainThread) [homeassistant.components.unifi] Exception on update Call https://192.168.1.1:443/proxy/network/api/self/sites received 401 Unauthorized
2024-06-12 07:40:26.990 WARNING (MainThread) [homeassistant.components.unifi] Exception on update Call https://192.168.1.1:443/proxy/network/api/s/default/stat/sysinfo received 401 Unauthorized
2024-06-12 07:40:26.990 WARNING (MainThread) [homeassistant.components.unifi] Exception on update Call https://192.168.1.1:443/proxy/network/api/s/default/rest/wlanconf received 401 Unauthorized
2024-06-12 07:40:26.990 ERROR (MainThread) [homeassistant.config_entries] Error setting up entry Default for unifi
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 594, in async_setup
    result = await component.async_setup_entry(hass, self)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/unifi/__init__.py", line 52, in async_setup_entry
    await hub.initialize()
  File "/usr/src/homeassistant/homeassistant/components/unifi/hub/hub.py", line 92, in initialize
    self.is_admin = self.api.sites[self.config.entry.unique_id].role == "admin"
                    ~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiounifi/interfaces/api_handlers.py", line 167, in __getitem__
    return self._items[obj_id]
           ~~~~~~~~~~~^^^^^^^^
KeyError: '629555bcb983050869acb2a6'

and the log for integration (re)setup:

2024-06-12 07:47:44.781 ERROR (MainThread) [homeassistant.components.unifi] Error connecting to the UniFi Network at 192.168.1.1: Call https://192.168.1.1:443/api/auth/login received 403 Forbidden
2024-06-12 07:48:02.357 ERROR (MainThread) [homeassistant.components.unifi] Error connecting to the UniFi Network at 192.168.1.1: Call https://192.168.1.1:443/api/auth/login received 403 Forbidden
Kane610 commented 1 month ago

I've been having this issue for about the same amount of time as others here. Getting 403 Forbidden upon login attempt. Agree it also appeared around the same time I setup MFA for my cloud users. I have a super admin user setup with restrict to local access only for HA access.

Accounts with MFA is not supported by the integration.

coreywillwhat commented 1 month ago

Thanks for the quick response! I've disabled MFA for my account and still getting the same error in my logs. I'll try to give it some time and reboot the UDMSE to see if it works.

issue-triage-workflows[bot] commented 2 weeks ago

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.