# Gladys and existing mqtt+zigbee2mqtt docker

**URL:** <https://community.gladysassistant.com/t/gladys-et-docker-mqtt-zigbee2mqtt-existant/8478>\
**Category:** Configuration\
**Created:** [November 11, 2023, 3:56pm UTC](https://community.gladysassistant.com/t/gladys-et-docker-mqtt-zigbee2mqtt-existant/8478 "2023-11-11T15:56:08Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![zedyxer](https://gladys-assistant-community.b-cdn.net/user_avatar/community.gladysassistant.com/zedyxer/32/13458_2.png) [@zedyxer](https://community.gladysassistant.com/u/zedyxer)\
**Post date:** [November 11, 2023, 3:56pm UTC](https://community.gladysassistant.com/t/gladys-et-docker-mqtt-zigbee2mqtt-existant/8478/1 "2023-11-11T15:56:08Z")

</div>

Hello everyone,

I have an existing Mosquitto (Docker) server as well as a zigbee2mqtt Docker container — is it possible to connect Gladys to these two Docker containers to make use of Zigbee sensors? Or is it necessary to go through Gladys’ two internal Docker containers (mqtt and zigbee2mqtt)?

 ![image](https://gladys-assistant-community.b-cdn.net/uploads/default/original/2X/5/59d21aed4ee621404cb9798d951d2aec1e24fa70.png)

I would like to keep my two Docker containers 🙂  
Thanks!

Z.

---

<div class="post-metadata">

**Author:** ![guim31](https://gladys-assistant-community.b-cdn.net/user_avatar/community.gladysassistant.com/guim31/32/4840_2.png) [@guim31](https://community.gladysassistant.com/u/guim31)\
**Post date:** [November 11, 2023, 4:42pm UTC](https://community.gladysassistant.com/t/gladys-et-docker-mqtt-zigbee2mqtt-existant/8478/2 "2023-11-11T16:42:13Z")

</div>

I’m trying to give an answer without being an expert at all, but I think it’s possible as long as access to the MQTT and z2m containers is configured correctly: username/password and IP:port

When in doubt, before modifying any config file… let’s wait for confirmation! 😉

---

<div class="post-metadata">

**Author:** ![cce66](https://gladys-assistant-community.b-cdn.net/letter_avatar_proxy/v4/letter/c/8797f3/32.png) [@cce66](https://community.gladysassistant.com/u/cce66)\
**Post date:** [November 11, 2023, 5:26pm UTC](https://community.gladysassistant.com/t/gladys-et-docker-mqtt-zigbee2mqtt-existant/8478/3 "2023-11-11T17:26:00Z")

</div>

The problem is that you’ll have port conflicts if you deploy Gladys’s services in addition to yours when they are on the same machine,  
ton docker mqtt = IP + port (1883 certainly) + username + password  
ton docker zigbee2mqtt = IP + port (1884 certainly) + username + password

docker Gladys mqtt = IP + port (1883) + username (Gladys by default) + password defined in Gladys  
docker Gladys zigbee2mqtt = IP + port (1884) + (Gladys by default) + password in the file «&nbsp;configuration.yaml&nbsp;» which is located in the «&nbsp;var/lib/gladysassistant/zigbee2mqtt/z2m&nbsp;» directory in the «&nbsp;mqtt:&nbsp;» section  
So you need to change the ports on your containers, and I think wanting to use other dockers than Gladys’s is not necessarily a good idea unless you tinker with that file but inside your docker so they communicate with Gladys correctly. Gladys needs zigbee2mqtt to integrate the devices but its parameters are not accessible from Gladys, unlike the MQTT part

If they’re on another machine, no problem!

What are you currently running that requires these dockers before installing Gladys?

---

<div class="post-metadata">

**Author:** ![zedyxer](https://gladys-assistant-community.b-cdn.net/user_avatar/community.gladysassistant.com/zedyxer/32/13458_2.png) [@zedyxer](https://community.gladysassistant.com/u/zedyxer)\
**Post date:** [November 11, 2023, 6:00pm UTC](https://community.gladysassistant.com/t/gladys-et-docker-mqtt-zigbee2mqtt-existant/8478/4 "2023-11-11T18:00:38Z")

</div>

I was using these two containers with Jeedom, which I had been using previously.  
I would have liked to keep them because I know them well, I know how to handle their config files, they are backed up and have been working together correctly for a long time. If it’s a bad idea to keep them, I’ll have to take the plunge and use only Gladys’s containers and

---

<div class="post-metadata">

**Author:** ![Tlse-vins](https://gladys-assistant-community.b-cdn.net/user_avatar/community.gladysassistant.com/tlse-vins/32/6054_2.png) [@Tlse-vins](https://community.gladysassistant.com/u/Tlse-vins)\
**Post date:** [November 11, 2023, 6:07pm UTC](https://community.gladysassistant.com/t/gladys-et-docker-mqtt-zigbee2mqtt-existant/8478/5 "2023-11-11T18:07:24Z")

</div>

If you want to keep them, can you change the ports on the ones that already exist?  
That way there won’t be a problem, right?

---

<div class="post-metadata">

**Author:** ![cce66](https://gladys-assistant-community.b-cdn.net/letter_avatar_proxy/v4/letter/c/8797f3/32.png) [@cce66](https://community.gladysassistant.com/u/cce66)\
**Post date:** [November 11, 2023, 7:24pm UTC](https://community.gladysassistant.com/t/gladys-et-docker-mqtt-zigbee2mqtt-existant/8478/6 "2023-11-11T19:24:23Z")

</div>

Like I said, put other ports in your config files besides 1883 and 1884 and there’s no problem working with your containers and Gladys’s, and at least you’ve got a stable config for Gladys! 😉

---

<div class="post-metadata">

**Author:** ![cicoub13](https://gladys-assistant-community.b-cdn.net/user_avatar/community.gladysassistant.com/cicoub13/32/4482_2.png) [@cicoub13](https://community.gladysassistant.com/u/cicoub13)\
**Post date:** [November 11, 2023, 8:29pm UTC](https://community.gladysassistant.com/t/gladys-et-docker-mqtt-zigbee2mqtt-existant/8478/7 "2023-11-11T20:29:38Z")

</div>

> [@zedyxer](#):
>
> Is it possible to connect Gladys to these 2 Docker containers in order to take advantage of Zigbee sensors?

Hello 👋

For MQTT, it’s possible (see the [documentation]([https://gladys](https://gladys)

---

<div class="post-metadata">

**Author:** ![zedyxer](https://gladys-assistant-community.b-cdn.net/user_avatar/community.gladysassistant.com/zedyxer/32/13458_2.png) [@zedyxer](https://community.gladysassistant.com/u/zedyxer)\
**Post date:** [November 12, 2023, 9:10am UTC](https://community.gladysassistant.com/t/gladys-et-docker-mqtt-zigbee2mqtt-existant/8478/8 "2023-11-12T09:10:36Z")

</div>

In fact I’m already using my Mosquitto with Gladys :

 ![image](https://gladys-assistant-community.b-cdn.net/uploads/default/original/2X/9/95e0c40dd39d2e68abaf6d53762935fd5c9a689a.png)

It works very well and I’m already getting all my topics.  
However, the zigbee2mqtt install creates a second Docker container for me; it doesn’t use my existing Mosquitto server.

---

<div class="post-metadata">

**Author:** ![GBoulvin](https://gladys-assistant-community.b-cdn.net/user_avatar/community.gladysassistant.com/gboulvin/32/10006_2.png) [@GBoulvin](https://community.gladysassistant.com/u/GBoulvin)\
**Post date:** [November 12, 2023, 9:36am UTC](https://community.gladysassistant.com/t/gladys-et-docker-mqtt-zigbee2mqtt-existant/8478/9 "2023-11-12T09:36:19Z")

</div>

I feel like you’d be more likely to create a backup in your personal ZigBee2MQTT and restore it to the one managed by Gladys…

---

<div class="post-metadata">

**Author:** ![spenceur](https://gladys-assistant-community.b-cdn.net/user_avatar/community.gladysassistant.com/spenceur/32/1961_2.png) [@spenceur](https://community.gladysassistant.com/u/spenceur)\
**Post date:** [November 12, 2023, 9:47am UTC](https://community.gladysassistant.com/t/gladys-et-docker-mqtt-zigbee2mqtt-existant/8478/10 "2023-11-12T09:47:36Z")

</div>

> [@cicoub13](#):
>
> For ZigbeMQTT, that’s not possible, it was a feature request from some users (you can make a feature request on the forum).

That’s exactly what @cicoub13 replied to you  
At the moment z2m doesn’t do it

---

<div class="post-metadata">

**Author:** ![zedyxer](https://gladys-assistant-community.b-cdn.net/user_avatar/community.gladysassistant.com/zedyxer/32/13458_2.png) [@zedyxer](https://community.gladysassistant.com/u/zedyxer)\
**Post date:** [November 12, 2023, 10:06am UTC](https://community.gladysassistant.com/t/gladys-et-docker-mqtt-zigbee2mqtt-existant/8478/11 "2023-11-12T10:06:16Z")

</div>

Ok, I’m giving up on my existing Docker containers. I’m using Gladys

---

<div class="post-metadata">

**Author:** ![guim31](https://gladys-assistant-community.b-cdn.net/user_avatar/community.gladysassistant.com/guim31/32/4840_2.png) [@guim31](https://community.gladysassistant.com/u/guim31)\
**Post date:** [November 12, 2023, 10:09am UTC](https://community.gladysassistant.com/t/gladys-et-docker-mqtt-zigbee2mqtt-existant/8478/12 "2023-11-12T10:09:56Z")

</div>

No, it’s all good 👌  
Each of these two integrations needs an MQTT broker to communicate with.

---

<div class="post-metadata">

**Author:** ![zedyxer](https://gladys-assistant-community.b-cdn.net/user_avatar/community.gladysassistant.com/zedyxer/32/13458_2.png) [@zedyxer](https://community.gladysassistant.com/u/zedyxer)\
**Post date:** [November 12, 2023, 10:13am UTC](https://community.gladysassistant.com/t/gladys-et-docker-mqtt-zigbee2mqtt-existant/8478/13 "2023-11-12T10:13:56Z")

</div>

Ok thanks for all the info, I’ve tidied things up while keeping my MQTT broker Mosquitto, I just need to take care of my Zigbee config:

 ![image](https://gladys-assistant-community.b-cdn.net/uploads/default/original/2X/e/ef355e2d4029835fd32ddc4ab58419b3c1e82dfa.png)

Thanks everyone for the quick info 😉

---

<div class="post-metadata">

**Author:** ![JeuFore](https://gladys-assistant-community.b-cdn.net/user_avatar/community.gladysassistant.com/jeufore/32/7544_2.png) [@JeuFore](https://community.gladysassistant.com/u/JeuFore)\
**Post date:** [November 12, 2023, 1:32pm UTC](https://community.gladysassistant.com/t/gladys-et-docker-mqtt-zigbee2mqtt-existant/8478/14 "2023-11-12T13:32:47Z")

</div>

Hello @zedyxer,  
On my side, I use Gladys with K8S, so I don’t have access to automatic Docker mounts.

For Zigbee, like you I use a separate container that is connected to Gladys. To get the two to communicate, I modify the connection values directly inside the Docker container.

Here are the files:

```bash
/src/server/services/zigbee2mqtt/lib/init.js
/src/server/services/zigbee2mqtt/lib/getConfiguration.js

```

It’s not the best technique, but I’ve been using it for a long time and I’ve never had a problem. However, you should check the Zigbee code updates from time to time in case there are major changes (once so far)

Here are the files in question:

init.js

> **Summary**
>
> ```js
> const logger = require('../../../utils/logger');
> const { CONFIGURATION } = require('./constants');
> const { generate } = require('../../../utils/password');
> const { PlatformNotCompatible } = require('../../../utils/coreErrors');
> 
> /**
> * @description Prepares service and starts connection with broker if needed.
> * @example
> * await z2m.init();
> */
> async function init() {
> // Load stored configuration
> const configuration = await this.getConfiguration();
> 
> this.mqttRunning = true
> 
> await this.connect(configuration);
> 
> await this.saveConfiguration(configuration);
> 
> return null;
> }
> 
> module.exports = {
> init,
> };
> 
> ```

getConfiguration.js

> **Summary**
>
> ```js
> const logger = require('../../../utils/logger');
> const { CONFIGURATION } = require('./constants');
> 
> /**
> * @description Get MQTT configuration.
> * @returns {Promise} Current MQTT network configuration.
> * @example
> * getConfiguration();
> */
> async function getConfiguration() {
> logger.debug('Zigbee2mqtt: loading stored configuration...');
> 
> // Load z2m parameters
> const z2mDriverPath = await this.gladys.variable.getValue(CONFIGURATION.Z2M_DRIVER_PATH, this.serviceId);
> //const z2mMqttUsername = await this.gladys.variable.getValue(CONFIGURATION.Z2M_MQTT_USERNAME_KEY, this.serviceId);
> //const z2mMqttPassword = await this.gladys.variable.getValue(CONFIGURATION.Z2M_MQTT_PASSWORD_KEY, this.serviceId);
> const z2mMqttUsername = '<username>';
> const z2mMqttPassword = '<password>';
> 
> // Load MQTT parameters
> // const mqttUrl = await this.gladys.variable.getValue(CONFIGURATION.MQTT_URL_KEY, this.serviceId);
> const mqttUrl = 'mqtt://<IP>:1883';
> const mqttUsername = '<username>';
> const mqttPassword = '<password>';
> // const mqttUsername = await this.gladys.variable.getValue(CONFIGURATION.GLADYS_MQTT_USERNAME_KEY, this.serviceId);
> // const mqttPassword = await this.gladys.variable.getValue(CONFIGURATION.GLADYS_MQTT_PASSWORD_KEY, this.serviceId);
> 
> return {
> z2mDriverPath,
> z2mMqttUsername,
> z2mMqttPassword,
> mqttUrl,
> mqttUsername,
> mqttPassword,
> };
> }
> 
> module.exports = {
> getConfiguration,
> }
> 
> ```

---

<div class="post-metadata">

**Author:** ![zedyxer](https://gladys-assistant-community.b-cdn.net/user_avatar/community.gladysassistant.com/zedyxer/32/13458_2.png) [@zedyxer](https://community.gladysassistant.com/u/zedyxer)\
**Post date:** [November 13, 2023, 10:37am UTC](https://community.gladysassistant.com/t/gladys-et-docker-mqtt-zigbee2mqtt-existant/8478/15 "2023-11-13T10:37:28Z")

</div>

thanks for the feedback, I modified my setup yesterday by removing my Docker MQTT and my Docker Zigbee2MQTT

I’ll still test your solution for my own info as soon as I have the time and a bit of courage ^^

ciao
