2 instances of zigbee2mqtt in hass os

Hi,
I use the HASS OS on a rpi4. Now i need to install 2 instances of zigbee2mqtt. Until now i used the zigbee2mqtt addon, but it seems impossible to install this one twice. How else can i do this ?
I hope its the right place to ask.

1 Like

Would you mind explaining why?

Just spitballing an idea here.
Run Zigbee2MQTT and Zigbee2MQTT Edge.
Set them up on different ports, and make sure to use different config directories as well. And of course you’ll need a second controller.

Not sure if it will work, but in theory it should.

I run 2, but one is on a second machine. The reason I run 2 is that I have 1 network strictly for those fussy aqara devices with ikea repeaters, the 2nd for everything else.

Splitting up a large network offers better performance and stability. For example, I currently run 3 instances of Z2M as well as ZHA, all on separate channels. 101 devices on the first Z2M instance, 104 on the second instance, while the 3rd instance of Z2M is for some older Osram bulbs that don’t play well with other devices. Finally, there are 14 devices on ZHA that aren’t supported by Z2M.

Around the holidays everything was on one huge mesh. Device response has much more consistent now.

Interesting. That is a lot of devices.

I will try the normal / edge addon approach. This sounds good. I hope to be able to access both configurations (settings).

I need to run 2 instances, because I use one USB bound stick and in my garden house i have a lan port, where i use a hacked lidl lan->zigbee hub. Zigbee2mqtt can only use one hub at the time, so i need 2 instances if i want to use both.

You’re not kidding. Been building out since moving into this home 8 years ago.

You can’t reach the garden house with a repeater node?

Nope, too far away.

Just in case someone also wants to do this I will write how to do.
Using edge was not the way, this led to a lot of problems and neither of the two versions was stable.
Then I found a hint in the internet. You have to add the repo twice.
One time as:
http://…
and the second time as:
http://…/
Both strings are different, so home assistant adds them.
Now you have zigbee2mqtt twice on the addon install page. You install both and configure only the first.
Change the mqqt topic, the zigbee id (both, the upper value and also the numerical value) and the zigbee channel. Now you can start the first z2m. After this you configure the second z2m and you can also start it.
This way you have two z2m links on the left menu and both instances work perfectly.

5 Likes

Hey, just wanted to know how stable it is? Any issues so far?

Hello. So today I created two instances of zigbee2mqtt.

I did it because Aqara e1 curtain drivers were leaving network every few days.
There is written somewhere on the internet that aqara devices have problems with coexisting with different brand zigbee routers on the same network.

So how I did it?
My HomeAssistant runs under Proxmox on device like Intel NUC.
The simplest way how to do it is to install another instance of Z2M as LXC container. To do that just follow this guideline Proxmox VE Helper Scripts | Scripts for Streamlining Your Homelab with Proxmox VE (you can find zigbee2mqtt in the website menu).
This is something like virtualized linux running under Proxmox (but sharing most of the stuff so not using much RAM). I have gone with the alpine linux version and it consumes 70MB of RAM.
Additionally setup a static ip to the running LXC instance so you can reach it back from the HA.
Just follow the steps for alpine.

To edit Z2M config open a shell console of a running LXC instance and run this command:

nano /etc/zigbee2mqtt/configuration.yaml

In the configuration of Z2M set MQTT server running in your HA as a MQTT server (basically just copy credentials from your original Z2M instance and add correct IP address).

I changed the MQTT topic to zigbee2mqtt2 but I am not sure if that is necessary.
Enable homeassistant in the config so Z2M can create devices in HA.

Set the correct Zigbee device (devices are shared with the Proxmox). Of course you need to have two zigbee dongles for this.

My final config looks like this:

mqtt:
  base_topic: zigbee2mqtt2
  server: mqtt://YOUR_HA_IP:1883
  user: YOUR_MQTT_USERNAME
  password: YOUR_MQTT_PASSWORD
serial:
  port: /dev/serial/by-id/usb-Texas_Instruments_TI_CC2531_USB_CDC___0X00124B001CDDF676-if00
frontend:
  port: 8080
homeassistant: true
advanced:
  log_level: info
  log_output:
    - console
    - syslog
  log_directory: /var/log/zigbee2mqtt
  log_syslog:
    facility: daemon
    path: /dev/log
    protocol: unix
    app_name: Zigbee2MQTT
    eol: /n
    host: localhost
    localhost: localhost
    pid: process.pid
    port: 514
    type: '5424'
  network_key: '!secret.yaml network_key'
  pan_id: '!secret.yaml pan_id'
  channel: 15
  last_seen: ISO_8601
devices: devices.yaml
groups: groups.yaml
availability:
  active:
    timeout: 10
  passive:
    timeout: 1000

Now to restart Z2M run:

rc-service zigbee2mqtt restart

You can check logs by running:

cat /var/log/messages

Since we enabled frondend in the config we can reach the Z2M gui from the HA.
For this install Zigbee2MQTT Proxy addon in your HA from the same repository as Zigbee2MQTT.
In the config set the server:

http://YOUR_LXC_INSTANCE_IP:8080

