Zigbee2mqtt - 502 bad gateway

Hi!

I have the problem with Zigbee2mqtt. The 502 bad gateway errors have appeared after the comlete new HA+Mosquitto+Zigbee2mqtt installation on my RPi4 8GB (SD card). I can not run the Z2M.

Z2M config:

data_path: /config/zigbee2mqtt
external_converters:
  - freepad_ext.js
  - one-more-converter.js
  - fromZigbee.js
  - homeassistant.js
devices: devices.yaml
groups: groups.yaml
homeassistant: true
permit_join: true
mqtt:
  base_topic: Zigbee2mqtt
  server: mqtt://core-mosquitto
serial:
  port: >-
    /dev/serial/by-id/usb-dresden_elektronik_ingenieurtechnik_GmbH_ConBee_II_DE2422042-if00
  adapter: deconz
advanced:
  log_level: warn
  pan_id: 6754
  channel: 11
  network_key:
    - 1
    - 3
    - 5
    - 7
    - 9
    - 11
    - 13
    - 15
    - 0
    - 2
    - 4
    - 6
    - 8
    - 10
    - 12
    - 13
  availability_blocklist: []
  availability_passlist: []
device_options: {}
blocklist: []
passlist: []
queue: {}
frontend:
  port: 8099
experimental: {}
socat:
  enabled: false
  master: pty,raw,echo=0,link=/tmp/ttyZ2M,mode=777
  slave: tcp-listen:8485,keepalive,nodelay,reuseaddr,keepidle=1,keepintvl=1,keepcnt=5
  options: '-d -d'
  log: true
zigbee_herdsman_debug: true

Z2M log:

[s6-init] making user provided files available at /var/run/s6/etc...exited 0.
[s6-init] ensuring user provided files have correct perms...exited 0.
[fix-attrs.d] applying ownership & permissions fixes...
[fix-attrs.d] done.
[cont-init.d] executing container initialization scripts...
[cont-init.d] socat.sh: executing... 
[12:01:44] INFO: Socat not enabled, marking service as down
[cont-init.d] socat.sh: exited 0.
[cont-init.d] zigbee2mqtt.sh: executing... 
[12:01:45] INFO: MQTT available, fetching server detail ...
[12:01:45] INFO: MQTT credentials not configured, trying to auto-discovering ...
[12:01:46] INFO: Configuring'addons' mqtt user
[12:01:46] INFO: Previous config file found, checking backup
[12:01:46] INFO: Creating backup config in '/config/zigbee2mqtt/.configuration.yaml.bk'
[12:01:46] INFO: Adjusting Zigbee2mqtt core yaml config with add-on quirks ...
[cont-init.d] zigbee2mqtt.sh: exited 0.
[cont-init.d] done.
[services.d] starting services
[services.d] done.
[12:01:47] INFO: Zigbee Herdsman debug logging enabled
[12:01:47] INFO: Handing over control to Zigbee2mqtt Core ...
> [email protected] start
> node index.js
(node:350) UnhandledPromiseRejectionWarning: Error: ENOENT: no such file or directory, open '/config/zigbee2mqtt/freepad_ext.js'
    at Object.openSync (fs.js:498:3)
    at Object.readFileSync (fs.js:394:35)
    at loadModuleFromFile (/app/lib/util/utils.ts:151:27)
    at Object.getExternalConvertersDefinitions (/app/lib/util/utils.ts:163:25)
    at getExternalConvertersDefinitions.next (<anonymous>)
    at new ExternalConverters (/app/lib/extension/externalConverters.js:10:20)
    at new Controller (/app/lib/controller.js:79:34)
    at start (/app/index.js:94:18)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:350) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:350) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
[12:01:53] INFO: Zigbee Herdsman debug logging enabled
[12:01:54] INFO: Handing over control to Zigbee2mqtt Core ...

System log:

21-09-12 11:58:40 INFO (MainThread) [supervisor.homeassistant.api] Updated Home Assistant API token
21-09-12 12:01:38 INFO (SyncWorker_2) [supervisor.docker.interface] Stopping addon_45df7312_zigbee2mqtt application
21-09-12 12:01:41 INFO (SyncWorker_2) [supervisor.docker.interface] Cleaning addon_45df7312_zigbee2mqtt application
21-09-12 12:01:43 INFO (SyncWorker_4) [supervisor.docker.addon] Starting Docker add-on zigbee2mqtt/zigbee2mqtt-aarch64 with version 1.21.1-1
21-09-12 12:02:30 ERROR (MainThread) [supervisor.api.ingress] Ingress error: Cannot connect to host 172.30.33.2:8099 ssl:default [Connect call failed ('172.30.33.2', 8099)]

