Skip to content

Commit f78b2d7

Browse files
committed
2024-12-09 Zigbee2MQTT doc - master branch
I keep fielding questions on Discord which suggest IOTstack's Zigbee2MQTT documentation doesn't place sufficient emphasis on using environment variables to pass configuration settings to the container. Also, the advent of adapters which are reachable via TCP isn't mentioned so I have included an example. Opportunistic cleanup of spurious 0x090A sequences. Signed-off-by: Phill Kelley <[email protected]>
1 parent db08cde commit f78b2d7

File tree

1 file changed

+91
-14
lines changed

1 file changed

+91
-14
lines changed

docs/Containers/Zigbee2MQTT.md

Lines changed: 91 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,17 @@
2525
1. Run the IOTstack menu and choose both "Mosquitto" and "Zigbee2MQTT". That adds the service definitions for both of those containers to your *compose file*.
2626

2727
2. [Prepare your Zigbee adapter](#prepareAdapter) by flashing its firmware.
28-
3. Follow the steps in [Identify your Zigbee adapter](#identifyAdapter) to work out how your adapter "mounts" on your Raspberry Pi, and edit your *compose file* to include that information.
28+
3. Follow the steps in [Identify your Zigbee adapter](#identifyAdapter) to work out how your adapter:
29+
30+
* "mounts" on your Raspberry Pi; or
31+
* "connects" over your network,
32+
33+
and edit your *compose file* to include that information.
34+
2935
4. The default environment variables assume:
3036

31-
- You are running Mosquitto and Zigbee2MQTT as IOTstack containers on the same computer; and
37+
- You are running Mosquitto and Zigbee2MQTT as IOTstack containers on the same computer;
38+
- Your adapter mounts via USB; and
3239
- You want the Zigbee2MQTT web front end to be available on port 8080.
3340

3441
This is a good basis for getting started. If it sounds like it will meet your needs, you will not need to make any changes. Otherwise, review the [environment variables](#envVars) and make appropriate changes to the service definition in your *compose file*.
@@ -62,9 +69,12 @@ Note:
6269

6370
## Identify your Zigbee adapter { #identifyAdapter }
6471

65-
This section covers adapters that connect to your Raspberry Pi via USB.
72+
* [USB adapters](#identifyUSBAdapter)
73+
* [Remote adapters](#identifyRemoteAdapter)
74+
75+
### USB adapters { #identifyUSBAdapter }
6676

67-
> See [connect to a remote adapter](https://www.zigbee2mqtt.io/advanced/remote-adapter/connect_to_a_remote_adapter.html) for information on connecting to adapters via TCP.
77+
This section covers adapters that connect to your Raspberry Pi via USB.
6878

6979
Many USB Zigbee adapters mount as `/dev/ttyACM0` but this is not true for *all* adapters. In addition, if you have multiple devices connected to your Raspberry Pi that contend for a given device name, there are no guarantees that your Zigbee adapter will *always* be assigned the *same* name each time the device list is enumerated.
7080

@@ -104,16 +114,16 @@ For those reasons, it is better to take the time to identify your Zigbee adapter
104114
The second line indicates a CC2531 adapter is attached to the Raspberry Pi.
105115

106116
If the response pattern does **not** change, it means the Raspberry Pi is unable to see your adapter. The two most common reasons are:
107-
117+
108118
1. Your adapter was not flashed correctly. Start over at [prepare your Zigbee adapter](#prepareAdapter).
109119
2. Your adapter does not mount as a serial device. Try repeating steps 2 through 4 with the command:
110120

111121
```console
112122
$ ls -1 /dev
113123
```
114-
124+
115125
to see if you can discover how your adapter attaches to your Raspberry Pi.
116-
126+
117127
> One example is the Electrolama zig-a-zig-ah which attaches as `/dev/ttyUSB0`.
118128

119129
5. Use the output from the `ls` command in step 4 to form the absolute path to your Zigbee adapter. Example:
@@ -138,7 +148,7 @@ For those reasons, it is better to take the time to identify your Zigbee adapter
138148
```
139149

140150
Note:
141-
151+
142152
* if you forget to do this step, docker-compose will display the following error message:
143153

144154
```
@@ -147,13 +157,75 @@ For those reasons, it is better to take the time to identify your Zigbee adapter
147157

148158
8. Continue from [bring up your stack](#upStack).
149159

160+
### Remote adapters { #identifyRemoteAdapter }
161+
162+
This section covers adapters that your Raspberry Pi connects to over a network via TCP.
163+
164+
See also:
165+
166+
* [connect to a remote adapter](https://www.zigbee2mqtt.io/advanced/remote-adapter/connect_to_a_remote_adapter.html).
167+
168+
The default service definition provided by IOTstack for Zigbee2MQTT includes this device mapping:
169+
170+
``` yaml
171+
devices:
172+
- "${ZIGBEE2MQTT_DEVICE_PATH:?eg echo ZIGBEE2MQTT_DEVICE_PATH=/dev/ttyACM0 >>~/IOTstack/.env}:/dev/ttyACM0"
173+
```
174+
175+
The above syntax assumes your Zigbee adapter connects via USB. You should either remove both of those lines from your compose file, or make the `devices` clause inactive by prepending `x-`, like this:
176+
177+
``` yaml
178+
x-devices:
179+
- "${ZIGBEE2MQTT_DEVICE_PATH:?eg echo ZIGBEE2MQTT_DEVICE_PATH=/dev/ttyACM0 >>~/IOTstack/.env}:/dev/ttyACM0"
180+
```
181+
182+
You tell the container how to find your Zigbee adapter across the network by using an environment variable:
183+
184+
``` yaml
185+
- ZIGBEE2MQTT_CONFIG_SERIAL_PORT=tcp://«ipaddr»:«port»
186+
```
187+
188+
Where:
189+
190+
* «ipaddr» is the IP address or domain name where your remote Zigbee adapter is reachable; and
191+
* «port» is the port on which your remote Zigbee adapter is listening.
192+
193+
Example:
194+
195+
``` yaml
196+
- ZIGBEE2MQTT_CONFIG_SERIAL_PORT=tcp://192.168.1.5:6638
197+
```
198+
150199
## Configuration
151200

152201
### Environment variables { #envVars }
153202

154-
Any value that can be set in a Zigbee2MQTT [configuration file](#confFile) can also be set using an environment variable.
203+
Many first time users of the Zigbee2MQTT container are following guidance which assumes their Zigbee2MQTT service is running *natively* rather than in a *container*.
204+
205+
When you run Zigbee2MQTT *natively* you provide configuration information by editing Zigbee2MQTT's `configuration.yaml` file. Although you *can* edit `configuration.yaml` when Zigbee2MQTT is running in a container, it is a multi-step process and is also a sub-optimal approach. The correct way to provide configuration information to the Zigbee2MQTT container is via environment variables.
206+
207+
**Any** value that can be set in a Zigbee2MQTT [configuration file](#confFile) can also be set using an environment variable.
208+
209+
Please read that last sentence again and notice the emphasis on "Any" because it is really important. When you are running Zigbee2MQTT in a container, you **never** have to resort to editing the `configuration.yaml`.
210+
211+
The [Zigbee2MQTT documentation](https://www.zigbee2mqtt.io/guide/configuration/#environment-variables) explains the syntax. It boils down to these rules:
212+
213+
1. All environment variables start with `ZIGBEE2MQTT_CONFIG_`.
214+
2. Append all-upper-case labels for section and variable names, separated by underscores.
215+
3. Append an `=` followed by the value(s).
155216

156-
> The [Zigbee2MQTT documentation](https://www.zigbee2mqtt.io/guide/configuration/#environment-variables) explains the syntax.
217+
For example, if the Zigbee2MQTT `configuration.yaml` example you are following contains these lines:
218+
219+
``` yaml
220+
serial:
221+
port: /dev/ttyACM0
222+
```
223+
224+
then the equivalent environment variable is:
225+
226+
``` yaml
227+
- ZIGBEE2MQTT_CONFIG_SERIAL_PORT=/dev/ttyACM0
228+
```
157229

158230
Note:
159231

@@ -190,7 +262,7 @@ The default service definition provided with IOTstack includes the following env
190262
```
191263

192264
The `depends_on` clause ensures that the Mosquitto container starts alongside the Zigbee2MQTT container. That would not be appropriate if Mosquitto was running on a separate computer.
193-
265+
194266
* <a name="frontEndEnable"></a>`ZIGBEE2MQTT_CONFIG_FRONTEND=true`
195267

196268
This variable activates the Zigbee2MQTT web interface on port 8080. If you want to change the port number where you access the Zigbee2MQTT web interface, see [connecting to the web GUI](#connectGUI).
@@ -204,11 +276,15 @@ The default service definition provided with IOTstack includes the following env
204276
```
205277

206278
See [Checking the log](#checkLog) for more information about why this is useful.
207-
279+
208280
* `- DEBUG=zigbee-herdsman*`
209281

210282
Enabling this variable turns on extended debugging inside the container.
211283

284+
See also [Remote adapters](#identifyRemoteAdapter) for an example of:
285+
286+
* `- ZIGBEE2MQTT_CONFIG_SERIAL_PORT=tcp://«ipaddr»:«port»`
287+
212288
### Configuration file { #confFile }
213289

214290
Zigbee2MQTT creates a default configuration file at the path:
@@ -231,9 +307,10 @@ If you decide to edit the configuration file:
231307

232308
3. [Check the log](#checkLog) for errors.
233309

234-
Note:
310+
Notes:
235311

236312
* If you start Zigbee2MQTT from a clean slate (ie where the configuration file does not exist) **and** your *compose file* does not define the [`… MQTT_SERVER`](#mqttServer) environment variable discussed above, the container will go into a restart loop. This happens because the Zigbee2MQTT container defaults to trying to reach the Mosquitto broker at `localhost:1883` instead of `mosquitto:1883`. That usually fails.
313+
* Settings passed via environment variables take precedence over both the defaults and any changes you make subsequently to `configuration.yaml`. The Zigbee2MQTT container does not update `configuration.yaml` to reflect settings passed via environment variables.
237314

238315
## Verifying basic operation
239316

@@ -430,7 +507,7 @@ The changes you should make to your existing Zigbee2MQTT service definition are:
430507
```
431508

432509
The first two have the **identical** effect to the changes previously made via the Dockerfile. The last variable makes it easier for you to find and [view the current log](#checkLog).
433-
510+
434511
See [environment variables](#envVars) for more detail.
435512

436513
3. Add the dependency clause:

0 commit comments

Comments
 (0)