Zigbee2MQTT - 502: Bad Gateway *SOLVED*

Hello all

I having a problem with the integration of my Sonoff dongle
Zigbee2MQTT keeps indicating 502: Bad Gateway

Hardware:
Unraid server 6.9.2
Sonoff Zigbee 3.0 Dongle Plus (ZBDongle-P)
Conbee II

Software
Home Assistant 2022.8.1 (as VM in Unraid)
Supervisor 2022.07.0
Operating System 8.4
Mosquitto broker 6.1.2
Zigbee2MQTT 1.27.0-1

Mosquitto broker 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] mosquitto.sh: executing…
[11:36:51] INFO: SSL is not enabled
[cont-init.d] mosquitto.sh: exited 0.
[cont-init.d] nginx.sh: executing…
[cont-init.d] nginx.sh: exited 0.
[cont-init.d] done.
[services.d] starting services
[11:36:51] INFO: Starting NGINX for authentication handling…
[services.d] done.
[11:36:52] INFO: Starting mosquitto MQTT broker…
1659778612: Warning: Mosquitto should not be run as root/administrator.
[11:36:53] INFO: Successfully send discovery information to Home Assistant.
[11:36:53] INFO: Successfully send service information to the Supervisor.

Zigbee2MQTT SETTINGS
data_path: /config/zigbee2mqtt
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: false
mqtt:
base_topic: zigbee2mqtt
server: mqtt://core-mosquitto:1883
user: mqtt-user
password: ***
serial:
port: /dev/ttyUSB0
zigbee_herdsman_debug: false

Zigbee2MQTT LOG