Thx for your time and help too!!!

is it there ?

Thx for your reaction.

File is not there. But problem was here before I have started my Z2M setup experiments, including external converters.

Well, remove the external convertors from your configuration, and show the error you get again. Only so we can see what is going on.

I have removed it.

Z2M log:

[s6-init] making user provided files available at /var/run/s6/etc...exited 0.
[s6-init] ensuring user provided files have correct perms...exited 0.
[fix-attrs.d] applying ownership & permissions fixes...
[fix-attrs.d] done.
[cont-init.d] executing container initialization scripts...
[cont-init.d] socat.sh: executing... 
[13:19:22] INFO: Socat not enabled, marking service as down
[cont-init.d] socat.sh: exited 0.
[cont-init.d] zigbee2mqtt.sh: executing... 
[13:19:23] INFO: MQTT available, fetching server detail ...
[13:19:24] INFO: MQTT credentials not configured, trying to auto-discovering ...
[13:19:24] INFO: Configuring'addons' mqtt user
[13:19:24] INFO: Previous config file found, checking backup
[13:19:24] INFO: Creating backup config in '/config/zigbee2mqtt/.configuration.yaml.bk'
[13:19:24] INFO: Adjusting Zigbee2mqtt core yaml config with add-on quirks ...
[cont-init.d] zigbee2mqtt.sh: exited 0.
[cont-init.d] done.
[services.d] starting services
[services.d] done.
[13:19:26] INFO: Zigbee Herdsman debug logging enabled
[13:19:26] INFO: Handing over control to Zigbee2mqtt Core ...
> [email protected] start
> node index.js
2021-09-12T11:20:53.197Z zigbee-herdsman:adapter Failed to validate path: 'Error: spawn udevadm ENOENT'
2021-09-12T11:20:53.204Z zigbee-herdsman:deconz:driver Set delay to 0
CREATED DECONZ ADAPTER
2021-09-12T11:20:53.208Z zigbee-herdsman:controller:log Starting with options '{"network":{"networkKeyDistribute":false,"networkKey":[1,3,5,7,9,11,13,15,0,2,4,6,8,10,12,13],"panID":6754,"extendedPanID":[221,221,221,221,221,221,221,221],"channelList":[11]},"serialPort":{"path":"/dev/serial/by-id/usb-dresden_elektronik_ingenieurtechnik_GmbH_ConBee_II_DE2422042-if00","adapter":"deconz"},"databasePath":"/config/zigbee2mqtt/database.db","databaseBackupPath":"/config/zigbee2mqtt/database.db.backup","backupPath":"/config/zigbee2mqtt/coordinator_backup.json","adapter":{"disableLED":false,"concurrent":null,"delay":null}}'
2021-09-12T11:20:53.209Z zigbee-herdsman:deconz:driver Opening with /dev/serial/by-id/usb-dresden_elektronik_ingenieurtechnik_GmbH_ConBee_II_DE2422042-if00
Zigbee2MQTT:error 2021-09-12 13:20:53: Error while starting zigbee-herdsman
Zigbee2MQTT:error 2021-09-12 13:20:53: Failed to start zigbee
Zigbee2MQTT:error 2021-09-12 13:20:53: Check https://www.zigbee2mqtt.io/information/FAQ.html#help-zigbee2mqtt-fails-to-start for possible solutions
Zigbee2MQTT:error 2021-09-12 13:20:53: Exiting...
Zigbee2MQTT:error 2021-09-12 13:20:53: Error: Error while opening serialport 'Error: Error: Resource busy, cannot open /dev/serial/by-id/usb-dresden_elektronik_ingenieurtechnik_GmbH_ConBee_II_DE2422042-if00'
    at SerialPort.<anonymous> (/app/node_modules/zigbee-herdsman/src/adapter/deconz/driver/driver.ts:182:28)
    at SerialPort._error (/app/node_modules/zigbee-herdsman/node_modules/@serialport/stream/lib/index.js:198:14)
    at /app/node_modules/zigbee-herdsman/node_modules/@serialport/stream/lib/index.js:242:12
