Koenkk / zigbee2mqtt

Zigbee 🐝 to MQTT bridge 🌉, get rid of your proprietary Zigbee bridges 🔨
https://www.zigbee2mqtt.io
GNU General Public License v3.0
11.74k stars 1.64k forks source link

MQTT failed to connect: Connection refused: Not authorized #11148

Closed rjmediallp closed 2 years ago

rjmediallp commented 2 years ago

What happened?

I updated zigbee2mqtt today (from 1.17 I think to 1.22.2-1) and having restarted, I get an error message "MQTT failed to connect: Connection refused: Not authorized".

What did you expect to happen?

MQTT connects and plugin starts up

How to reproduce it (minimal and precise)

Deleted zigbee2mqtt from home assistant. Added the new repository address and installed v1.22.2-1. Added my Sonof USB adaptor and restarted the plugin.

Home assistant core: 2021.12.10 Supervisor: 2021-12.2 Mosquitto broker v6.0.1

Zigbee2mqtt config:

data_path: /config/zigbee2mqtt
external_converters: []
devices: devices.yaml
groups: groups.yaml
homeassistant: true
permit_join: false
mqtt:
  base_topic: zigbee2mqtt,
  user: mqtt-user,
  password: ********
  server: http://10.1.1.48:1883
serial:
  port: >-
    /dev/serial/by-id/usb-ITead_Sonoff_Zigbee_3.0_USB_Dongle_Plus_7ac0421bb0c9eb1188d98b4f1d69213e-if00-port0
advanced:
  log_level: warn
  pan_id: 6754
  channel: 25
  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: {}
availability: false
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

I should add that I've tried different servers (with and without). The default previous which worked was "server": "mqtt://core-mosquitto:1883",

Zigbee2MQTT version

1.22.2-1

Adapter firmware version

unknown - bad gateway

Adapter

ITead Sonoff Zigbee 3.0 USB Dongle Plus

Debug 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:51:31] INFO: Socat not enabled, marking service as down
[cont-init.d] socat.sh: exited 0.
[cont-init.d] zigbee2mqtt.sh: executing... 
[12:51:33] INFO: MQTT available, fetching server detail ...
[12:51:34] INFO: Previous config file found, checking backup
[12:51:34] INFO: Creating backup config in '/config/zigbee2mqtt/.configuration.yaml.bk'
[12:51:35] 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:51:38] INFO: Handing over control to Zigbee2mqtt Core ...
> zigbee2mqtt@1.22.2 start
> node index.js
Zigbee2MQTT:error 2022-01-31 12:51:56: MQTT failed to connect: Connection refused: Not authorized
Zigbee2MQTT:error 2022-01-31 12:51:56: Exiting...
Koenkk commented 2 years ago

MQTT failed to connect: Connection refused: Not authorized

your mqtt credential are incorrect.

rjmediallp commented 2 years ago

See, I thought that too!

MQTT broker uses the HA user I set up. That's configured in the Zigbee2Mqtt config. I confirmed it's working by using that login on an MQTT explorer on the windows PC.

mqtt:
  base_topic: zigbee2mqtt,
  user: mqtt-user,
  password: *******,
  server: mqtt://core-mosquitto:1883

The above is the login used and confirmed working.

I'm stumped. This only started happening after the update.

/edit - I changed the user and server back to what it was previously to see if that helped. It didn't.

error log as it stands....

