More than one instance of Zigbee2MQTT on a single rPi?

  • openHABian 3.4.3 on a rPi4 with 4GB.

OH has an Ember Zigbee coordinator for the OH Zigbee binding, and an ITEAD Zigbee Coordinator for z2m. All is working well.

I need to connect a 2nd and 3rd (SLZB-06 POE) Zigbee coordinator for the garage and another for the shed (three separate buildings).

I have installed the SLZBs, as these are Ethernet (LAN) connected; they have their own names and I have configured and updated these.

Now comes the step I do not know.

Can run multiple instances on this rPi without using docker or Proxmox machines?
If so, how?

I haven’t figured out how z2m is launched; maybe it can be launched with specifying a different config file?

Has anyone done this?
Or what is the best approach; as I can run up LXCs or docker instances on another machine, but was hoping there is a simpler way.

Thanks, any hints appreciated.

Its all here on the help about and the device manual of the device:

I am well aware of this URL… it shows a config for a single instance, but does not say how to get there what other entries to make.
Yes, I have got the ‘yellow boxes’ (SLZBs with individual IP addresses), and I am sure I can make these talk to one MQTT broker… but what do I need to do to get there?

It seems that people just copy the zigbee2mqtt directory in /opt/ to say /opt/zigbee2mqtt2 and /opt/zigbee2mqtt3 and change the config file.

While (I believe) I can follow this in principle, how do these other two instances start at start-up?

I have 2 zigbee2mqtt installs under /opt and 2 systemd config files to control them

Use systemd:

I have for example under /etc/systemd/system/zigbee2mqttSHED

[Unit]
Description=zigbee2mqttSHED
After=network.target

[Service]
ExecStart=/usr/bin/node /opt/zigbee2mqttSHED/index.js
WorkingDirectory=/opt/zigbee2mqttSHED
StandardOutput=inherit
StandardError=inherit
Restart=always
User=pi

[Install]
WantedBy=multi-user.target

Then you can use the systemctrl commands to stop and start end to make it start on boot use the systemctrl enable command.

Example: How To Use Systemctl to Manage Systemd Services and Units | DigitalOcean

Here is a snippet of the zigbee2mqtt configuration.yaml

homeassistant: false
permit_join: false
device_options:
  retain: true
  legacy: false
mqtt:
  base_topic: zigbee2mqttSHED
  server: mqtt://192.168.1.164
  keepalive: 60
  reject_unauthorized: true
  version: 4
  include_device_information: false
serial:
  port: tcp://192.168.1.9:6638
  baudrate: 115200
frontend:
  port: 8083
  host: 0.0.0.0
blocklist: []
availability: true
groups: {}
advanced:
  channel: 11
  homeassistant_legacy_entity_attributes: false
  legacy_api: false
  legacy_availability_payload: false
  legacy: false

An for the other configuration.yaml file snippet:

homeassistant: false
permit_join: false
device_options:
  retain: true
  legacy: false
mqtt:
  base_topic: zigbee2mqtt
  server: mqtt://192.168.1.164
  keepalive: 60
  reject_unauthorized: true
  version: 4
  include_device_information: false
serial:
  disable_led: true
  port: tcp://192.168.1.8:6638
  baudrate: 115200

The base topics are different but still use the same broker.

2 Likes

Awesome! I will have a crack at this…

This now makes sense… create a .service file for the auto start, and a directory copy.

I shall report back here…

Alright… your instructions helped me to make this work! :slight_smile:

  1. I created a copy of the /opt/zigbee2mqtt directory called /opt/zigbee2mqtt_garage and /opt/zigbee2mqtt_shed
  2. I edited the /opt/zigbee2mqtt_garage/data/configuration.yaml as follows:
frontend:
  port: 8083
homeassistant: false
permit_join: false
mqtt:
  base_topic: zigbee2mqtt_garage
  server: mqtt://192.168.1.5
  keepalive: 60
  include_device_information: false
serial:
  port: tcp://192.168.1.221:6638
  baudrate: 115200
advanced:
  channel: 11
  output: attribute_and_json
  log_directory: /var/log/zigbee2mqtt_garage/%TIMESTAMP%al
  homeassistant_legacy_entity_attributes: false
  legacy_api: false
  legacy_availability_payload: false
device_options:
  legacy: false
availability: true

The key here is to change the following parameters per instance:
frontend:
port: 8083
mqtt:
base_topic: zigbee2mqtt_garage
server: mqtt://192.168.1.5
serial:
port: tcp://192.168.1.221:6638
advanced:
channel: 11
log_directory: /var/log/zigbee2mqtt_garage/%TIMESTAMP%al

  1. I copied zigbee2mqtt.service to zigbee2mqtt_garage.service
    with sudo cp /etc/systemd/system/zigbee2mqtt.service /etc/systemd/system/zigbee2mqtt_garage.service
  2. I edited like so:
[Unit]
Description=Zigbee2MQTT_Garage
After=network.target

[Service]
ExecStart=/usr/bin/npm start
WorkingDirectory=/opt/zigbee2mqtt_garage
StandardOutput=inherit
StandardError=inherit
Restart=always

[Install]
WantedBy=multi-user.target

Key words to change:

Description=Zigbee2MQTT_Garage
// this seems to be different in different installations; at least it differs from Greg’s (most likely) standard install, while mine runs on openHABian
ExecStart=/usr/bin/npm start
WorkingDirectory=/opt/zigbee2mqtt_garage

  1. Did the same with the shed files.

  2. Start the services:
    sudo systemctl status zigbee2mqtt_garage.service and for the shed too.

  3. Check if it running:
    sudo systemctl status zigbee2mqtt_garage.service (same for shed)

  4. Set the services to auto start:
    sudo systemctl enable zigbee2mqtt_garage.service (and for the shed too).

This worked perfectly for me.

Thank you for putting me in the right direction.

Glad it worked.
I have it set up on my server ready to use but I didn’t need to use it yet as the coordinator is good enough to cover the whole property. Mine server etc is in the garage which is 10 metres from the house but I have a lot of zigbee router devices (10 roller blind motors) which relay the signal quiet well.

:slight_smile: I have bigger distances to cover with “tin-foiled” buildings.

There is a lesson learned (at least for me). Architecture matters!
I started with one USB Ember in the OH instance in the shed.
I have now devices in house and garage.
I wanted a backup Ember for redundancy, but could not get any Embers
Bought two ITEADs.
Then realised I do Zigbee in the garage too.
Dang.
:frowning:
When I got onto SLZBs (thanks to you) and got three, one for each building.
Now that the instances can be housed on the OH rPi, the rPi can be relocated to the tech room in the house when the time comes WITHOUT any dongle business no longer reaching its location :slight_smile:

I am now in the process of migrating devices to the right coordinator (SLZB).

What I also discovered, I can use ArgyleCourt/Shed instead of zigbee2mqtt_shed as a base topic in the config, which brings consistency to my MQTT topics. I am wrapped.

image

image

… now becomes KDL/Presence_01 as friendly name; great.

So again, thank you for your support. :+1:

You can also use those devices in wifi mode and you don’t need an ethernet POE cable from the switch. You can use either a USB power supply or a POE injector which means you can put it anywhere there is a power point.

Again, glad it worked. I might do it for real one day but everything is working fine at the moment although I have just built another shed and am going to put some temperature sensors on there so I may need another co-ordinator?

1 Like