[13:20:53] INFO: Zigbee Herdsman debug logging enabled
[13:20:53] INFO: Handing over control to Zigbee2mqtt Core ...
> [email protected] start
> node index.js
2021-09-12T11:21:00.191Z zigbee-herdsman:adapter Failed to validate path: 'Error: spawn udevadm ENOENT'
2021-09-12T11:21:00.197Z zigbee-herdsman:deconz:driver Set delay to 0
CREATED DECONZ ADAPTER
2021-09-12T11:21:00.201Z zigbee-herdsman:controller:log Starting with options '{"network":{"networkKeyDistribute":false,"networkKey":[1,3,5,7,9,11,13,15,0,2,4,6,8,10,12,13],"panID":6754,"extendedPanID":[221,221,221,221,221,221,221,221],"channelList":[11]},"serialPort":{"path":"/dev/serial/by-id/usb-dresden_elektronik_ingenieurtechnik_GmbH_ConBee_II_DE2422042-if00","adapter":"deconz"},"databasePath":"/config/zigbee2mqtt/database.db","databaseBackupPath":"/config/zigbee2mqtt/database.db.backup","backupPath":"/config/zigbee2mqtt/coordinator_backup.json","adapter":{"disableLED":false,"concurrent":null,"delay":null}}'
2021-09-12T11:21:00.202Z zigbee-herdsman:deconz:driver Opening with /dev/serial/by-id/usb-dresden_elektronik_ingenieurtechnik_GmbH_ConBee_II_DE2422042-if00
Zigbee2MQTT:error 2021-09-12 13:21:00: Error while starting zigbee-herdsman
Zigbee2MQTT:error 2021-09-12 13:21:00: Failed to start zigbee
Zigbee2MQTT:error 2021-09-12 13:21:00: Check https://www.zigbee2mqtt.io/information/FAQ.html#help-zigbee2mqtt-fails-to-start for possible solutions
Zigbee2MQTT:error 2021-09-12 13:21:00: Exiting...
Zigbee2MQTT:error 2021-09-12 13:21:00: Error: Error while opening serialport 'Error: Error: Resource busy, cannot open /dev/serial/by-id/usb-dresden_elektronik_ingenieurtechnik_GmbH_ConBee_II_DE2422042-if00'
    at SerialPort.<anonymous> (/app/node_modules/zigbee-herdsman/src/adapter/deconz/driver/driver.ts:182:28)
    at SerialPort._error (/app/node_modules/zigbee-herdsman/node_modules/@serialport/stream/lib/index.js:198:14)
    at /app/node_modules/zigbee-herdsman/node_modules/@serialport/stream/lib/index.js:242:12
[13:21:00] INFO: Zigbee Herdsman debug logging enabled
[13:21:00] INFO: Handing over control to Zigbee2mqtt Core ...
> [email protected] start
> node index.js

System log:

21-09-12 13:19:16 INFO (SyncWorker_6) [supervisor.docker.interface] Stopping addon_45df7312_zigbee2mqtt application
21-09-12 13:19:20 INFO (SyncWorker_6) [supervisor.docker.interface] Cleaning addon_45df7312_zigbee2mqtt application
21-09-12 13:19:22 INFO (SyncWorker_2) [supervisor.docker.addon] Starting Docker add-on zigbee2mqtt/zigbee2mqtt-aarch64 with version 1.21.1-1
21-09-12 13:21:54 ERROR (MainThread) [supervisor.api.ingress] Ingress error: Cannot connect to host 172.30.33.2:8099 ssl:default [Connect call failed ('172.30.33.2', 8099)]

Seems your conbeeII can not be accessed

But why?
Integration is working. Additionally I installed deconz addon. This addon is working and I am able to intagrate devices via that.

BTW, my Conbee II is connected through the usb extender.

You can’t use deconz and zigbee2mqtt at the same time using the same stick.

Ok, but tell me, why is not Z2M working after fresh instalation? As I wrote:

  1. Complete reinstall HA on SD card.
  2. Mosquitto
  3. Z2M - and not working. There must be some specific problem.

Yes, deconz is using the stick.

BUT, deconz was not installed yet.

The last protocol/log:

