Unifi stats to MQTT

The official Unifi integration is perfect to get all clients as device trackers, but is missing a lot of useful information which is provided by the Unifi API. For example access point status, score, cpu usage, uptime etc.
So I created a small docker image which acts as a bridge between the Unifi API and MQTT.
You can start this docker container and it will poll the Unifi API each 30 seconds (this is configurable) for the latest statistics and will publish this to MQTT. I have also included a configuration example how to get the sensors in Home Assistant.
Maybe this could also help others so I published it on my github https://github.com/bramstroker/UnifiMqttPublisher.

Where does the “publish_stats.py” in the repo come into play?

I don’t see that referenced anywhere in the instructions.

This is the python script which is run inside the docker container.
You could also run this python script and install the dependencies yourself with pip (or run inside a virtualenv).
But I like to have it contained in a docker image because it does not pollute my operating systems and to get things up and running it is just a single command.

Ah, Ok. thanks.

trying it out now.

Does this work with the latest UnifiOS auth requirements?

Right now I’m getting a “connection refused” error.

Likely because the new auth requirements for UnifiOS require a 2FA to log into the controller.

Is there any way to handle that?

I don’t know exactly. I’m using this library to access the unifi API. GitHub - nickovs/unificontrol: A high-level Python interface to the Unifi controller software. Maybe you could find something in their issue tracker.

However “connection refused” sounds more like a firewall/connection issue. Did you specify the correct host/port in the .env file?

the example .env file doesn’t ask for a controller port so I didn’t add one and I’m assuming the host needs to be the IP address of the Unifi controller.

Which port is this using to access the controller?

there was a change recently (at the same time as the auth change) to move from port 8443 to 443.


NVM, I see it’s using the older 8443 port.

Not sure if this will work on the later versions of UnifiOS.

Default port is 8443 in my python script.
You can also specify this in .env. I have also changed the example file to include this environment variable.

yeah, see my edit to the pot above.

It looks like it’s running into this issue here:

Yes I think so. Unfortunately there is not much we can do than wait till the issue is resolved in the library.

Ok, I’ll be watching here for an update.

Wouldn’t it be much better to expand the integration rather than creating one more thing that needs maintenance and support?

1 Like

yes that would definitely be the best option, however I don’t have much time on hand and needed to have something working quickly. It was working for me so I thought it might be useful for others.

I’m waiting for a month already to get some other additions merged which I did for another integration. When this is merged I’ll have a look into extending the official Unifi integration.