After this setup you can have both Z2M visible and manageable from HA.

2 Likes

No problems, works like a charm. Hope this will not get patched out, because its a very good workaround.

Thanks for this, I would like to try this out myself, so have a few questions:

  • In the second instance, you need a separate configuration directory correct? So I think one would have the second instance configured in the AddOn’s UI “Configuration” tab to use a different directory, for example: data_path: /config/zigbee2mqtt-2
  • Hostname: Do the two different instances have different hostnames? (You can see the Hostname on the AddOn’s UI “Info” tab page).
  • AddOn Webpage: On the AddOn’s UI “Info” tab page is a button “Open Web UI”. When you click on it, it takes you to the AddOn’s webserver. For the second instance, do you change the configuration’s web port number somehow?
  • what is “zigbee id”? Do you mean pan-id and ext-pan-id?

Best Regards :slight_smile:
[EDIT] I went ahead and got this working (I think), and made some notes along the way:

  • UI->Setttings->Add-Ons->+Add On Store->3-dots->Repository.
    I "ADD"ed a respository with the additonal “/” at the end of the URL as tom78 said to do (making it https://github.com/zigbee2mqtt/hassio-zigbee2mqtt/) , and indeed another entry was made (and it looks identical to the first instance’s entry). However after closing this pop-up I did not see the additional instance in the AddOn list. Anyway I did reboot the machine and the additional instance did appear this time (along with additonal instances of Edge and Proxy) in the AddOn Store. Note: there is not any way really to distinguish which one is which.
  • Host/Docker Name - It turns out that the Hostname and Dockernames for the two instances are different, one will be xxxxxxxx_zigbee2mqtt, the other will be yyyyyyyy_zigbee2mqtt.
    • When you click on the 2nd instance of zigbee2mqtt, the regular Add-On “Info” page shows up and there is nothing to distinguish it from the 1st instance except for one thing: the URL in the browser is slightly different. The URL will contain the hostname in the string. Once the instance is running, the “info” page will actually show the hostname.
    • Logs sent to the HassOS journal will be prefixed with hostname. However if you use the UI->Settings->System->Log->PullDown you will see two instances to choose from but they have the same name (the last one is the 2nd instance)
    • Zigbee2MQTT Web UI: Because the hostnames are different, the same webserver port can be used, so no need to have the front-end use a different port. Note: That the Zigbee2MQTT docs also say “you cannot change the port. The addon will force the frontend to run on port 8099 as Home Assistant Ingress requires this”.
  • Configuration (Zigbee2MQTT Add-On “Info” page):
    • The SoCat port has to change. When the AddOn starts up it stops and tells you there is something else listening on 8485. I simply incremented it by 1 to 8486
    • I did change the configuration directory to /config/zigbee2mqtt-2
    • I did change the MQTT parameters to include the base_topic as I changed it to zigbee2mqtt2
    • Then next configure which serial port to use, and other things like channel-id, pan-id, ext-pan-id etc.
    • There may be other things from an administrative/management standpoint to configure in order to distinguish the two instances, but this is all I have done so far.

If one is curious why I was interested in setting up two instances, its because I have a “sandbox” HA system that I use to play around with so that my “production” HA system won’t be affected. On my sandbox I have HA running on a VM, and I have one instance of Zigbee2MQTT using the SiLabs multiprotocol Add-on (that’s been running for several months now), and now on my second instance I wanted to play around with some VM related mappings of the Physical Zigbee USB Stick to my HA-VM serial port.

Same question here:

I am using several UZG-01 coordinator over Ethernet/PoE and I need to use Zigbee2MQTT for each UZG-01.

HA is installed on a dedicated Debian station (Pc Egines APU with 4GB of RAM). Docker is installed and I installed HA in managed mode. This means HA has control over Docker.

How do I create a Docker instance and integrate in Home-assistant managed? I would like to continue using HA managed but I understand at some point it would be interesting to go plain Docker.

Any solution?

Kind regards,
FF

Hello

Is Home assistant able to detect devices from both zigbee2mqtt instance ?

I just came across this topic trying to set up two instances of zigbee2mqtt aswell.
It didn’t work at first as it was ignoring the different base_topic I tried to change.
I changed it in addon config under “mqtt” but apparently THIS WAS IGNORED

It caused all the entities from the first Z2M instance to vanish from HA once the secondary was started. To be specific only entites from the addon that was (re)started as last worked.

What worked:

Install secondary z2m instance by changing the address
In addon configuration change data path, put your serial config, save and run. Don’t put anything about mqtt there (I am using mosquito broker)
(at this point all your entities from primary addon will disappear from HA)
Open the secondary Z2M, go to settings, mqtt and chage the base topic here in GUI
Restart secondary addon
Restart primary addon - this will bring back all entitites from primary addon

It looks like it is working fine but I am testing it only for last 15minutes or so…

Can you tell me how you got 3? I got by adding an extra / at the end of the URL but cannot figure out the 3rd

1 Like

two slashes at the end :smiley:
But three and more slashes don’t work. But another workaround that seems to work is to change https to http and again repeating one slash and two…