021-09-12 17:11:33 WARNING (MainThread) [zigpy.zcl] Unknown cluster 61184
2021-09-12 17:11:35 WARNING (MainThread) [zigpy_deconz.api] No response to 'Command.read_parameter' command with seq id '0x02'
2021-09-12 17:11:35 ERROR (MainThread) [zigpy.application] Couldn't start application
2021-09-12 17:11:35 ERROR (MainThread) [homeassistant.components.zha.core.gateway] Couldn't start deCONZ = dresden elektronik deCONZ protocol: ConBee I/II, RaspBee I/II coordinator
Traceback (most recent call last):
File "/usr/local/lib/python3.9/asyncio/tasks.py", line 492, in wait_for
fut.result()
asyncio.exceptions.CancelledError
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/components/zha/core/gateway.py", line 152, in async_initialize
self.application_controller = await app_controller_cls.new(
File "/usr/local/lib/python3.9/site-packages/zigpy/application.py", line 69, in new
await app.startup(auto_form)
File "/usr/local/lib/python3.9/site-packages/zigpy_deconz/zigbee/application.py", line 67, in startup
self.version = await self._api.version()
File "/usr/local/lib/python3.9/site-packages/zigpy_deconz/api.py", line 455, in version
(self._proto_ver,) = await self[NetworkParameter.protocol_version]
File "/usr/local/lib/python3.9/site-packages/zigpy_deconz/api.py", line 420, in read_parameter
r = await self._command(Command.read_parameter, 1 + len(data), param, data)
File "/usr/local/lib/python3.9/site-packages/zigpy_deconz/api.py", line 305, in _command
return await asyncio.wait_for(fut, timeout=COMMAND_TIMEOUT)
File "/usr/local/lib/python3.9/asyncio/tasks.py", line 494, in wait_for
raise exceptions.TimeoutError() from exc
asyncio.exceptions.TimeoutError

Now I see errors about zigpy ? That is ZHA.

I repeat : only one integration can use the same zigbee stick at the same time ! There is no way deconz, zigbee2mqtt and ZHA can access the same stick at the same time !

I have unstalled deconz and esphome and restarted HA server and … voilá … Z2M is working.

1 Like

Although esphome has nothing to with it.

Now I am going to reinstall HA+Mosquitto+Z2M to avoid any “bugs”-done-by-myself. We will see …

It is working … thx for both your help and inspiration. :wink:

but there are some bugs still:

2021-09-12 18:56:39 ERROR (MainThread) [aiohttp.server] Unhandled exception
Traceback (most recent call last):
File "/usr/local/lib/python3.9/site-packages/aiohttp/web_protocol.py", line 485, in start
resp, reset = await task
File "/usr/local/lib/python3.9/site-packages/aiohttp/web_protocol.py", line 440, in _handle_request
reset = await self.finish_response(request, resp, start_time)
File "/usr/local/lib/python3.9/site-packages/aiohttp/web_protocol.py", line 591, in finish_response
await prepare_meth(request)
File "/usr/local/lib/python3.9/site-packages/aiohttp/web_fileresponse.py", line 241, in prepare
return await self._sendfile(request, fobj, offset, count)
File "/usr/local/lib/python3.9/site-packages/aiohttp/web_fileresponse.py", line 96, in _sendfile
await loop.sendfile(transport, fobj, offset, count)
File "/usr/local/lib/python3.9/asyncio/base_events.py", line 1151, in sendfile
return await self._sendfile_native(transport, file,
File "/usr/local/lib/python3.9/asyncio/selector_events.py", line 586, in _sendfile_native
return await self.sock_sendfile(transp._sock, file, offset, count,
File "/usr/local/lib/python3.9/asyncio/base_events.py", line 867, in sock_sendfile
self._check_sendfile_params(sock, file, offset, count)
File "/usr/local/lib/python3.9/asyncio/base_events.py", line 920, in _check_sendfile_params
raise ValueError(
ValueError: count must be a positive integer (got 0)
2021-09-12 19:13:29 WARNING (MainThread) [zigpy_znp.uart] Lost connection
Traceback (most recent call last):
File "/usr/local/lib/python3.9/site-packages/serial_asyncio/__init__.py", line 114, in _read_ready
data = self._serial.read(self._max_read_size)
File "/usr/local/lib/python3.9/site-packages/serial/serialposix.py", line 595, in read
raise SerialException(
serial.serialutil.SerialException: device reports readiness to read but returned no data (device disconnected or multiple access on port?)
2021-09-12 19:13:37 WARNING (MainThread) [zigpy_deconz.api] No response to 'Command.device_state' command with seq id '0x02'
2021-09-12 19:13:40 WARNING (MainThread) [zigpy_zigate.api] No response to command 0x0002
2021-09-12 19:13:40 WARNING (MainThread) [zigpy_zigate.api] Retry command 0x0002
2021-09-12 19:13:43 WARNING (MainThread) [zigpy_xbee.api] at: No response to AP command
2021-09-12 19:13:44 WARNING (MainThread) [zigpy_cc.api] No response for: SRSP SYS version {}

And these are zigpy errors again, meaning you installed ZHA.

Bugs? Where?

It can not be made more crystal clear:

:dizzy_face: