Cannot connect Zigbee2mqtt to MQTT : docker install

Hello everybody,

I am new to Home Assistant and I am tryng to set up a basic Home Assistant configuration with some Zigbee devices I already have. I am using Docker installation on a Ubuntu laptop (and I am new to Docker too).
I tested the ZHA integration (very easy to set up) but while I could easily connect to some LIDL and Sonoff devices, I could not finalise the configuration of some others (IKEA and Lexman).

So I moved to mqtt and zigbee2mqtt. I have got no error while configuring my containers. However, it looks like zigbee2mqtt cannot connect to mqtt broker; the last message the corresponding container log is:

Zigbee2MQTT:info  2022-05-09 21:19:47: Connecting to MQTT server at mqtt://192.168.xx.xxx

No other message follow and when I stop the container I get:

Zigbee2MQTT:error 2022-05-09 21:19:32: Failed to call 'Frontend' 'stop' (TypeError: Cannot read properties of null (reading 'clients')
    at Controller.callExtensions (/app/lib/controller.ts:316:40)
    at Frontend.stop (/app/lib/extension/frontend.ts:59:39)
    at stop (/app/index.js:114:5)
    at process.handleQuit (/app/index.js:120:9))
Zigbee2MQTT:error 2022-05-09 21:19:32: Not connected to MQTT server!
    at Controller.stop (/app/lib/controller.ts:191:9)

I cannot figure out what’s going wrong. I have no log from mosquitto (even by adding log_type all in its config file) to check from that side…however it looks like mqtt is running and correctly set up in Home Assistant (no error in that phase…but I do not know if there is any way to check that mqtt respond correctly to any request).

I add that the frontend of zigbee2mqtt is not available (which seems to confirm that zigbee2mqtt is not really ON even if I get no error message).
For information, I also add some errors previously with zigbee2mqtt (which crashed that time) because the USB zigbee dongle was still associated which ZHA. Since then, I removed the ZHA integration and that error went away…leading me to my actual issue: no error message, but zigbee2mqtt not really fonctional.

Thanks in advance for your help.

Here follows my docker-compose file:

version: '3.0'

services:

  portainer:
    container_name: portainer
    image: portainer/portainer-ce
    restart: always
    ports:
      - "9000:9000/tcp"
    environment:
      - TZ=Europe/Paris
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - /mnt/soft_space/dockData/portainer:/data

  homeassistant:
    container_name: homeassistant
    image: "ghcr.io/home-assistant/home-assistant:stable"
    volumes:
      - /mnt/soft_space/dockData/homeassistant/config:/config
      - /etc/localtime:/etc/localtime:ro
    restart: unless-stopped
    privileged: true
    network_mode: host

  mosquitto:
    image: eclipse-mosquitto
    container_name: mosquitto
    volumes:
      - /mnt/soft_space/dockData/mosquitto:/mosquitto
    ports:
      - 1883:1883
      - 9001:9001

  zigbee2mqtt:
    container_name: zigbee2mqtt
    image: koenkk/zigbee2mqtt
    restart: unless-stopped
    volumes:
      - /mnt/soft_space/dockData/zigbee2mqtt/data:/app/data
      - /run/udev:/run/udev:ro
    ports:
      - 8080:8080
    environment:
      - TZ=Europe/Paris
    devices:
      - /dev/ttyUSB0:/dev/ttyACM0

…and the config files of mosquitto :

persistence true
persistence_location /mosquitto/data/
log_dest file /mosquitto/log/mosquitto.log
log_type all
listener 1883

## Authentication ##
allow_anonymous false
password_file /mosquitto/config/password.txt

…and of zigbee2mqtt:

# Home Assistant integration (MQTT discovery)
homeassistant: true

# allow new devices to join
permit_join: true

frontend: true

# MQTT settings
mqtt:
  # MQTT base topic for zigbee2mqtt MQTT messages
  base_topic: zigbee2mqtt
  # MQTT server URL
  server: 'mqtt://192.168.xx.xxx'
  # MQTT server authentication, uncomment if required:
  user: hass
  password: xxxxxxxxxxxxx

# Serial settings
serial:
  # Location of CC2531 USB sniffer
  port: /dev/ttyACM0

Does MQTT run well, do you see any topics in there (e.g. use MQTT explorer)
I noticed you added pwd to mqtt, did you properly load them into mqtt?
If MQTT not reachable via MQTT explorer… suggestion to try mqtt first without pwd, allow anonymous…keep it simple and then close it down

Try:

listener 1883 0.0.0.0

Thanks to both of you;

I tried to:

  • remove the password
  • add the 0.0.0.0 to the listener line (even if I do not understand its role)

The situation did not change.

However, installing mqtt-explorer made me progress : I am know sure that the mqtt broker is running and that it is connected to Home Assistant (the test = eheh epoi line in the following screenshot was published by HA):

Screenshot from 2022-05-10 22-15-33

So the issue seems to come from zigbee2mqtt: why is it trying forever to connect to mqtt without any success?

I then tried to restore the password request: I achieve in correctly connect to mqtt with mqtt-explorer once I provided the password.
However, zigbee2mqtt (who does not know the password anymore) keep trying to connect as always (password or no-password, nothing changed for him…).

What I read from your data is that you have both z2m and mqtt on a non-host container meaning that you need to supply the port i order to get there, i.e. you supplied the ost IP but in fact the container ha an internal different one only available via the port 1883 so you should setup z2m with that.
I myself decided from the start to put both on ‘host’ (–net=host) to avoid all of this, not sure if that decision is the best but it has worked from the start.
See first (balcK0 section in here and change the ‘server’
MQTT | Zigbee2MQTT

1 Like

That did the job ! Thanks for your help !