[12:12:03] INFO: Handing over control to Zigbee2MQTT Core …
[email protected] start
node index.js
Zigbee2MQTT:info 2022-08-06 12:12:04: Logging to console and directory: ‘/config/zigbee2mqtt/log/2022-08-06.12-12-04’ filename: log.txt
Zigbee2MQTT:info 2022-08-06 12:12:04: Starting Zigbee2MQTT version 1.27.0 (commit #unknown)
Zigbee2MQTT:info 2022-08-06 12:12:04: Starting zigbee-herdsman (0.14.46)
Zigbee2MQTT:error 2022-08-06 12:12:04: Error while starting zigbee-herdsman
Zigbee2MQTT:error 2022-08-06 12:12:04: Failed to start zigbee
Zigbee2MQTT:error 2022-08-06 12:12:04: Check zigbee2mqtt website for possible solutions
Zigbee2MQTT:error 2022-08-06 12:12:04: Exiting…
Zigbee2MQTT:error 2022-08-06 12:12:04: Error: Error while opening serialport ‘Error: Error: No such file or directory, cannot open /dev/ttyUSB0’
at SerialPort. (/app/node_modules/zigbee-herdsman/src/adapter/z-stack/znp/znp.ts:146:28)
at SerialPort._error (/app/node_modules/@serialport/stream/lib/index.js:198:14)
at /app/node_modules/@serialport/stream/lib/index.js:242:12

Things I’ve already tried:

It looks like there is an issue with the Sonoff dongle.
When I replace the Sonoff dongle for my ConBee II (and adjust the port settings) Zigbee2MQTT starts up immediately without any error.

Probably I’m going to overlook something simple, but don’t get anywhere with it after 2 days…

Have you confirmed that you are using the correct USB port setting in the Addon ? When I moved over to the Sonoff stick I had to correct the port.

Does the Sonoff show up in your Hardware settings ?

image

These are the hardware settings:

ttyUSB0

i tried 2 different configurations in ZigBee2MQTT

Configuration 1:
port: /dev/ttyUSB0

Configuration 2:
port: /dev/serial/by-id/usb-ITead_Sonoff_Zigbee_3.0_USB_Dongle_Plus_ac231e4f5345ec118e5b98fd6f14af06-if00-port0

Both will not fix my problem

Have you tried rebooting the host ? Did you follow the guide to migrate to another stick to the letter ?

It works!

What I do, step-by-step

  • Disconnect all zigbee routers from the main power
  • Stop the Zigbee2MQTT plugin in Home Assistant
  • Manually add a new pan_id and network_key to the configuration.yaml of Zigbee2MQTT
  • Delete coordinator_backup.json
  • Delete database.db.backup
  • Starting the Zigbee2MQTT plugin
  • Reboot the system after a few minutes
  • Reconnect the Zigbee routers to the mains
  • All devices now need to be manually paired again. I knew this because the pan_id has changed

Do some work tonight, but i’m happy :slight_smile:

3 Likes

That’s good to hear. If you can mark your post as the solution then others may find it in the future and find your post useful :wink:

1 Like

Hi @n4m3l355 newbie here… can you clarify how to do this exactly ?
stuck in Bad Gateway for 2 days and no solution. Thanks for your help

No problem :grinning:

The easiest way is to install Samba share through supervisor Add-on Store
Then browser with Windows Explorer to IP-address-HA\config\zigbee2mqtt
Open the configuration.yaml file (with notepad or notepad++) to change the pan_id and network_key.

  • Hit save
  • Delete coordinator_backup.json in the \config\zigbee2mqtt folder
  • Delete database.db.backup in the \config\zigbee2mqtt folder
  • Starting the Zigbee2MQTT plugin
  • Reboot the system after a few minutes
  • Reconnect the Zigbee routers to the mains
  • Repair all your devices again
6 Likes

Thank you it helped :slight_smile:

What did you do? Just replace the network key and the PanID with some random figures? Have tried that and had no success. I am a total newbie I have to say.

After updating to HA OS 10.0 I got the error 502 bad gateway with zigbee2mqtt.

Luckily I could ‘restore’ this issue by replace a back up, but this is not a solution.
Is it really necessary to do add a new pan_id and network_key like post #5 ?

Hi there had this problem for a couple of days now after rebuilding my proxmox server to version 8…i can browse to the network share from windows but what creds do i use…the one for HA doesnt work…

Old post, but I wonder if it might have been solved by simply reflashing the stick. Blowing away a 60 node zigbee network is not a solution that is sensible.

2 Likes

This helped me.
But I also deleted the whole configuration.yaml inside the Z2M folder.
My problem was that I changed from one coordinator to another and it would keep trying the old port configuration.
After deleting that file and restarting the addon, it worked with the new coordinator.

Hi there, I’m also a total Newbie and have no experience in Notepad++. Thank you very much for proposed solution, I’m trying to follow your steps.

First I downloaded and startet Smaba share Add On.
Then I opened the IP-address-HA\config\zigbee2mqtt page, but it only shows me a blank page in home assistant with just “Settings” marked in the sidebar.
How do I open the configuration.yaml of Zigbee2MQTT? How do I get to open in N++/ create a link?

Is it just opening the Add On, going to configuration and selecting to work in yaml?

You can do it with visual studio server.

Also only deleting state.json worked for me to get over 502 error

2 Likes

Deleting the state.json works for me too to get Zigbee2mqtt back on track.

1 Like

This worked for me, thank you!

For me the solution was to remove ZHA integration, where Conbee had been discovered prior to zigbee2mqtt installation.

HAOS 12.4
RPI4-64
Zigbee2mqtt 1.39.0-1
Sonoff Zigbee_3.0_USB_Dongle_Plus_V2

Have also experienced this as of the last week. Will also confirm that state.json deletion was the fix. A few extra details for what its worth:

Relocated my RPI and added a ethernet USB extension, everything worked fine for a few days. Then started receiving this error. Strangely, the problem went away on its own (or possibly due to an update that temporarily reset something), but then returned and was persistent no matter what, even with restoring zigbee and other components to recent previous versions.

I did not attempt the original solution as it seemed overkill, but a deleting state.json and then waiting a few minutes, then restart, did seem to solve it for me, and is currently still working.

1 Like