How to : my attempt at discovering zigbee devices on 2 local HA instances with only one coordinator

It has been a long and painful journey so I thought my learning experience could help
Please note : during my quest I made some assumptions and choices, so feel free to comment if I was wrong.

Background

My learning curve with zigbee started with 3 devices (movement sensor, illuminance sensor, lightbulb), a Conbee II stick as zigbee coordinator attached to my production HA on a RaspberryPi, ZHA integration, and that was quite easy and straightforward to setup. But then I migrated to Zigbee2Mqtt because it would allow me to dive deeper in my understanding of the zigbee network.

After that migration, I had the following chain (in my understanding) :

zigbee device
:arrow_right: zigbee coordinator
:arrow_right: zigbee2mqtt
:arrow_right: mqtt broker (HA addon)
:arrow_right: mqtt client (HA integration)
:arrow_right: HA

Then starting to build automations with many tries and failures, I felt like I needed to test these on my development/test HA running in a virtual machine on the same LAN.

Objective

So my objective was to test automations, scripts… for zigbee devices on a development/test HA, but I did not want to by a second zigbee coordinator.
Not to mention that I was not sure if connecting an USB coordinator to the physical box, passing it through the hypervisor to the virtual machine would work as expected.
Other wifi devices were already discovered and could already be tested on the dev HA.

1st try - miserable failure

My first idea was to bridge the 2 mqtt brokers (let’s call them B1 and B2) to get messages from my devices sent to B2 from B1.
I followed the excellent tutorials here and here, had to put both brokers in debug mode, finally confirmed that the bridge was connected between B1 and B2, confirmed in the logs that messages from B1 were being passed through to B2, but I was unable to see anything coming in the target mqtt integration.
I did not find how to tell the dev mqtt client to subscribe to topic, but however, no message seemed to arrive

After another long way with lots of tries and failures I finally realized that having 2 brokers with the same name (mqtt://core-mosquitto) publishing and listening on the same ports was perhaps what was wrong.
I tried without success to find where to change the broker name, and decided that it was not possible (if you know, please comment)

But I was not happy to try again by changing all these ports, with no guaranteed success, so I was about to give up.

2nd try
I then understood that if the mqtt addon was the broker and the mqtt integration was the client, I might be able to connect the development client (C2) to my production broker (B1), and I don’t really need a developement broker (B2), especially if no message arrive.

I tested that assuption with the also excellent addon MQTT Explorer. and the connection worked.
I have still to understand why I need the IP address instead of the mqtt name (core-mosquitto). (if you know, please comment)

OK, fine, so I

  1. un-configured the bridge on B1 to keep things clean, remove debug log option
  2. restarted the prod HA
  3. uninstalled the dev mqtt addon B2
  4. uninstalled the dev mqtt client/integration C2
  5. re-installed the mqtt integration on the dev HA,
  6. configured it with the IP@ of B1 (here as well I would have preferred to use the mqtt server name, but does not work), and the user and password I have configured in B1 (my choice)
  7. restarted the dev HA

And it worked.
C2 suscribed to B1 # topic, and HA discovered the zigbee devices published in the zigbee2mqtt/# topic.

Et voilà…

Solved,
One Zigbee coordinator with multiple HA.

zigbee device
:arrow_right: zigbee coordinator
:arrow_right: zigbee2mqtt
:arrow_right: mqtt broker (HA addon)
:arrow_right: mqtt client1 (HA integration) :arrow_right: HA1
:arrow_right: mqtt client2 (HA integration) :arrow_right: HA2

Hoping this can help

Core-mosquitto is only valid for the device the broker addon is installed on. The other HA instance has no idea where that name points to. Hence you need to use the IP address.