Monitoring your Unifi AP

Could version = ‘UDMP-unifiOS’ be the problen as I have a UCG Ultra instead of a UDMP.
But when I try all other version credential options [v4|v5|unifiOS]
i get the following error

error: "Login failed - status code: 401"
traceback: |
  Traceback (most recent call last):
    File "/config/custom_components/python_script/__init__.py", line 107, in execute_script
      exec(code, vars)
      ~~~~^^^^^^^^^^^^
    File "/config/python_scripts/unifi_mqtt.py", line 17, in <module>
      client = Controller(host, username, password, port, version, site_id=site_id, ssl_verify=verify_ssl)
    File "/usr/local/lib/python3.13/site-packages/pyunifi/controller.py", line 113, in __init__
      self._login()
      ~~~~~~~~~~~^^
    File "/usr/local/lib/python3.13/site-packages/pyunifi/controller.py", line 195, in _login
      raise APIError(
          "Login failed - status code: %i" % response.status_code
          )
  pyunifi.controller.APIError: Login failed - status code: 401

We need to look into it if version is still needed.

[v4|v5|unifiOS] was for older versions of the controller.

your issue also been resolved @Alwin_Hummels as per ticket.

1 Like

Great work, thank you so much for your time and dedication

1 Like

Great work on this. I found it easy to contribute to the script as well and add a few other bits in that I wanted to use :slight_smile:

2 Likes

All thanks to @ingoldsby we finally moved to a proper intergration.

Please test and give feedback if you have any issues.

I think works great.
But I need to re do the card again.
Do you have a beta off the card?
I dont know how to use the atributes in the old card. If i can see a example then it will be easy for me to adapt my card to this new integration

1 Like

Receiving this error when setting up the integration - local super admin account used.

It does however seem to be populating the MQTT server with the devices.

Logger: homeassistant.config_entries
Source: config_entries.py:640
First occurred: 20:09:30 (3 occurrences)
Last logged: 20:20:31

Error setting up entry UniFi MQTT for unifi_mqtt
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 640, in __async_setup_with_context
    result = await component.async_setup_entry(hass, self)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/unifi_mqtt/__init__.py", line 59, in async_setup_entry
    controller = await hass.async_add_executor_job(init_controller)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
asyncio.exceptions.CancelledError```

Is it possible to use this integration to connect to a MQTT server on a different host and not the MQTT Integration in HA? Also, when trying it out, it is not able to connect to my self hosted Unifi Network Manager as it is running on port 8443. I changed the port config from 443 to 8443 but the HA log shows that it is still trying to connect to port 443 and it times out as there is nothing listening on port 443.

I have added this an issue here, Change port and set option for MQTT server · Issue #21 · w1tw0lf/Unifi-Device-info · GitHub We will look into this.

1 Like

is there anything else in the logs showing errors related to it?

yes, apologies, didn’t notice this one previously.

Logger: homeassistant
Source: custom_components/unifi_mqtt/__init__.py:75
integration: UniFi MQTT Integration (documentation)
First occurred: 4 February 2025 at 22:13:03 (738 occurrences)
Last logged: 10:30:04

Error doing job: Task exception was never retrieved (None)
Traceback (most recent call last):
  File "/config/custom_components/unifi_mqtt/__init__.py", line 75, in update_unifi_data
    if not device.get("adopted"):
           ^^^^^^^^^^
AttributeError: 'str' object has no attribute 'get'[wrap="justify"]
Text
[/wrap]

Could you try upgrading to release v1.0.1. There was a fix put in there earlier today to potentially resolve that issue. I haven’t been able to test on different apps, but the fix would resolve that error.

If you check logs in the future, you may see something like “Received device that is not a dictionary”. If you do, I would be keen to get details that are provided in the logs. In mine when I have had this, it simply said “Error”, I would like to know if that’s the same as others.

Thanks for you help I seem to be getting this error with v1.0.1, although all MQTT publishing seems to be working.

Logger: custom_components.unifi_mqtt
Source: custom_components/unifi_mqtt/__init__.py:63
integration: UniFi Device Info Integration (documentation)
First occurred: 11:52:02 (1 occurrences)
Last logged: 11:52:02

Failed to initialize UniFi controller: HTTPSConnectionPool(host='192.68.1.1', port=443): Max retries exceeded with url: /api/auth/login (Caused by ConnectTimeoutError(<urllib3.connection.HTTPSConnection object at 0x7f6944ac10>, 'Connection to 192.68.1.1 timed out. (connect timeout=None)'))

I also had this error due to an apostrophe in one of my Unifi devices, but I changed the name and this obviously was resolved, just thought it would be good to know.

Logger: homeassistant.components.mqtt.discovery
Source: components/mqtt/discovery.py:395
integration: MQTT (documentation, issues)
First occurred: 11:49:49 (1 occurrences)
Last logged: 11:49:49

Received message on illegal discovery topic 'homeassistant/sensor/unifi_mqtt/usw-flex-george's_room/config'. The topic contains non allowed characters. For more information see https://www.home-assistant.io/integrations/mqtt/#discovery-topic

Hello.
I updated today and create the new integration(after delete de previous 1.0)
in this new version I set the pool interval to 30seconds.
But i see that the entitis refresh after aprox 70sg (60sec pooling, and 10sg between the script launch and report information).

maybe the config pool interval is not working?
and other thing. how can i change the pooling interval? I must delete de integration and create again? i cant find the configuration button to change it in the integration :frowning:

Can I confirm with the removal if you did:

  1. Did ‘delete’ on the Integration entries screen to remove the integration entry, or
  2. In HACS, removed the integration and installed a new one, or
  3. In HACS, updated the integration

The configuration button issue is one I’m working through (Provide 'configure' option for updating configuration information for integration · Issue #20 · w1tw0lf/Unifi-Device-info · GitHub) but I do wonder whether the update interval polling doesn’t get updated by HA in certain circumstances (maybe #2 & #3) with and without restarting HA to remove config entries.

I delete in the integraron menu.
Then i delete the mqtt devices.
Then i go to hacs and force re download.
Then i configure again the integration

Thanks - will look into it a bit more.

1 Like

hello.
today at morning i see the log and see this errors:

Este error se originó a partir de una integración personalizada.

Registrador: custom_components.unifi_mqtt
Fuente: custom_components/unifi_mqtt/__init__.py:79
integración: UniFi Device Info Integration (documentación)
Ocurrió por primera vez: 5 de febrero de 2025, 22:57:35 (1377 ocurrencias)
Última vez registrado: 10:25:38

Received device that is not a dictionary: error

no more details :frowning:

Hi, my problems seem to have been resolved either with the introduction of 1.0.2 or with the update to HA 2025.2.0, I’m unsure which. Thank you :grinning:

2 Likes