EMQX integration with Home Assistant and Zigbee2MQTT

Introduction

I used Xiaomi Gateway 3 for my Smart Home with Home Assistant integration last three years.

You can find guidance on how to integrate it with Zegbee2MQTT in this article:

https://www.diyenjoying.com/2022/09/25/home-assistant-zigbee-integration-with-xiaomi-gateway/

Unfortunately, after three years of stable functioning, I was faced with the issue due to losing connection with all my devices after 30 min of Zigbee2MQTT running. 

So, I started debugging and found the source of the problem. 

I found that HA and Zigbee2MQTT provide a lot of information in logs, but I still had a black box – Mosquitto broker with a lack of information in logs.

I started to search for another broker and found EMQX which has more rich functionality, and its own dashboard because it’s developed for high-loaded systems.

In this article you will find step-by-step guidance on how to switch from Mosquitto Broker to EMQX.

This guidance can be used for fresh install of EMQX as well.

Install EQMX Add-on for Home Assistant

I hope you use a supervised version of Home Assistant and have the ability to install add-ons easily.

Please my following articles if you struggling with installing a supervised version onto Raspberry OS or Debian forks (Ubuntu for example):

Go to Settings -> Add-ons, press ADD-ON STORE buttong on the bottom right corner.

You should see a new screen with “Official add-ons”. Type EMQX in search field and find it.

Click on the Add-on and install it.

As a result you should see this screen:

You can’t start it if you have launched Mosquitto Broker because of a conflict of used TCP ports. 

So, you have to stop your Mosquitto Broker.

Go to Settings -> Add-ons-> Mosquito Broker and stop it. Don’t forget to switch off “Start on Boot”. Otherwise, you’ll have “surprises” after rebooting your instance.

Now you can start EMQX.

Go to Settings -> Add-ons-> EMQZ and start it.

Please pay attention to Hostname of EMQX docker container – you’ll need it for MQTT and Zigbee2MQTT configurations.

Please also switch on “Show in sidebar” for easy access to it.

Please configure core-mosquitto integration to use EMQX.

Go to Settings-> Devices & Services and “Configure” button on the integration:

Press RE-CONFIGURE MQTT on the new screen and replace core-mosquitto with EMQX hostname ( a0d7b954-emqx in my case). 

Pay attention to Username and Password fields. You have to add used in Home Assistant in case of fresh installation and add the credentials here. 

This user is used for authorized connections between the integration and the broker.

Please press NEXT button on this screen and COMPLETE one on the next. Your integration configuration is completed.

The next step is Zigbee2MQTT add-on configuration.

Go to Settings -> Add-ons-> Zigbee2MQTT and stop it. Now, please choose “Configuration” tab of Zigbee2MQTT window and replace core-mosquitto with EMQX hostname ( a0d7b954-emqx in my case). 

Don’t forget to save your configuration and start Zigbee2MQTT Add-on.

Now you can observe EMQX dashboard. The default login and passwords are: 

  • admin
  • public

Please click on EQMX on the slide bar and login onto the dashboard.

Here you can find a lot of statistic, configurations, and logs on MQTT broker level.

Also, you can configure a log tracer and check which information is coming from Zigbe2MQTT add-on to debug it.

The example of collected log:

[MQTT]  msg: mqtt_packet_sent, packet: PUBLISH(Q0, R0, D0),Topic=zigbee2mqtt/HUE_Sensor_1, PacketId=undefinedPayload={"battery":59.5,"illuminance":2609,"illuminance_lux":2,"led_indication":true,"linkquality":138,"motion_sensitivity":"high","occupancy":true,"occupancy_timeout":60,"temperature":21.82,"update":{"state":"idle"},"update_available":false}

EMQX vs Mosquitto broker

EMQX is a rich broker which provides a lot of information and possibility for tuning and configuration. 

But, on the other hand it is heavier than Mosquitto Broker.

EMQX consumes 22% CPU capacity of my Raspberry PI 4 more than Mosquito Broker. You can see the loading difference below.

 

Raspberry PI loading with Mosquitto broker.

Raspberry PI loading with EMQX

Actually, I use EMQX if some debugging is needed because my current setup doesn’t require a broker for heavy-loaded systems.

Please feel free to ask any questions in the comments.

2 thoughts on “EMQX integration with Home Assistant and Zigbee2MQTT

  1. Thanks for the tip about setting the mosquito to point to the EQMX, I was missing that, and Home Assistant wasn't connecting to the new EQMX (but Node Red and all my other clients were).

  2. I am having trouble with zigbee2mqtt: The password is not working. Also getting a 502: bad gateway when I open Zigbee2MQTT. I used my account and password I setup in EMQX. What am I missing? I see in the pic it shows the word addons with a green-out, then what looks like a UID for a password.

Leave a Reply

Your email address will not be published. Required fields are marked *