[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... 
[17:51:39] INFO: Socat not enabled, marking service as down
[cont-init.d] socat.sh: exited 0.
[cont-init.d] zigbee2mqtt.sh: executing... 
[17:51:42] INFO: MQTT available, fetching server detail ...
[17:51:43] INFO: Previous config file found, checking backup
[17:51:43] INFO: Creating backup config in '/config/zigbee2mqtt/.configuration.yaml.bk'
[17:51:44] 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.
[17:51:48] INFO: Handing over control to Zigbee2mqtt Core ...
> zigbee2mqtt@1.22.2 start
> node index.js
Zigbee2MQTT:error 2022-01-31 17:52:08: MQTT failed to connect: Connection refused: Not authorized
Zigbee2MQTT:error 2022-01-31 17:52:08: Exiting...
[17:52:22] INFO: Handing over control to Zigbee2mqtt Core ...
> zigbee2mqtt@1.22.2 start
> node index.js
Zigbee2MQTT:error 2022-01-31 17:52:39: MQTT failed to connect: Connection refused: Not authorized
Zigbee2MQTT:error 2022-01-31 17:52:39: Exiting...
[17:52:54] INFO: Handing over control to Zigbee2mqtt Core ...
> zigbee2mqtt@1.22.2 start
> node index.js
rjmediallp commented 2 years ago

Would there be anything between 1.17 and 1.22 which would break the listening on the server:1883 or something? It's definitely working as I said, I can see the other MQTT elements reporting back.

image

rjmediallp commented 2 years ago

Update: I kept all user settings and MQTT broker as-is... then removed the Zigbee2Mqtt plugin. I noticed I had a repository from both the z2m website as well as the github one. I removed the website repo and installed 1.22.2-1 from github. I then added the mqtt user which I know connects fine and it's all working again. No idea if that was the problem (having two repos and possibly installing a website version rather than the github?) Closing now.

henrikrox commented 2 years ago

@rjmediallp I'm having the same issue seems @Koenkk just gave a generalised answer that wasn't very helpful. What do you mean website repo and GitHub repo? can you make a list of what you did to fix this, driving me insane

djblogi commented 2 years ago

@henrikrox in my case i had the config for zigbee 2 mqtt like this mqtt: base_topic: zigbee2mqtt user: mqtt-user pass: mqtt-pass server: mqtt://core-mosquitto:1883

And changed it to

mqtt: base_topic: zigbee2mqtt user: "mqtt-user" password: "mqtt-pass" server: mqtt://core-mosquitto:1883

that worked for me.

xoref commented 2 years ago

In case anyone has a similar login issue; My system crashed and I had to do a fsck -f filesystem repair to get it all back up. Afterwards the only thing that was broken in my setup was the Mosquitto broker. It would not accept the login I had been using for years (not via MQTT Explorer nor Zigbee2MQTT).

TL;DR; I simply changed the login a little, restarted Mosquitto and it started working again.

radek-kafka commented 1 year ago

I have found similar problem within my setup. I have supervised version of Homeassistant on RPI4 and after a reboot I need to manually restart MQTT add-on.. 1st attempt to start failing with "Not authorized ..." message for other messages and also from outside (MQTT Explorer) I could not connect to ..

DannyFeliz commented 1 year ago

I have found similar problem within my setup. I have supervised version of Homeassistant on RPI4 and after a reboot I need to manually restart MQTT add-on.. 1st attempt to start failing with "Not authorized ..." message for other messages and also from outside (MQTT Explorer) I could not connect to ..

Same here, I solved it by restarting Mosquitto

radek-kafka commented 1 year ago

I have found similar problem within my setup. I have supervised version of Homeassistant on RPI4 and after a reboot I need to manually restart MQTT add-on.. 1st attempt to start failing with "Not authorized ..." message for other messages and also from outside (MQTT Explorer) I could not connect to ..

Same here, I solved it by restarting Mosquitto

The solution I have found is:

add into configuration.yaml

mqtt: broker: "core-mosquitto" username: "username" password: "password"

Now it survives restart without any additional user interaction needed ...

buteo72 commented 1 year ago

For me it was that I had the original files in configuration.yaml in **share\zigbee2mqtt\ and after the update it looked at \config**\zigbee2mqtt. In that configuration.yaml file, there was no password.

DzgHomeCastle commented 1 year ago

In my case the problem with "not authorized MQTT fail" was in mosquitto configuration. Everything work after add in mosquitto brocker:

loggins:
   - username: mqtt-user
     password: Anim@lsH0m3
SJensen721 commented 1 year ago

For future travelers. Mine was a password issue. In other words, I think I had a special character that, when I entered it into the MQTT password space, it invalidated the YAML structure. When I changed my password to something a bit more mundane, it was able to enter and worked perfectly.

Cohesive5412 commented 1 year ago

For future future travellers, essentially make your password alphanumeric only (I had a # in mine that likely borked it), and be sure to change it on both ends. Reconfigure the MQTT integration and the Zigbee2mqtt side either in settings>MQTT, or in the configuration.yaml. I was initially struggling because I forgot the MQTT integration side.

AlinGoga commented 11 months ago

@henrikrox in my case i had the config for zigbee 2 mqtt like this mqtt: base_topic: zigbee2mqtt user: mqtt-user pass: mqtt-pass server: mqtt://core-mosquitto:1883

And changed it to

mqtt: base_topic: zigbee2mqtt user: "mqtt-user" password: "mqtt-pass" server: mqtt://core-mosquitto:1883

that worked for me.

Thanks mate! it worked for me too ! :)

anotherfatduck commented 10 months ago

In my case the problem with "not authorized MQTT fail" was in mosquitto configuration. Everything work after add in mosquitto brocker:

loggins:
   - username: mqtt-user
     password: Anim@lsH0m3

this sorted out my issue as well. thank you.

sfnemis commented 5 months ago

In my case the problem with "not authorized MQTT fail" was in mosquitto configuration. Everything work after add in mosquitto brocker:

loggins:
   - username: mqtt-user
     password: Anim@lsH0m3

this sorted out my issue as well. thank you.

Thank you so much ! It worked !